Linux script for controlling Opentherm Gateway

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

Moderator: hvxl

Post Reply
sappien
Starting Member
Starting Member
Posts: 38
Joined: Fri Oct 16, 2009 11:11 am
Location: Netherlands

Linux script for controlling Opentherm Gateway

Post 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?
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Linux script for controlling Opentherm Gateway

Post 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.
Schelte
sappien
Starting Member
Starting Member
Posts: 38
Joined: Fri Oct 16, 2009 11:11 am
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Post 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..
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Linux script for controlling Opentherm Gateway

Post 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.
Schelte
sappien
Starting Member
Starting Member
Posts: 38
Joined: Fri Oct 16, 2009 11:11 am
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Post by sappien »

Reading is difficult :oops:

I forget the -e option. Now it's working! Thanks :)
FoRMaTC
Member
Member
Posts: 89
Joined: Fri Sep 26, 2008 1:50 am
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Post 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
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Linux script for controlling Opentherm Gateway

Post by hvxl »

Are /dev/ttyUSB0 and /dev/ttyUSBot the same device?
Schelte
FoRMaTC
Member
Member
Posts: 89
Joined: Fri Sep 26, 2008 1:50 am
Location: Netherlands

Re: Linux script for controlling Opentherm Gateway

Post by FoRMaTC »

Oh yes sorry
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Linux script for controlling Opentherm Gateway

Post 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
Schelte
Post Reply

Return to “Opentherm Gateway Forum”