LUA os.execute on Synology

Moderator: leecollings

Post Reply
typiak84
Posts: 5
Joined: Tuesday 23 April 2019 20:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

LUA os.execute on Synology

Post by typiak84 »

Hello.
Here is my configuration:
Domoticz on Synology
Yeelight Bulb
Lua Scene Script:
runcommandoff = "echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | netcat -w1 " ..IP.." " ..PORT.."";
os.execute(runcommandoff);
print(runcommandoff)

Here is my problem:
When i'm connected in SSH on my Yeelight bulb and i type "echo -ne '{"id":1,"method":"set_power", "params":["off", "smooth", 500]}\r\n' | netcat -w1 192.168.0.100 55443" all works fine.
When i type "sudo" before, i have to type the user passwod after the command and then all is all right too.

But whit the script: It don't work (with ok without sudo). I think it's maybe an identification issue.
I've no feedback from the bulb and no feedback in the Domoticz logs too.
Anyone already have this problem ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA os.execute on Synology

Post by waaren »

typiak84 wrote: Tuesday 23 April 2019 20:18 When i'm connected in SSH on my Yeelight bulb and i type "echo -ne '{"id":1,"method":"set_power", "params":["off", "smooth", 500]}\r\n' | netcat -w1 192.168.0.100 55443" all works fine.
But whit the script: It don't work (with or without sudo). I think it's maybe an identification issue.
I've no feedback from the bulb and no feedback in the Domoticz logs too.
Anyone already have this problem ?
Can you test with this runcommandoff ?

Code: Select all

runcommandoff = "echo -ne '{\\"id\\":1,\\"method\\":\\"set_power\\", \\"params\\":[\\"off\\", \\"smooth\\", 500]}\\r\\n' | netcat -w1 " ..IP.." " ..PORT.."";
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
typiak84
Posts: 5
Joined: Tuesday 23 April 2019 20:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: LUA os.execute on Synology

Post by typiak84 »

Thank you but it don't works:
The escape caracters are already in the line i've tested before.
When i try yours, i've a syntax error.
With my first version: no syntax error...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA os.execute on Synology

Post by waaren »

typiak84 wrote: Tuesday 23 April 2019 20:55 Thank you but it don't works:
The escape caracters are already in the line i've tested before.
When i try yours, i've a syntax error.
With my first version: no syntax error...
I tested this from a Lua (dzVents) script and It works on my system. Check this post
Did you test this from a Lua script ? And if so where do you see the syntax error ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
typiak84
Posts: 5
Joined: Tuesday 23 April 2019 20:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: LUA os.execute on Synology

Post by typiak84 »

Ok Thank you waaren.
I have read the post and i found my ridiculous issue: I've just forgot the path before netcat (/opt/bin/netcat)
Now, the sript works but not completely (not very responsive).
After this, the Domoticz logs wtite an error message on each scene command:
2019-04-24 01:49:13.976 Error: EventSystem: Warning!, lua script Script_Scenes_Selector_RVBWW has been running for more than 10 seconds
After some reseach i've modified my script y the adding of " &" at the end of the line:

runcommandoff = "echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | opt/bin/netcat -w1 " ..IP2.." " ..PORT.." &";
os.execute(runcommandoff);
print(runcommandoff)

But there is now a new issue: my bulb acceps only 4 connection and refused the next ones.
In the Yeelight Api, it's written: NOTE: Currently WiFi smart device support up to 4 simultaneous TCP connections, any further
connect attempt will be rejected.

Indeed, i've test it with many terminal connection and i can have only 4 connection at the same time.

So, i think the Lua Script let's the connection open after each Scene selection.
I now have to find how to close connection for each lua os.execute command.

Any Idea?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA os.execute on Synology

Post by waaren »

typiak84 wrote: Wednesday 24 April 2019 11:31 Now, the sript works but after this, the Domoticz logs wtite an error message on each scene command:
2019-04-24 01:49:13.976 Error: EventSystem: Warning!, lua script Script_Scenes_Selector_RVBWW has been running for more than 10 seconds
So, i think the Lua Script let's the connection open after each Scene selection.
Netcat is known to be a process that does not quit by itself on some implementations.
I now have to find how to close connection for each lua os.execute command. Any Idea?
Try to add -q 0 as parm to the netcat command.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
typiak84
Posts: 5
Joined: Tuesday 23 April 2019 20:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: LUA os.execute on Synology

Post by typiak84 »

Thank you but -q 0 don't works for me (certainly my version of netcat on Synology)
I've found a temporary solution by adding this at the end of the script: os.execute("sleep 1 && killall netcat");

It work perfectly but, if i have a netcat session open for another usage (not domoticz) it will be killed too.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA os.execute on Synology

Post by waaren »

typiak84 wrote: Wednesday 24 April 2019 18:56 Thank you but -q 0 don't works for me (certainly my version of netcat on Synology)
I've found a temporary solution by adding this at the end of the script: os.execute("sleep 1 && killall netcat");

It work perfectly but, if i have a netcat session open for another usage (not domoticz) it will be killed too.
If you have netcat version 0.7 on your Synology you can try the -c option
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
typiak84
Posts: 5
Joined: Tuesday 23 April 2019 20:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: LUA os.execute on Synology

Post by typiak84 »

I must be a little dumb but when it try the -c option, it close effectively the connection but it don't send the datas...(the connection just open and close)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest