Linux script for controlling Opentherm Gateway

This Forum is about the Opentherm gateway (OTG) from Schelte

Moderator: hvxl

Linux script for controlling Opentherm Gateway

Postby sappien » Fri Jan 25, 2013 9:46 pm

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?
sappien
Starting Member
Starting Member
 
Posts: 38
Joined: October 2009
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Postby hvxl » Sat Jan 26, 2013 10:34 am

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.
Schelte
hvxl
Senior Member
Senior Member
 
Posts: 1264
Joined: June 2010

Re: Linux script for controlling Opentherm Gateway

Postby sappien » Sun Jan 27, 2013 9:24 am

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..
sappien
Starting Member
Starting Member
 
Posts: 38
Joined: October 2009
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Postby hvxl » Sun Jan 27, 2013 12:57 pm

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.
Schelte
hvxl
Senior Member
Senior Member
 
Posts: 1264
Joined: June 2010

Re: Linux script for controlling Opentherm Gateway

Postby sappien » Sun Jan 27, 2013 2:49 pm

Reading is difficult :oops:

I forget the -e option. Now it's working! Thanks :)
sappien
Starting Member
Starting Member
 
Posts: 38
Joined: October 2009
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Postby FoRMaTC » Tue Jan 29, 2013 10:54 pm

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
FoRMaTC
Member
Member
 
Posts: 89
Joined: September 2008
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Postby hvxl » Tue Jan 29, 2013 11:19 pm

Are /dev/ttyUSB0 and /dev/ttyUSBot the same device?
Schelte
hvxl
Senior Member
Senior Member
 
Posts: 1264
Joined: June 2010

Re: Linux script for controlling Opentherm Gateway

Postby FoRMaTC » Wed Jan 30, 2013 8:28 am

Oh yes sorry
FoRMaTC
Member
Member
 
Posts: 89
Joined: September 2008
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Postby hvxl » Thu Feb 07, 2013 12:55 pm

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
Schelte
hvxl
Senior Member
Senior Member
 
Posts: 1264
Joined: June 2010


Return to Opentherm Gateway Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron