Page 2 of 3

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 16:18
by fabry91
EddyG wrote: Wednesday 05 January 2022 15:45 It should be:

Code: Select all

script:///opt/domoticz/scripts/relay....
because Domoticz is inside docker and using paths like /opt/domoticz/.....

You could check what the right path is by going inside docker.
Yes, right, now it returns a different error, maybe something to do with user rights?

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 16:26
by EddyG
That is probably because the 'nc' command is not in the docker image.
You could install that but remember that every time you update the image you will have to do it again, because it is lost if you update the image.
Go into the container with

Code: Select all

sudo docker run -it domoticz/domoticz /bin/bash
execute these command in the container.

Code: Select all

apt-get update
apt-get install netcat
exit the container.

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 16:38
by fabry91
EddyG wrote: Wednesday 05 January 2022 16:26 That is probably because the 'nc' command is not in the docker image.
You could install that but remember that every time you update the image you will have to do it again, because it is lost if you update the image.
Go into the container with

Code: Select all

sudo docker run -it domoticz/domoticz /bin/bash
execute these command in the container.

Code: Select all

apt-get update
apt-get install netcat
exit the container.
I have tried to install netcut but it returns with some warnings, same error in Domoticz when I run the script:

PS. the script is:

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 16:57
by EddyG
Try using netcat instead of the nc command in the script.

Code: Select all

echo -n "11" | netcat -n -w 1 192.168.0.99 6722

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 17:19
by fabry91
EddyG wrote: Wednesday 05 January 2022 16:57 Try using netcat instead of the nc command in the script.

Code: Select all

echo -n "11" | netcat -n -w 1 192.168.0.99 6722
same error, I noticed that in the container scripts folder there isn't the same script files outside the docker:

PS. I have modified the scripts file in "\docker\Domoticz\scripts"

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 17:55
by fabry91
Maybe figured it out!!

I added at the end of the Action: "script:///opt/domoticz/.... & and now command are executing right, will check in place when I get home ;)

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 20:34
by fabry91
EddyG wrote: Wednesday 05 January 2022 16:57 Try using netcat instead of the nc command in the script.

Code: Select all

echo -n "11" | netcat -n -w 1 192.168.0.99 6722
Doesn't help to use netcat instead of "nc"...
Result of domoticz logs:

Code: Select all

Error: Error executing script command (/opt/domoticz/scripts/relay_ch2_on.sh). returned: 32512
and the relay doesn't turn on or off, maybe netcut is not installed right? :(
How can I test netcat and be sure it is working?

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 21:50
by EddyG
I oversaw that you have to open port 6722 in the docker container besides the port 8080 and 443
Did you test the complete command on the command line in the docker container?

Re: Synology - script doesn't work

Posted: Wednesday 05 January 2022 22:26
by fabry91
EddyG wrote: Wednesday 05 January 2022 21:50 I oversaw that you have to open port 6722 in the docker container besides the port 8080 and 443
Did you test the complete command on the command line in the docker container?
Okay, port settings of the docker says that is in the same network of the docker host, how can I open port 6722?

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 10:35
by EddyG
Set the problem of the port aside, it does not hurt, I assumed that the same port might be used for a response.
First get your script working from inside docker.
Did you try to execute the script content inside the docker container?

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722
Did you try to find inside the container your script?
E.g. in /opt/domoticz/scripts or /opt/domoticz/userdata or /opt/domoticz/userdata/scripts
And what is the result?
If you found your script in the docker container, did you try to execute the script from inside the container?
And what is the result?
If you lack the experience with docker, either read more about docker and how to install and maintain containers or go back to your working raspberry.

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 13:05
by fabry91
EddyG wrote: Thursday 06 January 2022 10:35 Set the problem of the port aside, it does not hurt, I assumed that the same port might be used for a response.
First get your script working from inside docker.
Did you try to execute the script content inside the docker container?

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722
Did you try to find inside the container your script?
E.g. in /opt/domoticz/scripts or /opt/domoticz/userdata or /opt/domoticz/userdata/scripts
And what is the result?
If you found your script in the docker container, did you try to execute the script from inside the container?
And what is the result?
If you lack the experience with docker, either read more about docker and how to install and maintain containers or go back to your working raspberry.
Hello Eddy and thank you again for your reply.

I am new with docker and I succesfull migrate Domoticz db, DZGA and get everything working, only thing that is not working is this SR-201 script relay.

So I tried to execute the script from a command line inside the docker and the result is "command not found":

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 13:09
by waltervl
Do I read netcut? it should be netcat.

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 13:19
by fabry91
waltervl wrote: Thursday 06 January 2022 13:09 Do I read netcut? it should be netcat.
You are right! Thank you and will try later

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 13:21
by EddyG
That is really strange. I did the same on my test system where domoticz also runs in a container.
I got the same errors when installing netcat.
Both nc and netcat are found in /bin/ in the docker container.
Your echo -n "11" | nc -n -w 1 192.168.0.99 6722 command runs fine in my container, of course I get an error about the non-existing IP or with a real IP that connection is refused.
You can check if those nc and netcat commands exists in the /bin/ directory in the container.
Remember (like I said before) when ever you stop the container or update the image the 2 command to install netcat have to be run again.
'netcat' is NOT part of the image. That is 1 of the disadvantages of running Domoticz in a docker container.
If you do have anything special (like you have with netcat / nc) than Domoticz in a container might not be a good idea.

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 13:22
by EddyG
When nc is not found then netcat is not found either. nc is just a link to netcat.

I already mentioned here that there is a way around it, see here: viewtopic.php?p=282919#p282919
But that is really complicated for people who are not familiar with Linux.

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 15:40
by EddyG
Also an idea might be to look for a python script that will do the same as your script.
python3 is default included in the Domoticz container image.

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 16:13
by waltervl
And here is the python equivalent (and doing much more): https://github.com/cryxli/sr201/blob/ma ... t/relay.py

usage

Code: Select all

python relay.py 192.168.0.99 close:1
to close relay 1

Code: Select all

python relay.py 192.168.0.99 open:1
to open relay 1

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 18:37
by fabry91
Hello Eddy and Walter,

thank you very much for yours suggestion, I finally figured it out doing this:

- open a new terminal on the Domoticz container
- cd scripts
- execute the command

Code: Select all

apt-get update
apt-get install netcat
- test the script

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722
with the return of "10000000" for on and "00000000" for off, with succesfull switch on and off of the relay :D

So now in domoticz no error and can control perfectly the SR-201

I know that SR-201 can use python script too but the easiest way when we tested for the first time this type of relay was to use netcat.

@EddyG only thing is that, when I stop e start back the container the script continue to work, anyway better ;)

Thank you very very much for all of your time and effort! ;) ;) ;)

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 19:00
by EddyG
Glad that it worked, but you still might investigate some time in the python3 solution, because that is always present in the container image.
So netcat does not get lost when you update the container.
@waltervl unfortunately there is, for some reason, no link from python to python3 in the container, so python will not work, only python3.

Re: Synology - script doesn't work

Posted: Thursday 06 January 2022 19:26
by waltervl
In the script there is a reference to python3 so it should work....

#!/usr/bin/python3
#