OpenHAB 2.2 MySensors Serial Gateway - How to install



  • [update 2018-03-03 for version 2.2]

    Preparing your raspberry with clean install:
    Download RASPBIAN STRETCH LITE from https://www.raspberrypi.org/downloads/raspbian/
    Flash to SD-Card with etcher (https://etcher.io/) or any other flash tool you like
    create empty "ssh" file in root on SD-Card
    Insert SD-Card into raspberry PI, connect with UTP cable to your router and power on.
    Go get some coffee
    Get IP address by pinging raspberrypi.local from commandprompt on your pc
    Start SSH session with putty to the raspberry pi
    Login as "pi" with password "raspberry"

    Initial configuration:
    sudo raspi-config
    Change your password
    Network options\Hostname Change hostname to "openhabpi" or what you want
    [optional: add wifi settings]
    Interfacing Options\SPI enable
    Advanced options\Expand the file system
    Advanced options\Memory split change the memory split for the GPU from "64" to “16”
    Finish + reboot
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install screen mc vim git htop

    Java installation:
    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
    echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
    sudo apt-get update
    sudo apt-get install oracle-java8-installer
    sudo apt-get install oracle-java8-set-default

    MySensors:
    git clone https://github.com/mysensors/MySensors.git --branch master
    cd MySensors
    [edit --my-serial-groupname=tty gives members of group tty rights to access /dev/ttyMySensorsGateway]

    Inside "/home/pi/MySensors/example_linux/mysgw.cpp" or where you downloaded the "git clone https://github.com/mysensors/MySensors.git --branch master" there is this option:

    // Grant access to the specified system group for the serial device
    //#define MY_LINUX_SERIAL_GROUPNAME "tty"

    uncomment to
    // Grant access to the specified system group for the serial device
    #define MY_LINUX_SERIAL_GROUPNAME "tty"

    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway --my-rf24-channel=69 --my-transport=nrf24 --my-serial-groupname=tty --my-config-file=/etc/mysensors.dat
    make
    sudo ./bin/mysgw -d
    sudo make install
    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway --my-rf24-channel=69 --my-transport=nrf24 --my-serial-groupname=tty --my-config-file=/etc/mysensors.dat
    sudo systemctl daemon-reload
    sudo systemctl enable mysgw.service
    sudo systemctl start mysgw.service

    OpenHAB2:
    wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
    echo 'deb http://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
    sudo apt-get update
    sudo apt-get install openhab2
    sudo apt-get install openhab2-addons
    sudo systemctl start openhab2.service
    sudo systemctl status openhab2.service
    sudo systemctl daemon-reload
    sudo systemctl enable openhab2.service

    Time for coffee again.......

    open web page select expert....

    cd /usr/share/openhab2/addons/
    sudo wget http://www.oberfoell.com/openhab2/org.openhab.binding.mysensors-2.2.0-SNAPSHOT.jar
    sudo chown openhab:openhab org.openhab.binding.mysensors-2.2.0-SNAPSHOT.jar
    ssh -p 8101 openhab@localhost (this fails for me 1st time with time-out. 2nd time it takes some time but succeeds)
    pw:habopen
    feature:install openhab-transport-serial
    log:set DEBUG org.openhab.binding.mysensors
    log:tail

    Start new putty session:
    sudo usermod -a -G dialout openhab
    [edit 2: add openhab to group tty to access /dev/ttyMySensorsGateway]
    sudo usermod -a -G tty openhab

    sudo reboot

    Finally:
    web-> paperui/things add MySensors Serial Gateway
    settings:
    Serial Port: /dev/ttyMySensorsGateway
    Send Delay: 200
    Baudrate: 115200
    Skip startup connection check: true

    All done. Good luck!


  • Hero Member

    Hey!

    The MysGW Service is running with root permissions and therefore creates the device "/dev/ttyMySensorsGateway" with owner and group root.

    Please test: "sudo usermod -a -G root openhab"

    Do a restart to be sure the settings are used.

    That shouldn't be the final solution though.



  • Really grateful for your reply. Tried it and it didn't fix my problem unfortenately

    09:43:21.396 [DEBUG] [col.serial.MySensorsSerialConnection] - Connecting to /dev/pts/1 [baudRate:115200]
    09:43:21.398 [DEBUG] [col.serial.MySensorsSerialConnection] - Final port list: /dev/pts/1
    09:43:21.402 [ERROR] [col.serial.MySensorsSerialConnection] - Can't connect to serial port. Wrong port?
    09:43:21.405 [ERROR] [col.serial.MySensorsSerialConnection] - Failed connecting to bridge...next retry in 10 seconds (Retry No.:17)
    09:43:21.407 [DEBUG] [col.serial.MySensorsSerialConnection] - Shutting down serial connection!
    
    09:45:14.726 [DEBUG] [col.serial.MySensorsSerialConnection] - Connecting to /dev/ttyMySensorsGateway [baudRate:115200]
    09:45:14.728 [DEBUG] [col.serial.MySensorsSerialConnection] - Final port list: /dev/ttyMySensorsGateway
    09:45:14.732 [ERROR] [col.serial.MySensorsSerialConnection] - Can't connect to serial port. Wrong port?
    09:45:14.735 [ERROR] [col.serial.MySensorsSerialConnection] - Failed connecting to bridge...next retry in 10 seconds (Retry No.:1)
    09:45:14.737 [DEBUG] [col.serial.MySensorsSerialConnection] - Shutting down serial connection!
    
    lrwxrwxrwx 1 root root          10 apr 23 09:35 ttyMySensorsGateway -> /dev/pts/1
    ....
    pi@Controller:/dev/pts $ ls -l
    totaal 0
    crw--w---- 1 pi   tty  136, 0 apr 23  2017 0
    crw--w---- 1 root tty  136, 1 apr 23 09:35 1
    crw--w---- 1 pi   tty  136, 2 apr 23 09:41 2
    c--------- 1 root root   5, 2 jan  1  1970 ptmx
    

    In my /etc/group I have this (filtered out some stuff this noob thinks is obsolete 😉 )

    root:x:0:openhab
    daemon:x:1:
    bin:x:2:
    sys:x:3:
    adm:x:4:pi
    tty:x:5:
    dialout:x:20:pi,openhab
    sudo:x:27:pi
    www-data:x:33:
    pi:x:1000:
    spi:x:999:pi
    i2c:x:998:pi
    gpio:x:997:pi
    openhab:x:119:```


  • solved it

    Inside "/home/pi/MySensors/example_linux/mysgw.cpp" or where you downloaded the "git clone https://github.com/mysensors/MySensors.git --branch master" there is this option:

    // Grant access to the specified system group for the serial device
    //#define MY_LINUX_SERIAL_GROUPNAME "tty"

    uncomment to
    // Grant access to the specified system group for the serial device
    #define MY_LINUX_SERIAL_GROUPNAME "tty"

    save file

    stop mysgw with "sudo systemctl stop mysgw.service"
    remove mysgw from auto start with "sudo systemctl disable mysgw.service"
    uninstall with "sudo make uninstall"
    installed again

    I added openhab to the tty group using "sudo usermod -a -G tty openhab"

    full reboot

    and it works!



  • Made a reïnstall again and found that something was incomplete and that it didn't work anymore with the stable branche.

    Missing in "initial config" is enabling SPI through raspi-config at the start

    At installing MySensors replace:
    git clone https://github.com/mysensors/MySensors.git --branch master
    with:
    git clone https://github.com/mysensors/MySensors.git --branch development

    echo 'deb http://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
    Now needs to be:
    echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list

    sudo wget http://www.oberfoell.com/openhab2/org.openhab.binding.mysensors-2.2.0-SNAPSHOT.jar

    sudo chown openhab:openhab org.openhab.binding.mysensors-2.2.0-SNAPSHOT.jar

    Somehow this next one always times-out the first time. 2nd attempt does give me a connection after a while
    ssh -p 8101 openhab@localhost



  • @flipflap3

    I still have problem with with org.openhab.binding.mysensors-2.2.0-SNAPSHOT.jar and org.openhab.binding.mysensors-2.3.0-SNAPSHOT.jar
    I get always de Mysensors Serial Gateway offline with this error

    2018-03-01 21:36:47.880 [DEBUG] [col.serial.MySensorsSerialConnection] - Connecting to /dev/ttyMySensorsGateway [baudRate:115200]
    2018-03-01 21:36:47.890 [ERROR] [col.serial.MySensorsSerialConnection] - No such port: /dev/ttyMySensorsGateway
    gnu.io.NoSuchPortException: null
    	at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:273) [25:com.neuronrobotics.nrjavaserial:3.12.0.OH]
    	at org.openhab.binding.mysensors.internal.protocol.serial.MySensorsSerialConnection.establishConnection(MySensorsSerialConnection.java:51) [195:org.openhab.binding.mysensors:2.3.0.201802141500]
    	at org.openhab.binding.mysensors.internal.protocol.MySensorsAbstractConnection.connect(MySensorsAbstractConnection.java:148) [195:org.openhab.binding.mysensors:2.3.0.201802141500]
    	at org.openhab.binding.mysensors.internal.protocol.MySensorsAbstractConnection.run(MySensorsAbstractConnection.java:127) [195:org.openhab.binding.mysensors:2.3.0.201802141500]
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
    	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?]
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?]
    	at java.lang.Thread.run(Thread.java:745) [?:?]
    
    

    I back to org.openhab.binding.mysensors-2.1.0-SNAPSHOT.jar and now it's working again. Any ideas?

    Thanks



  • @jic Nope sry, BUT.. I am going to do a fresh install again today. Will check if I can get it to work and make updates to this howto where needed.



  • 2.3 snapshot doesn't work. 2.2 does

    Updated opening post for step by step instruction on installing openhab2.2 with mysensors 2.2 serial gateway binding. If you have any questions, just post them here.



  • Seem it's working know.

    Thanks



  • I am trying to follow these instructions to set up OpenHab with the MySensors Serial Gateway, but ran into a problem when installing the Java (Third command.). Here is a copy of the command and error:

    pi@openhabpi:~ $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
    Executing: /tmp/apt-key-gpghome.3nAEDiCNLy/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
    gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
    gpg: connecting dirmngr at '/tmp/apt-key-gpghome.3nAEDiCNLy/S.dirmngr' failed: No such file or directory
    gpg: keyserver receive failed: No dirmngr

    Please let me know if I missed something.

    BTW, this is using the raspbian stretch lite version, dated 2018-03-13.

    Thank you!



  • @FlipFlap3
    Firstly well done for the brilliant instructions . I too have been attempting to use Openhab with my sensors over the last year and to be honest although I've had relative success, because of the limited amount of, up to date and accurate tutorials its been a steep slope to climb. Currently I have Openhabian installed on a Raspberry pi with a Gateway connected to the I/O pins of the Pi and a couple of temp sensors connected ( all be it with difficulty ). It's setup as an Ethernet Gateway but I did try once to setup it up as a serial gateway, unsuccessfully I might add. Out of interest if I did re- install using your setup instructions, Is a serial Gateway better or easier in any way ? it does seem like the most supported option of the 3 for most people on the forum .



  • @frozenyack Sorry, I can't remember seeing an error like that before.



  • @greymarvel said in OpenHAB 2.2 MySensors Serial Gateway - How to install:

    @FlipFlap3
    Firstly well done for the brilliant instructions . I too have been attempting to use Openhab with my sensors over the last year and to be honest although I've had relative success, because of the limited amount of, up to date and accurate tutorials its been a steep slope to climb. Currently I have Openhabian installed on a Raspberry pi with a Gateway connected to the I/O pins of the Pi and a couple of temp sensors connected ( all be it with difficulty ). It's setup as an Ethernet Gateway but I did try once to setup it up as a serial gateway, unsuccessfully I might add. Out of interest if I did re- install using your setup instructions, Is a serial Gateway better or easier in any way ? it does seem like the most supported option of the 3 for most people on the forum .

    Thanks

    Sorry for late response (busy with anual reporting lately).

    I have tried MTTQ first myself, but I didn't get things working smoothly. 2nd attempt was with serial gateway. Even though I had some problems at first, I did manage to get it working. I had a hard time finding a good tutorial though, so I wrote down the steps I took carefully. Reason for me to put it here was to have a personal backup for my notes and if it would be helpful for anyone else that would be an awesome bonus 😉

    I didn't try ethernet gateway yet cause I am happy with the current setup.



  • Hi,

    The mysgw seems to be creating a link to the wrong TTY.
    When I connect the arduino gateway, I get the /dev/ttyUSB1 device.

    Insert Code Herepi@nettemp:~/MySensors $ ls /dev/tty*
    /dev/tty    /dev/tty15  /dev/tty22  /dev/tty3   /dev/tty37  /dev/tty44  /dev/tty51  /dev/tty59  /dev/tty9
    /dev/tty0   /dev/tty16  /dev/tty23  /dev/tty30  /dev/tty38  /dev/tty45  /dev/tty52  /dev/tty6   /dev/ttyAMA0
    /dev/tty1   /dev/tty17  /dev/tty24  /dev/tty31  /dev/tty39  /dev/tty46  /dev/tty53  /dev/tty60  /dev/ttyUSB0
    /dev/tty10  /dev/tty18  /dev/tty25  /dev/tty32  /dev/tty4   /dev/tty47  /dev/tty54  /dev/tty61  /dev/ttyUSB1
    /dev/tty11  /dev/tty19  /dev/tty26  /dev/tty33  /dev/tty40  /dev/tty48  /dev/tty55  /dev/tty62  /dev/ttyprintk
    /dev/tty12  /dev/tty2   /dev/tty27  /dev/tty34  /dev/tty41  /dev/tty49  /dev/tty56  /dev/tty63
    /dev/tty13  /dev/tty20  /dev/tty28  /dev/tty35  /dev/tty42  /dev/tty5   /dev/tty57  /dev/tty7
    /dev/tty14  /dev/tty21  /dev/tty29  /dev/tty36  /dev/tty43  /dev/tty50  /dev/tty58  /dev/tty8
    
    

    Then I start the mysgw and a new tty is created: "/dev/ttyMySensorsGateway", which looks nice. However, the mysgw returns lots of errors:

    mysgw: Starting gateway...
    mysgw: Protocol version - 2.2.0
    mysgw: Serial port /dev/ttyMySensorsGateway (115200 baud) created
    mysgw: MCO:BGN:INIT GW,CP=RNNGL---,VER=2.2.0
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=1
    mysgw: TSM:FAIL:DIS
    mysgw: TSF:TDI:TSL
    mysgw: TSM:INIT
    mysgw: !TSM:INIT:TSP FAIL
    mysgw: TSM:FAIL:CNT=2
    mysgw: TSM:FAIL:DIS
    mysgw: TSF:TDI:TSL
    

    Then I go check what is wrong an I see the pointer wasn't created towards "/dev/ttyUSB1", but "/dev/pts/1":

    pi@nettemp:~/MySensors $ ls -larth /dev/ttyMySensorsGateway 
    lrwxrwxrwx 1 root root 10 Apr 26 18:27 /dev/ttyMySensorsGateway -> /dev/pts/1
    

    Taking a look into the /dev/ttyUSB1 directly I can see it is fine, the problem is the GW software on the Raspberry PI that is pointing towards the wrong tty:

    pi@nettemp:~ $ stty -F /dev/ttyUSB1 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
    pi@nettemp:~ $ cat /dev/ttyUSB1 
    0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RNNGAS--,VER=2.2.0
    0;255;3;0;9;0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RNNGAS--,VER=2.2.0
    0;255;3;0;9;26 SGN:PER:OK
    0;255;3;0;9;64 SGN:INI:BND OK
    0;255;3;0;9;67 TSM:INIT
    0;255;3;0;9;69 TSF:WUR:MS=0
    0;255;3;0;9;77 TSM:INIT:TSP OK
    0;255;3;0;9;79 TSM:INIT:GW MODE
    0;255;3;0;9;82 TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;87 MCO:REG:NOT NEEDED
    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;18;2.2.0
    0;255;3;0;9;91 MCO:BGN:STP
    0;255;3;0;9;98 MCO:BGN:INIT OK,TSP=1
    

    Any idea of how to make this work?

    Where can I see the alternatives for the "
    ./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway --my-rf24-channel=69 --my-transport=nrf24 --my-serial-groupname=tty --my-config-file=/etc/mysensors.dat" command?

    Thanks,


 

411
Online

8.0k
Users

8.8k
Topics

94.4k
Posts