Page 1 of 1

Linux script for controlling Opentherm Gateway

Posted: Fri Jan 25, 2013 10:46 pm
by sappien
I'm trying to make a script to send commands (and read the output) with a bash script.

I've put the gateway in PS=1 mode, so that the debug messages are stopped.

But I don't get it to work.

Code: Select all

stty -F /dev/ttyUSB0 9600 -icrnl -echo clocal
exec 3<> /dev/ttyUSB0
echo 'PR=A' >&3
read -t 1 response <&3
echo "$response"
exec 3>&-
any suggestions?

Re: Linux script for controlling Opentherm Gateway

Posted: Sat Jan 26, 2013 11:34 am
by hvxl
The gateway wants to see a CR as the termination of a command. As far as I can tell you are only sending a LF. Try adding the option -onlret or -onlcr to the stty command. Alternatively, replace the third command with: echo -e 'PR=A\r' >&3

If you want to do anything more complex than this example, I would suggest to switch to a more advanced scripting language. My personal favorite is Tcl, for things like this perhaps in the form of expect.

Re: Linux script for controlling Opentherm Gateway

Posted: Sun Jan 27, 2013 10:24 am
by sappien
Capturing data from the gateway works, but no luck with sending commands.

With minicom etc it works fine, but with echo it doesn't respond.

echo "PR=A" > /dev/ttyUSB0
echo "PR=A\n"> /dev/ttyUSB0

I've tried different setings with ssty. It should work with echo?

cat /dev/ttyUSB0 works fine..

Re: Linux script for controlling Opentherm Gateway

Posted: Sun Jan 27, 2013 1:57 pm
by hvxl
Read my previous post again. I wrote: echo -e 'PR=A\r', not: echo "PR=A\n". The -e option and \r are significant. I haven't actually checked if it works, but it should.

Re: Linux script for controlling Opentherm Gateway

Posted: Sun Jan 27, 2013 3:49 pm
by sappien
Reading is difficult :oops:

I forget the -e option. Now it's working! Thanks :)

Re: Linux script for controlling Opentherm Gateway

Posted: Tue Jan 29, 2013 11:54 pm
by FoRMaTC
i'm trying todo the same but I can't write to the port:

root@raspberrypi:~# stty -F /dev/ttyUSB0 9600 -icrnl -echo clocal
root@raspberrypi:~# echo -e 'PR=A\r' > /dev/ttyUSB0

root@raspberrypi:~# ls -all /dev/ttyUSB0
crwxrwxrwx 1 root root 188, 0 Jan 29 22:34 /dev/ttyUSB0

Cat on that device is fine:

root@raspberrypi:~# cat /dev/ttyUSBot
BF0180000
T80000200
Error 03
T80000200
B40000200
T80190000
BC0192A00
T10010A00
Error 03
T10010A00
BD0010A00

Re: Linux script for controlling Opentherm Gateway

Posted: Wed Jan 30, 2013 12:19 am
by hvxl
Are /dev/ttyUSB0 and /dev/ttyUSBot the same device?

Re: Linux script for controlling Opentherm Gateway

Posted: Wed Jan 30, 2013 9:28 am
by FoRMaTC
Oh yes sorry

Re: Linux script for controlling Opentherm Gateway

Posted: Thu Feb 07, 2013 1:55 pm
by hvxl
I hooked up a Raspberry Pi to my Opentherm Gateway today and (after struggling to get the USB->serial converter to work), it all works just as advertised:
  • pi@raspberrypi ~ $ uname -a
    Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux
    pi@raspberrypi ~ $ ls -l /dev/ttyUSB0
    crw-rw---T 1 root dialout 188, 0 Feb 7 12:39 /dev/ttyUSB0
    pi@raspberrypi ~ $ stty -F /dev/ttyUSB0 9600 -icrnl -echo clocal
    pi@raspberrypi ~ $ echo -e 'PR=A\r' > /dev/ttyUSB0
    pi@raspberrypi ~ $ head -2 /dev/ttyUSB0
    OpenTherm Gateway 4.0a4
    SE
The SE appears to be caused by the newline sent by echo (although it should be ignored by the gateway). The way to get rid of that is by telling echo not to send a newline:
  • pi@raspberrypi ~ $ echo -e 'PR=A\r\c' > /dev/ttyUSB0
    pi@raspberrypi ~ $ head -2 /dev/ttyUSB0
    OpenTherm Gateway 4.0a4
    T80190000
For the record, my initial suggestion to add the -onlret option to stty also works perfectly fine:
  • pi@raspberrypi ~ $ stty -F /dev/ttyUSB0 9600 -icrnl -echo clocal -onlret
    pi@raspberrypi ~ $ echo 'PR=A' > /dev/ttyUSB0
    pi@raspberrypi ~ $ head -2 /dev/ttyUSB0
    OpenTherm Gateway 4.0a4
    T10010A00