OpenHAB 2.0 MySensors Serial Gateway - [solved]



  • I am not an experienced linux/pi/arduino user. I started working with all this a few weeks ago and managed to get OpenHAB 2.0 woring with a Serial Gateway. New nodes got discovered nicely etc in the end. With all trial and (lots of) error(s) on my part I thought it was smart to make a fresh start.

    This is what I did:
    flash sd with raspbian-jessie img
    put empty file ssh in sd root
    boot pi

    Initial config:
    sudo raspi-config
    Expand the file system
    Change your password
    (Change the host name if you wish, e.g. “openhabpi”)
    From the advanced menu, change the memory split for the GPU to “16”
    Restart
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install screen mc vim git htop

    JAVA:
    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]
    ./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

    open web page select expert....

    cd /usr/share/openhab2/addons/
    sudo wget http://www.oberfoell.com/openhab2/org.openhab.binding.mysensors-2.0.0-SNAPSHOT.jar
    sudo chown openhab:openhab org.openhab.binding.mysensors-2.0.0-SNAPSHOT.jar
    ssh -p 8101 openhab@localhost
    pw:habopen
    feature:install openhab-transport-serial
    log:set DEBUG org.openhab.binding.mysensors and 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

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

    MySensors Serial Gateway stays offline (also after full reboot) in OpenHAB
    changing Serial Port to /dev/pts/1 or 2 doesn't work either.

    22:49:59.483 [DEBUG] [col.serial.MySensorsSerialConnection] - Connecting to /dev/ttyMySensorsGateway [baudRate:115200]
    22:49:59.485 [DEBUG] [col.serial.MySensorsSerialConnection] - Final port list: /dev/ttyMySensorsGateway
    22:49:59.489 [ERROR] [col.serial.MySensorsSerialConnection] - Can't connect to serial port. Wrong port?
    22:49:59.493 [ERROR] [col.serial.MySensorsSerialConnection] - Failed connecting to bridge...next retry in 10 seconds (Retry No.:119)
    

    /dev/

    ...
    crw-rw---- 1 root dialout 204,  64 apr 22 22:17 ttyAMA0
    lrwxrwxrwx 1 root root          10 apr 22 22:29 ttyMySensorsGateway -> /dev/pts/1
    ...
    

    /dev/pts/

    crw--w---- 1 pi   tty  136, 0 apr 22 23:13 0
    crw--w---- 1 root tty  136, 1 apr 22 22:29 1
    crw--w---- 1 pi   tty  136, 2 apr 22 23:13 2
    

    sudo chown root:dialout 1 - doesn't help to get it working.

    my MySensor node(s) do communicate with the gateway on my RPi, but somehow communication between the serial gateway on my RPi and OpenHAB doesn't.

    thanks @TimO


  • 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!


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.