Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. OpenHAB
  4. [Tutorial] openHAB with serial gateway

[Tutorial] openHAB with serial gateway

Scheduled Pinned Locked Moved OpenHAB
78 Posts 25 Posters 76.4k Views 16 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tango2
    wrote on last edited by
    #16

    Thanks @TimO. I got everything running in /opt (@9600, but I can change that later), and am receiving humidity/temp stats from my one sensor module running on a nano with DHT22 connected. I need to go through and do some major cleanup now, and also figure out how to convert to from F to C for the temp. It seems like the stock code has provisions for that, however I haven't quite figured out how to enable the change yet.

    Thanks for the help - I look forward to implementing more of these sensors.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guzzler
      wrote on last edited by guzzler
      #17

      I am having trouble getting Arduino Nano detected by Raspberry Pi via USB.

      I could see this in the monitor when I selected the correct baudrate:

       0;0;3;0;14;Gateway startup complete.
      
      [151199.509040] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
      [151199.612259] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=7523
      [151199.612296] usb 1-1.2: New USB device strings: Mfr=0, Product=2,
      SerialNumber=0
      [151199.612314] usb 1-1.2: Product: USB2.0-Serial
      [153464.158413] usb 1-1.2: USB disconnect, device number 5
      [153715.311307] usb 1-1.3: new full-speed USB device number 6 using dwc_otg
      [153715.414679] usb 1-1.3: New USB device found, idVendor=1a86, idProduct=7523
      [153715.414717] usb 1-1.3: New USB device strings: Mfr=0, Product=2,
      SerialNumber=0
      [153715.414733] usb 1-1.3: Product: USB2.0-Serial
      

      Initially while flashing serial gateway sketch to nano from Mac I had some trouble to get the right drivers. After following this post it worked fine. Is this to do with chinese knock offs?
      http://kiguino.moos.io/2014/12/31/how-to-use-arduino-nano-mini-pro-with-CH340G-on-mac-osx-yosemite.html

      Also I installed Arduino sketch on Raspberry pi with apt-get install arduino: When I launch Arduino and go to Tools>Port is disabled.

      Is there anything I need to do on RPi so it can detect Arduino Nano knock pff?

      P 1 Reply Last reply
      0
      • T Offline
        T Offline
        TimO
        Hero Member
        wrote on last edited by
        #18

        I followed the link to the page you mentioned and from there to the chinese page.
        There is a zip-file for linux too, maybe you need to install the driver on the RPi too?

        http://www.wch.cn/download/CH341SER_LINUX_ZIP.html

        Just a guess. :-)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          guzzler
          wrote on last edited by
          #19

          Thanks @TimO .

          I have been trying to make and load that driver but cannot get hands on 3.12.28+ kernel source. It wont compile without it.

          I am wondering how come no body has come accross this issue, I bought my Arduino Nano from one of the links on mysensors store.

          http://www.aliexpress.com/item/1-pcs-for-Nano-V3-0-ATmega328P-Module-Board-Free-Mini-USB-Cable-for-Arduino-Compatible/1397847851.html?aff_platform=aaf&sk=3jYZr3nAE%3A&aff_trace_key=23901740799811215&cpt=1431974332161

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jan Gatzke
            wrote on last edited by
            #20

            I don't understand why everybody is using an USB connection for the serial gateway when openHAB is running on a raspberry pi. The pi has a rock stable uart with 3.3V logic. There is no need to convert the arduinos uart to USB. Just connect RX to TX and TX to RX. Connect ground to ground and VCC of the arduino to the 3.3V pin of the pi and you are done. The official openHAB wiki contains instructions on how to use the onboard uart of the pi: https://github.com/openhab/openhab/wiki/Serial-Binding

            1 Reply Last reply
            1
            • G Offline
              G Offline
              guzzler
              wrote on last edited by
              #21

              @Jan-Gatzke Thanks for the pointer. I will try that.

              I think the reason is lack of understanding. After reading sea of information I am able to pull together the basic architecture of how this would work.

              1 Reply Last reply
              0
              • G guzzler

                I am having trouble getting Arduino Nano detected by Raspberry Pi via USB.

                I could see this in the monitor when I selected the correct baudrate:

                 0;0;3;0;14;Gateway startup complete.
                
                [151199.509040] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
                [151199.612259] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=7523
                [151199.612296] usb 1-1.2: New USB device strings: Mfr=0, Product=2,
                SerialNumber=0
                [151199.612314] usb 1-1.2: Product: USB2.0-Serial
                [153464.158413] usb 1-1.2: USB disconnect, device number 5
                [153715.311307] usb 1-1.3: new full-speed USB device number 6 using dwc_otg
                [153715.414679] usb 1-1.3: New USB device found, idVendor=1a86, idProduct=7523
                [153715.414717] usb 1-1.3: New USB device strings: Mfr=0, Product=2,
                SerialNumber=0
                [153715.414733] usb 1-1.3: Product: USB2.0-Serial
                

                Initially while flashing serial gateway sketch to nano from Mac I had some trouble to get the right drivers. After following this post it worked fine. Is this to do with chinese knock offs?
                http://kiguino.moos.io/2014/12/31/how-to-use-arduino-nano-mini-pro-with-CH340G-on-mac-osx-yosemite.html

                Also I installed Arduino sketch on Raspberry pi with apt-get install arduino: When I launch Arduino and go to Tools>Port is disabled.

                Is there anything I need to do on RPi so it can detect Arduino Nano knock pff?

                P Offline
                P Offline
                poeml
                wrote on last edited by
                #22

                @guzzler I stumbled over the same issue. The FTDI chip on my Nano is correctly recognized as USB device when I attach it to the Raspi. However, when I reboot the Raspi, the device is not there. I need to unplug and replug it.

                That's not normal behaviour of an USB device. And it's quite hindering deploying the Nano as gateway via USB-serial. Maybe it has something to do with automatically performed reset on the Arduino Nano board??

                (The hint about attaching directly to serial is great. Noted for later.)

                P 1 Reply Last reply
                0
                • P poeml

                  @guzzler I stumbled over the same issue. The FTDI chip on my Nano is correctly recognized as USB device when I attach it to the Raspi. However, when I reboot the Raspi, the device is not there. I need to unplug and replug it.

                  That's not normal behaviour of an USB device. And it's quite hindering deploying the Nano as gateway via USB-serial. Maybe it has something to do with automatically performed reset on the Arduino Nano board??

                  (The hint about attaching directly to serial is great. Noted for later.)

                  P Offline
                  P Offline
                  poeml
                  wrote on last edited by
                  #23

                  @poeml more precisely, the Nano's FTDI chip connects to the booting Raspberry, but instead of registering a single device there are 4 (!) log lines claiming registering 4 devices (very funny), and none of the devices are bound.

                  May 23 23:16:21 bramble kernel: [    3.738087] usb 1-1.5: new full-speed USB device number 5 using dwc_otg
                  May 23 23:16:21 bramble kernel: [    4.283520] usb 1-1.5: new full-speed USB device number 6 using dwc_otg
                  May 23 23:16:21 bramble kernel: [    4.768136] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
                  May 23 23:16:21 bramble kernel: [    5.268161] usb 1-1.5: new full-speed USB device number 8 using dwc_otg
                  
                  

                  I don't find a way to trigger re-registering the device, or power-cycle the USB port, via software. I can only power-cycle the whole USB bridge, which means that the LED goes out (the Ethernet chip is switched off as well...) and LED goes on again, but with the same faulty registering as when booting.

                   # cat reset-usb
                  #!/bin/bash
                  echo 0 > /sys/bus/usb/devices/1-1/authorized
                  sleep 1
                  echo 1 > /sys/bus/usb/devices/1-1/authorized
                  

                  Unplugging and replugging always works.

                  For the record: Raspberry Pi version 2 with the 4 USB ports, just updated to Debian 8.0 (Jessie). I didn't check with Debian Wheezy if it worked then. The Nano was linked from MySensors store I believe and works great otherwise. I have two of them and both have the same problem (or the Raspi's USB stack has the problem, who knows).

                  greglG P 2 Replies Last reply
                  0
                  • G Offline
                    G Offline
                    gizmosensor
                    wrote on last edited by
                    #24

                    Great tutorial! Thank you for putting this together.

                    My controller is on RPi, and I'm using a Nano for mySerial gateway with the USB plugged into the RPi. When I specify the port as follows I get the following message

                    String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }

                    org.openhab.model.item.binding.BindingConfigParseException: Could not open serial port /dev/ttyUSB0@115200: Serial port '/dev/ttyUSB0@115200' could not be found. Available ports are:
                    /dev/ttyUSB0

                    MySensors.h has the following
                    #define BAUD_RATE 115200

                    I tried taking out @115200, I see openhab.log showing it trying to read garbage and the rules failing. So, I', thinking the garbage is because openhab is not reading it with the right baud rate. However, openhab on the RPi doesn't like /dev/ttyUSB0@115200

                    Any ideas anyone?

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      Jan Gatzke
                      wrote on last edited by
                      #25

                      Your Version of openHAB is to old. You need openHAB 1.7 to set the baud rate with @xxxxx. Update openHAB or recompile the gateway sketch with 9600 baud in config.h.

                      G 1 Reply Last reply
                      0
                      • P poeml

                        @poeml more precisely, the Nano's FTDI chip connects to the booting Raspberry, but instead of registering a single device there are 4 (!) log lines claiming registering 4 devices (very funny), and none of the devices are bound.

                        May 23 23:16:21 bramble kernel: [    3.738087] usb 1-1.5: new full-speed USB device number 5 using dwc_otg
                        May 23 23:16:21 bramble kernel: [    4.283520] usb 1-1.5: new full-speed USB device number 6 using dwc_otg
                        May 23 23:16:21 bramble kernel: [    4.768136] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
                        May 23 23:16:21 bramble kernel: [    5.268161] usb 1-1.5: new full-speed USB device number 8 using dwc_otg
                        
                        

                        I don't find a way to trigger re-registering the device, or power-cycle the USB port, via software. I can only power-cycle the whole USB bridge, which means that the LED goes out (the Ethernet chip is switched off as well...) and LED goes on again, but with the same faulty registering as when booting.

                         # cat reset-usb
                        #!/bin/bash
                        echo 0 > /sys/bus/usb/devices/1-1/authorized
                        sleep 1
                        echo 1 > /sys/bus/usb/devices/1-1/authorized
                        

                        Unplugging and replugging always works.

                        For the record: Raspberry Pi version 2 with the 4 USB ports, just updated to Debian 8.0 (Jessie). I didn't check with Debian Wheezy if it worked then. The Nano was linked from MySensors store I believe and works great otherwise. I have two of them and both have the same problem (or the Raspi's USB stack has the problem, who knows).

                        greglG Offline
                        greglG Offline
                        gregl
                        Hero Member
                        wrote on last edited by
                        #26

                        @poeml Just a thought - try connecting the nano to the rpi via a USB hub.

                        1 Reply Last reply
                        0
                        • J Jan Gatzke

                          Your Version of openHAB is to old. You need openHAB 1.7 to set the baud rate with @xxxxx. Update openHAB or recompile the gateway sketch with 9600 baud in config.h.

                          G Offline
                          G Offline
                          gizmosensor
                          wrote on last edited by gizmosensor
                          #27

                          @Jan-Gatzke That seemed to work. I'm getting readable data now. Thanks!

                          I also set the nodeId to 15 (The above example assumed it was set to 101), as follows in the sensor

                          gw.begin(NULL, 15);

                          I adjusted the mapping accordingly in the mapping, as specified in the tutorial using 15 instead of 101. The following is now being output from event.log

                          2015-05-31 22:18:33 - livingTemp01 state updated to 22

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            almj
                            wrote on last edited by
                            #28

                            Dear all,

                            I've stuck. Please help me to understand.
                            Currently I have a serial gateway and openHAB 1.7. I've managed to get controller working and send commands to openhab installed on Windows.

                            Now I need to understand how to convert commands from the gateway.

                            I have a rule

                            rule "Arduino sends to Openhab"
                                when
                                    Item Arduino received update
                                then
                                    var String lineBuffer =  Arduino.state.toString.split("\n")
                                    for (String line : lineBuffer) {
                                        var String[] message = line.split(";")
                                        var Integer nodeId = new Integer(message.get(0))
                                        var Integer childId = new Integer(message.get(1))
                                        var Integer msgType = new Integer(message.get(2))
                                        var Integer ack = new Integer(message.get(3))
                                        var Integer subType = new Integer(message.get(4))
                                        var String msg = message.get(5)
                            			
                                        if(msgType == 3 ){
                                            if (subType == 9){
                            					sendCommand(Arduino_Motion1, ON)
                            					pushover("Motion Detected", -1)
                            		} } }			
                            end
                            

                            items:

                            String Arduino "Serial" {serial="COM4@115200"}
                            Switch Arduino_Motion1 	"Motion" <siren>
                            

                            and a sitemap

                            sitemap home label="Home"
                            {
                            
                            Frame label="Serial" {
                            Switch item=Arduino_Motion1 label="Motion Sensor"
                            } } 
                            

                            So in debug I have following:

                            2015-06-01 12:51:29.154 [INFO ] [runtime.busevents             ] - Arduino state updated to 0;0;3;0;9;read: 1-1-0 s=1,c=1,t=16,pt=0,l=1:1
                            1;1;1;0;16;1
                            
                            2015-06-01 12:51:29.156 [INFO ] [runtime.busevents             ] - Arduino_Motion1 received command ON
                            

                            So I've found an example of temp sensor but not the motion...
                            Pushover sends me notifications when motion sensor send 0 to the gateway every minute or so. (0;0;3;0;9;read: 1-1-0 s=1,c=1,t=16,pt=0,l=1:0). I don't understand how can I separate last 0 from 1.
                            I know I'm on a last step, please help :)

                            Thank you!

                            1 Reply Last reply
                            1
                            • A Offline
                              A Offline
                              almj
                              wrote on last edited by
                              #29

                              Thanks for help ;)
                              Figured out it by myself

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                Jan Gatzke
                                wrote on last edited by
                                #30

                                Would you mind to share the solution?

                                1 Reply Last reply
                                1
                                • T TimO

                                  The support for a baudrate of 115.200, which is used by the MySensor serial gateway, is available since 1.7.0 in the OpenHab serial binding.

                                  You're able to remove the old version with "apt-get remove ...", no need to replace the files. Just use the installation in /opt.

                                  C Offline
                                  C Offline
                                  C.r.a.z.y.
                                  wrote on last edited by
                                  #31

                                  @TimO Hi do you work with Openhab 2.0? I tried to install it and couldnt create a binding, its very hard for me. I need auto Discovery of mysensors with 2.0

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    Jan Gatzke
                                    wrote on last edited by
                                    #32

                                    A 2.0 binding would be great. How far did you get?

                                    1 Reply Last reply
                                    0
                                    • T Offline
                                      T Offline
                                      TimO
                                      Hero Member
                                      wrote on last edited by
                                      #33

                                      Last time I've tested Openhab 2.0 there were some (well known) serious bugs and it still is only an alpha version. An MySensors binding for Openhab would be really cool and I will give it a try, but not for the 1.X Version, because of the lack of autodiscovery mechanisms in Openhab itself and because I think it is a little bit too early for Openhab 2.0.

                                      C 2 Replies Last reply
                                      0
                                      • T TimO

                                        Last time I've tested Openhab 2.0 there were some (well known) serious bugs and it still is only an alpha version. An MySensors binding for Openhab would be really cool and I will give it a try, but not for the 1.X Version, because of the lack of autodiscovery mechanisms in Openhab itself and because I think it is a little bit too early for Openhab 2.0.

                                        C Offline
                                        C Offline
                                        C.r.a.z.y.
                                        wrote on last edited by
                                        #34

                                        @TimO ok 2.0 alpha...

                                        An idea for 1.x; Ready-Discovery ?
                                        We write 250 mysensors items like ID=1-30 for switches, 31-50 for contacts, 51-70 for motion etc... if item is available then sitemap will show them.

                                        Is there anyway to create rules on frontend? Maybe IFTTT + MySensors goes well..

                                        1 Reply Last reply
                                        0
                                        • T TimO

                                          Last time I've tested Openhab 2.0 there were some (well known) serious bugs and it still is only an alpha version. An MySensors binding for Openhab would be really cool and I will give it a try, but not for the 1.X Version, because of the lack of autodiscovery mechanisms in Openhab itself and because I think it is a little bit too early for Openhab 2.0.

                                          C Offline
                                          C Offline
                                          C.r.a.z.y.
                                          wrote on last edited by
                                          #35

                                          @TimO

                                          Hi

                                          Please check this http://forum.mysensors.org/topic/1543/universal-gateway-for-315-433mhz-devices/2

                                          Is there anyway to use directly 433 with openhab --- serial gateway will be 433 receiver and transmitter (without mysensors lib and devices)

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          18

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular