Skip to content
  • 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
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

[Tutorial] openHAB with serial gateway

Scheduled Pinned Locked Moved OpenHAB
78 Posts 25 Posters 76.3k 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.
  • E Offline
    E Offline
    ewgor
    wrote on last edited by
    #36

    hi,
    just wanted to ask if anybody developed l154 work here http://forum.mysensors.org/topic/655/serial-gateway-connection-to-openhab/31? any arduino code for the node point with a few relays and a few sensors?
    thanks!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gigaguy
      wrote on last edited by
      #37

      How to I add I_BATTERY_LEVEL to the openhab rules? Being internal I wasnt sure if hashmap would do it.

      Something like this? Where Item is NodeX_Batt

              // Internal Command
              if(msgType == 3){
                  if(subType == I_BATTERY_LEVEL){
                          postUpdate("Node" + nodeId + "_Batt, msg)
                          println("Node" + nodeId + "_Batt:" + msg)
                      }}
      
      1 Reply Last reply
      0
      • John ConnollyJ Offline
        John ConnollyJ Offline
        John Connolly
        wrote on last edited by
        #38

        This is a BRILLIANT tutorial. Up and running with a single temp/humidity node in minutes. Thanks so much.

        I built a second node (identical simple DHT22 temp/humidity) and set the Node-id to 110. I'm just wondering how to add the second node into OpenHAB? I have confirmed that openhab is receiving the signals from the second node correctly, but not quite sure about the OpenHAB rules, sitemap and items configs for a second node - that is identical in every way save for the Node ID and different item names. I've simply duplicated all of the code in the relevant config files, changed the item names and added four extra lines to the mapping to map the second 110 node. When I do this I get no data from either of the nodes. If I comment out my changes, I get the values from my first node just fine.

        Can anyone with multiple nodes post a link to their configs so I can see what I might be doing wrong? Cheers.

        1 Reply Last reply
        0
        • John ConnollyJ Offline
          John ConnollyJ Offline
          John Connolly
          wrote on last edited by
          #39

          Scratch that...I figured it out. In the rules file, I needed to add a extra comma after the first chunk of mapping. As it stood, I presume it failed to process the whole rule, as there was a syntax error (missing comma) which mean't the 'list' of mappings were incomplete. Added a comma and all was right once again. :)

          1 Reply Last reply
          0
          • Dave DanD Offline
            Dave DanD Offline
            Dave Dan
            wrote on last edited by Dave Dan
            #40

            Hi guys,

            I'm running in an interesting issue here, posting to see where I'm missing a step.

            I have a Serial Gateway, connected to openHAB and working without issue. I see messages from the arduino Monitor and I can see the messages in openHAB without issue.

            I'm running openHAB on Raspberry PI. arduino connected to PI by USB (on serial port /dev/ttyUSB0) declared as below:

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

            The problem that I'm facing is related to the parse process ( I think ).

            Message sent from my node:

            send: 124-124-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:32.0
            

            with this code:
            This is the section of the arduino sketch that I'm using to send the Humidity status:

            float humidity = dht.getHumidity();
              if (isnan(humidity)) {
                  Serial.println("Failed reading humidity from DHT");
              } else if (humidity != lastHum) {
                  lastHum = humidity;
                  gw.send(msgHum.set(humidity, 1));
                  Serial.print("H: ");
                  Serial.println(humidity);
                  numAttemptsHum = 0;
              }  else {
                Serial.print("Attempt ");
                Serial.print(numAttemptsHum);
                Serial.print("/");
                Serial.print(MAX_NUM_ATTEMPTS_HUM);
                Serial.print(" - Same Humidity level presented");
                Serial.print(" (Previous:");
                Serial.print(lastHum);
                Serial.print(" vs Current: ");
                Serial.print(humidity);
                Serial.println(") - not sending");
                numAttemptsHum ++;
                if ( numAttemptsHum > MAX_NUM_ATTEMPTS_HUM ) {
                  lastHum = 0;
                  numAttemptsHum = 0;
                }
              }
            

            (it's based on the Humidity & Temp example with minor changes to avoid traffic witout reducing the sampling frequency but with consistent updates based on a specific threshold.).

            Message received in openHAB:

            13:27:54.142 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 124-124-0 s=0,c=1,t=1,pt=7,l=5,sg=0:31.0
            ' on serial port /dev/ttyUSB0
            

            So at this point I see that all messages are type 3 ( not 1 as in the above example ).

            That message updates my openHAB item, as per this example I have a rule that descompose the original message ( no modifications done yet to the one posted here ).

            So, when I finally get to the core msg ( the one that in this example is directly assigned to the openHAB item ) the value is:

            124-124-0 s=0,c=1,t=1,pt=7,l=5,sg=0:31.0
            

            instead of the 31.0 that I was expecting.

            Any ideas?

            (happy to provide more sections of code if needed, didn't want to put everyting here to avoid garbage)

            Thanks in advance for any help.

            1 Reply Last reply
            0
            • hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by
              #41

              @Dave-Dan
              0;0;3 means a debug message.. you can throw these away. Shouldn't be processed by your controller.

              Dave DanD 1 Reply Last reply
              0
              • hekH hek

                @Dave-Dan
                0;0;3 means a debug message.. you can throw these away. Shouldn't be processed by your controller.

                Dave DanD Offline
                Dave DanD Offline
                Dave Dan
                wrote on last edited by
                #42

                @hek
                hey hek, thanks for the quick reply.

                so that means that if i disable DEBUG in the arduino skech I'll remove that part of the message?

                1 Reply Last reply
                0
                • hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #43

                  Yes, they disappear when disabling DEBUG.

                  1 Reply Last reply
                  0
                  • Dave DanD Offline
                    Dave DanD Offline
                    Dave Dan
                    wrote on last edited by
                    #44

                    Ok cool.
                    That means that I'm doing something else wrong bc I still see that part after disabling DEBUG.

                    I'm curious on why having the same sketch + openHAB rule from thia thread I xan make it work ...

                    Will review carefully because sounds weird for me.

                    Thanks!!!!

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      ewgor
                      wrote on last edited by ewgor
                      #45

                      Hi TimO,
                      I want to make a permanent USB setting for my Radberry and I follow your tutorial here.
                      In my etc/udev/rules.d I have two documents: 40-scratch.rules and 99-input.rules and I don't know where to make the needed modifications as you show in this tutorial.
                      The file you point to make the modifications has another name and I can't figure where to add the vendor, product and serial no for my arduino. Shall I make a new file called 99-usb-serial.rules and to write in it the ATTRS{idVendor} and the rest of them according to my dmesg as you say here above or to do that in one of the two files I have?
                      Thanks!

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        ewgor
                        wrote on last edited by
                        #46

                        Hi! Can somebody please help here? I got stuck with my openhab server on my raspberry!
                        By now I was starting the server by:

                        Sudo /opt/openhab/start.sh
                        

                        But I wanted more, to make it auto start on reboot so in case of power failure to auto start when the power is back. Therefore I followed some tutorials found on the www and I got it done, now the server starts alone but I cannot do anything from web page or from my phone. I also can't see the temp and humidity on the web or phone!
                        The question is how to stop this server? I tried different commands found on the internet but non of them can stop this invincible server I have lunched :)
                        I tried to stop it, remove, delete... Nothing works!
                        Is there any way to remove everything from my raspberry pi and to start it all over again with all the installation as for windows ? Format the partition, install the noobs again and so on?
                        Thanks.

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          TimO
                          Hero Member
                          wrote on last edited by
                          #47
                          1. udev: Just create the new file if it is not there yet. It should be processed automatically.

                          2. The best way to start a service in Linux is using an etc-script. You will find an example here: https://github.com/openhab/openhab/wiki/Samples-Tricks#how-to-configure-openhab-to-start-automatically-on-linux
                            The script will start OpenHab at boot and you're able to start/stop/restart with

                            /etc/init.d/openhab start
                            or
                            service openhab start
                            
                          1 Reply Last reply
                          0
                          • Daniel LindbergD Offline
                            Daniel LindbergD Offline
                            Daniel Lindberg
                            wrote on last edited by
                            #48

                            I'm having issues getting the ttyUSB99 fix to work.
                            I'm running openhab 1.7.1 and it was installed using apt-get.
                            My dmseg output looks like this

                            [10167.765598] usb 1-1.2: USB disconnect, device number 4
                            [10167.766311] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
                            [10167.766407] ch341 1-1.2:1.0: device disconnected
                            [10171.843803] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
                            [10171.946998] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=7523
                            [10171.947025] usb 1-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
                            [10171.947042] usb 1-1.2: Product: USB2.0-Serial
                            [10171.948288] ch341 1-1.2:1.0: ch341-uart converter detected
                            [10171.952514] usb 1-1.2: ch341-uart converter now attached to ttyUSB0
                            

                            As you can see there is no SerialNumber here, but I found it using

                            pi@raspberrypi ~ $ udevadm info -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1
                                ATTRS{serial}=="3f980000.usb
                            

                            So I created a rules file looking like this:

                            pi@raspberrypi ~ $ cat /etc/udev/rules.d/99-usb-serial.rules
                            SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{serial}=="3f980000.usb", SYMLINK+="ttyUSB99"
                            

                            I have disconnected and reconnected my gateway.
                            But starting openhab now just results in the following error:

                            2015-09-20 09:24:48.867 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type 'serial' of item ?Arduino? could not be parsed correctly.
                            org.openhab.model.item.binding.BindingConfigParseException: Could not open serial port /dev/ttyUSB99: Serial port '/dev/ttyUSB99' could not be found. Available ports are:
                            /dev/ttyUSB0
                            

                            What can I do to resolve this?

                            1 Reply Last reply
                            0
                            • Daniel LindbergD Offline
                              Daniel LindbergD Offline
                              Daniel Lindberg
                              wrote on last edited by
                              #49

                              Eventually solved it by just omitting SerialNumber, i.e.

                              SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{serial}=="3f980000.usb", SYMLINK+="ttyUSB99
                              

                              I guess that could cause problems if I would attached more similar devices to my RPI, but I don't know if there is any point in having more than one gateway? (unless you have > 255 sensors I guess)

                              1 Reply Last reply
                              0
                              • N Offline
                                N Offline
                                nikos1671
                                wrote on last edited by
                                #50

                                Hi,

                                I am new with mysensors and i am trying to make it work with openhab.
                                I have a soil sensor and with same copy paste from the forum i manage to sent the value on the openhab, now i am trying to translate the battery level on the opnehab side but i dont know how to do it. can someone help me please?? this is what i get on the openhab 0;0;3;0;9;read: 254-254-0 s=255,c=3,t=0,pt=1,l=1,sg=0:68
                                254;255;3;0;0;68 this is the battery value.
                                But i am lost on the rule how to decode the message.

                                Thanks
                                Nikos

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SiLeX
                                  wrote on last edited by
                                  #51

                                  I also would like to share my working default.rules + examples with you. Hope it can help someone.

                                  https://gist.github.com/gersilex/13f39b3419427b35636a

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

                                    Hi @nikos1671 !

                                    You need to add an item to the hash map with nodeID 254 and childId 255.
                                    In the rules section search for

                                    // Internal Command
                                            		    if(msgType == 3){
                                            		        if(subType == I_SKETCH_NAME){
                                            		                println("Sketch name: " + msg )
                                            		                sketchName=msg
                                            		            }
                                            		        if(subType == I_SKETCH_VERSION){
                                            		                println("Sketch version: " + msg )
                                            		                postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
                                            		                sketchName=""
                                            		            }
                                            		        }
                                            	 	   }
                                    
                                    

                                    As the battery status is an internal message, you need to modify this section. Add an if statement for I_BATTERY_LEVEL.

                                    For more information about the messages: http://www.mysensors.org/download/serial_api_15

                                    N 1 Reply Last reply
                                    0
                                    • T TimO

                                      Hi @nikos1671 !

                                      You need to add an item to the hash map with nodeID 254 and childId 255.
                                      In the rules section search for

                                      // Internal Command
                                              		    if(msgType == 3){
                                              		        if(subType == I_SKETCH_NAME){
                                              		                println("Sketch name: " + msg )
                                              		                sketchName=msg
                                              		            }
                                              		        if(subType == I_SKETCH_VERSION){
                                              		                println("Sketch version: " + msg )
                                              		                postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
                                              		                sketchName=""
                                              		            }
                                              		        }
                                              	 	   }
                                      
                                      

                                      As the battery status is an internal message, you need to modify this section. Add an if statement for I_BATTERY_LEVEL.

                                      For more information about the messages: http://www.mysensors.org/download/serial_api_15

                                      N Offline
                                      N Offline
                                      nikos1671
                                      wrote on last edited by
                                      #53

                                      @TimO thank you

                                      1 Reply Last reply
                                      0
                                      • N Offline
                                        N Offline
                                        nikos1671
                                        wrote on last edited by
                                        #54

                                        What i am doing wrong??
                                        i am using the last rules from silex and i can parse the data from my sensebender temp and hum on openhab but i cannot make it with battery. here is my setup

                                        // Mappings
                                        var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(

                                        "3;1;"                 -> "Temp",
                                        "Temp"					-> "3;1;",
                                        "3;2;"                 -> "Hum",
                                        "Hum"					-> "3;2;",
                                        "3;255;"                 -> "Batt",
                                        "Batt"			   		-> "3;255;",
                                        

                                        the rule

                                        if(msgType == M_INTERNAL){ // Internal Command
                                        print("(INTERNAL)\t")
                                        if(subType == I_SKETCH_NAME){
                                        println("Sketch name: " + msg )
                                        }
                                        if(subType == I_SKETCH_VERSION){
                                        println("Sketch version: " + msg )
                                        }
                                        if(subType == I_BATTERY_LEVEL){
                                        postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                        println ("Batt item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Batt: " + msg )
                                        }

                                                        }
                                        

                                        my.items
                                        String Arduino "Arduino" { serial="COM3@115200" }

                                        Number Temp "Temperatur [%.1f °C]" <temperature>
                                        Number Hum "Feuchtigkeit [%.1f %%]" <temperature>
                                        Number Batt "bataria [%.1f %%]" <energy>

                                        and this is the logs of openhab
                                        20:02:58.954 [DEBUG] [b.serial.internal.SerialDevice:194 ] - Received message '0;0;3;0;9;read: 3-3-0 s=255,c=4,t=0,pt=6,l=10,sg=0:FFFFFFFFFFFFFFFF03
                                        3;255;4;0;0;FFFFFFFFFFFFFFFF0300
                                        0;0;3;0;9;read: 3-3-0 s=255,c=3,t=11,pt=0,l=17,sg=0:Sensebender Micro
                                        3;255;3;0;11;Sensebender Micro
                                        0;0;3;0;9;read: 3-3-0 s=255,c=3,t=12,pt=0,l=3,sg=0:1.3
                                        3;255;3;0;12;1.3
                                        0;0;3;0;9;read: 3-3-0 s=1,c=0,t=6,pt=0,l=0,sg=0:
                                        3;1;0;0;6;
                                        0;0;3;0;9;read: 3-3-0 s=2,c=0,t=7,pt=0,l=0,sg=0:
                                        3;2;0;0;7;
                                        0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.6
                                        3;1;1;0;0;23.6
                                        0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:53
                                        3;2;1;0;1;53
                                        0;0;3;0;9;read: 3-3-0 s=255,c=3,t=0,pt=1,l=1,sg=0:113
                                        3;255;3;0;0;113
                                        ' on serial port COM3
                                        20:02:58.960 [DEBUG] [o.b.f.i.h.FritzahaWebInterface:336 ] - Sending update to item Power_FritzDECTv
                                        20:02:58.977 [DEBUG] [m.r.internal.engine.RuleEngine:305 ] - Executing rule 'Decode incoming MySensors data'
                                        20:02:59.101 [ERROR] [o.o.c.s.ScriptExecutionThread :50 ] - Error during the execution of rule 'Decode incoming MySensors data': 5

                                        Can someone help me please??

                                        1 Reply Last reply
                                        0
                                        • Dave DanD Offline
                                          Dave DanD Offline
                                          Dave Dan
                                          wrote on last edited by
                                          #55

                                          Hi @nikos1671,

                                          everytime I had that error was mainly because I forgot / add extra comma in the LinkedHastMap definition or something like that.

                                          Can you please share the full openHAB rule?

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


                                          17

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 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
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular