Openhab MQTT Example



  • Hi,

    i'm new here.

    I got a binary switch sensor to work and the mqtt ethernet gateway and i installed openhab on my raspberry - everything is working.

    But here is my problem:

    I dont know how to implement the binary switch to openhab.

    This is what my serial monitor prints out from the node:

    sensor started, id 20
    send: 20-20-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
    send: 20-20-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    read: 0-0-20 s=255,c=3,t=6,pt=0,l=1:M
    send: 20-20-0-0 s=3,c=0,t=0,pt=0,l=5,st=ok:1.4.1
    send: 20-20-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 20-20-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:1
    send: 20-20-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 20-20-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:1

    I need an easy example i cant find samething with google.

    If u have ready to use config-files for openhab that would be nice.



  • Add this to your openhab.cfg file:

    mqtt:mysensor.url=tcp://xxx.xxx.xxx.xxx:1883
    mqtt:mysensor.clientId=MyMQTT
    

    Dont't forget to replace xxx with your broker's IP-Adress.
    ClientID has to be unique for your broker, e.g. if there is another connection with the same ID, only the last established connection will be valid.

    Add this to your *.items file:

    Switch mqttsw1 "Switch 1" (all) {mqtt=">[mysensor:/testsw/1:command:on:default],>[mysensor:/testsw/1:command:off:default]"}
    Switch mqttsw2 "Switch 2" (all) {mqtt=">[mysensor:/testsw/2:command:off:default],>[mysensor:/testsw/2:command:on:default]"}
    

    Add this to your *.sitemap file:

    Frame label="MQTT" {
    Switch item=mqttsw1 label="MQTT Switch 1"	
    Switch item=mqttsw2 label="MQTT Switch 2"
    }
    

    This should be enough for a dryfit run. It will be safe to restart OpenHab at this point. Using mosquitto_pub/mosquitto_sub or WMQTT-Utility or something similar you should be able to receive messages from OpenHab under topic "/testsw/#"



  • Thank u tboha

    now there is a mistake in the sitemap-file:

    2014-12-10 09:42:13.967 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.6.1).
    2014-12-10 09:42:33.835 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
    2014-12-10 09:42:34.692 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
    2014-12-10 09:42:34.751 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
    2014-12-10 09:42:34.768 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mymqtt'
    2014-12-10 09:42:38.721 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'exec.persist'
    2014-12-10 09:42:42.505 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'logging.persist'
    2014-12-10 09:42:42.904 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'db4o.persist'
    2014-12-10 09:42:43.159 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
    2014-12-10 09:42:44.089 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.items'
    2014-12-10 09:43:07.490 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.sitemap'
    2014-12-10 09:43:11.083 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.script'
    2014-12-10 09:43:29.438 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
    2014-12-10 09:43:39.518 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
    2014-12-10 09:43:57.645 [INFO ] [.o.io.habmin.HABminApplication] - Started HABmin REST API at /services/habmin
    2014-12-10 09:44:54.138 [WARN ] [c.internal.ModelRepositoryImpl] - Configuration model 'test.sitemap' is either empty or cannot be parsed correctly!
    2014-12-10 09:44:54.268 [WARN ] [e.jetty.servlet.ServletHandler] - /openhab.app
    org.openhab.ui.webapp.render.RenderException: Sitemap 'test' could not be found
        at org.openhab.ui.webapp.internal.servlet.WebAppServlet.service(WebAppServlet.java:114) ~[na:na]
        at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61) ~[na:na]
        at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:128) ~[na:na]
        at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60) ~[na:na]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) ~[javax.servlet_3.0.0.v201112011016.jar:na]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598) ~[org.eclipse.jetty.servlet_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486) [org.eclipse.jetty.servlet_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413) [org.eclipse.jetty.servlet_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.Server.handle(Server.java:350) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:944) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630) [org.eclipse.jetty.http_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230) [org.eclipse.jetty.http_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) [org.eclipse.jetty.server_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606) [org.eclipse.jetty.io_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46) [org.eclipse.jetty.io_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603) [org.eclipse.jetty.util_8.1.3.v20120522.jar:8.1.3.v20120522]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538) [org.eclipse.jetty.util_8.1.3.v20120522.jar:8.1.3.v20120522]
        at java.lang.Thread.run(Thread.java:744) [na:1.8.0]
    

    And here my sitemap file:

    Frame label="MQTT" 
    	{
    	Switch item=mqttsw1 label="MQTT Switch 1"    
    	Switch item=mqttsw2 label="MQTT Switch 2"
    	}
    

    I Hope u can help.



  • openhab designer.JPG

    And here Screenshot from openhab designer.



  • Okay, i found the mistake.

    test.sitemap schould look like this:

    sitemap Test label="Menu"
    {
    	
    Frame label="MQTT" 
    	{
    	Switch item=mqttsw1 label="MQTT Switch 1"    
    	Switch item=mqttsw2 label="MQTT Switch 2"
    	}
    	
    }
    

    Now i can go on with testing.



  • openhab screen.JPG

    Now it looks like this.

    But i still have the problem that i cant see the position of my window switch.

    {mqtt=">[mysensor:/testsw/1:command:on:default],>[mysensor:/testsw/1:command:off:default]"}
    

    This line has to be modified i think. Plz tell me how it must be to show the status of my sensor-node.

    send: 20-20-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 20-20-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:1
    

    this is what the serial monitor from my sensor node prints.
    Can someone explain what this meesage mean?!



  • @Marcus .. I have to think about this. Meanwhile I would be interested in your OpenHab output concernig lines like these:

    15:19:49.599 DEBUG o.o.b.m.i.MqttItemBinding[:44] - Publishing command OFF to /tbtestm/1
    15:19:49.599 DEBUG o.o.i.t.m.i.MqttBrokerConnection[:437] - Publishing message 325 to topic '/tbtestm/1'
    

    You got some messages similar to this?



  • Well u are back.

    pi@raspberrypi /opt/openhab $ sudo ./start.sh
    Launching the openHAB runtime...
    osgi> 2014-12-10 14:59:25.455 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been     started (v1.6.1).
    2014-12-10 14:59:45.668 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
    2014-12-10 14:59:46.488 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
    2014-12-10 14:59:46.589 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
    2014-12-10 14:59:46.597 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mymqtt'
    2014-12-10 14:59:50.693 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'exec.persist'
    2014-12-10 14:59:55.287 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'logging.persist'
    2014-12-10 14:59:55.513 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'db4o.persist'
    2014-12-10 14:59:55.702 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
    2014-12-10 14:59:56.627 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.items'
    2014-12-10 15:00:10.357 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.script'
    2014-12-10 15:00:24.527 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.sitemap'
    2014-12-10 15:00:31.120 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
    2014-12-10 15:00:38.539 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
    2014-12-10 15:00:59.480 [INFO ] [.o.io.habmin.HABminApplication] - Started HABmin REST API at /services/habmin
    

    This happened when i activated/deactivated the switches in the "test-environment" on the webpage.

     2014-12-10 15:02:30.560 [INFO ] [runtime.busevents             ] - mqttsw1 received command ON
    2014-12-10 15:02:31.060 [INFO ] [runtime.busevents             ] - mqttsw1 received command OFF
    2014-12-10 15:02:31.969 [INFO ] [runtime.busevents             ] - mqttsw2 received command ON
     2014-12-10 15:02:32.736 [INFO ] [runtime.busevents             ] - mqttsw2 received command OFF
    

    This is everything it prints. but if i switch on the node it prints nothing.

    This must be simple problem with the item definition i think. But there are less examples where i can look an figure out how it works.



  • Now I installed MyMQTT on my smartphone and connected it to my MQTT Gateway.

    If i activate and deactivate the switch on the node it prints this:

    1
    MyMQTT/20/3/V_TRIPPED
    0 
    MyMQTT/20/3/V_TRIPPED
    

    I hope this helps.



  • I forgot about the DEBUG part.

    <logger name="org.openhab" level="INFO"/>
    <logger name="org.openhab.binding.mqtt" level="DEBUG" />
    <logger name="org.openhab.io.transport.mqtt" level="DEBUG" />
    

    In File "logback.xml" look for the first line and insert the second and third line.
    This will lead to some additional infos in Openhabs output.

    I'm looking for some trace of successfully established connections between OpenHab and MQTT broker.

    If there is no connection the switch will show like you described above.



  • I did what u said.

    This is what openhab says after start.

     pi@raspberrypi /opt/openhab $ sudo ./start.sh
     Launching the openHAB runtime...
     osgi> 2014-12-10 17:32:36.323 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.6.1).
     2014-12-10 17:32:56.766 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
     2014-12-10 17:32:57.084 [DEBUG] [.io.transport.mqtt.MqttService] - Starting MQTT Service...
     2014-12-10 17:32:58.022 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
     2014-12-10 17:32:58.139 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
     2014-12-10 17:32:58.154 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mymqtt'
     2014-12-10 17:32:58.232 [DEBUG] [o.i.t.m.i.MqttBrokerConnection] - Creating new client for 'tcp://192.168.0.3:1883' using id 'MyMQTT' and file store '/tmp/mymqtt'
     2014-12-10 17:33:01.703 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'exec.persist'
     2014-12-10 17:33:04.772 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'logging.persist'
     2014-12-10 17:33:05.181 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'db4o.persist'
     2014-12-10 17:33:05.437 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
     2014-12-10 17:33:06.092 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.items'
     2014-12-10 17:33:29.493 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.sitemap'
     2014-12-10 17:33:33.644 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test.script'
     2014-12-10 17:33:47.367 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
     2014-12-10 17:33:53.419 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
     2014-12-10 17:34:15.084 [INFO ] [.o.io.habmin.HABminApplication] - Started HABmin REST API at /services/habmin
     2014-12-10 17:34:20.543 [DEBUG] [.b.mqtt.internal.MqttActivator] - MQTT binding has been started.
     2014-12-10 17:34:20.703 [DEBUG] [b.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item 'mqttsw1' : 0 subscribers, 2 publishers
     2014-12-10 17:34:20.722 [DEBUG] [b.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item 'mqttsw2' : 0 subscribers, 2 publishers
     2014-12-10 17:34:20.794 [DEBUG] [m.internal.MqttEventBusBinding] - MQTT: Activating event bus binding.
    

    0 subscribers, 2 publishers???



  • This is not the expected result. Where does the second publisher come from?

    But this result tells us that your broker and your connection are working fine, at least for output (regarded from the OpenHab side).

    Toggling the switch should now result in a message like shown above ( "Publishing command....). This message should show up in your MyMQTT on your Smartphone.

    Maybe I misunderstood your intentions. I thought you wanted to control some appliance with a switch from within OpenHab. This should work with the given example.

    If you want to control a switch (e.g. MySensors BinarySwitchSensor) things get a little more complex. You need an inbound channel from the broker. A code example for this purpose can be found in http://forum.mysensors.org/topic/303/mqtt-broker-gateway. The following line implements this.

    Switch node2_sw2  "sw2 send + recieve example"  (node2,all)      {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0],<[mysensor:MyMQTT/21/2/V_LIGHT:command:MAP(1on0off.map)]"}
    

    ( This will not fit for a switch - its only an example for inbound channels)
    I tried this, but it was not successful. I got a Feed-back-loop blocking my OpenHab Server.

    If you want to monitor your switch, the String Example some lines below could be an option.

     String sketch20 "Switch 20 [%s]"  (sketch,all) {mqtt="<[mysensor:MyMQTT/20/3/V_TRIPPED:state:default]"}


  • I only wanna see the state of the switch.

    For example i wanna know if the window is open or not.

    But the line does not work. i cannot see the state of the switch.

    I used the example and edited the line u gave me in there:

     Group all
     Group node1  (all)
     Group node2  (all)
     Group sketch (all)
    
     Number node1_temp  "Temp [%.1f °C]"     (node1,all)  {mqtt="<[mysensor:MyMQTT/20/10/V_TEMP:state:default]"}
     Number node1_humid "Humid [%.1f %%Rh]" (node1,all)  {mqtt="<[mysensor:MyMQTT/20/11/V_HUM:state:default]"}
    
     Switch node2_sw1  "sw2"  (node2,all)  {mqtt=">[mysensor:MyMQTT/21/1/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/21/1/V_LIGHT:command:OFF:0]"}
     Switch node2_sw2  "sw2 send + recieve example"  (node2,all)      {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0],<[mysensor:MyMQTT/21/2/V_LIGHT:command:MAP(1on0off.map)]"}
    
      String sketch20 "Switch name 20 [%s]"  (sketch,all) {mqtt="<[mysensor:MyMQTT/20/3/V_TRIPPED:state:default]"}


  • I stripped my Openhab Installation to the bones and tried to run the example - now I'm getting strange errors like "InstantiationException on org.openhab.core.library.types.StringType"

    It will take a while to check out the reasons this behavior.

    If I change the MQTT-Topics by hand (e.g. with mosquitto_pub from the raspberry) with some String, they show up correct, if it's a number it won't. Strange.



  • A little update. I couldn't figure out the reasons of this strange behavior, bus at least there exist a kind of workaround.

    File mqtt.sitemap

    sitemap mqtt label="MQTT-Test"
    {
     Frame label="MQTT" 
       {	
        Switch item=mqttsw1 label="MQTT Switch 1 (text)" 
        Text item=mqttsw1s   
        Switch item=mqttsw2 label="MQTT Switch 2 (raw)"
        Text item=mqttsw2s 
        Switch item=mqttsw3 label="MQTT Switch 3 (string)" 
        Text item=mqttsw3s
        Text item=sketch20
       }
    }
    

    File mqtt.items

    Switch mqttsw1 "MQTT Switch 1" (all,mqtt) {mqtt=">[mysensor:/testsw/1:command:on:RED],>[mysensor:/testsw/1:command:off:Green]"}
    Switch mqttsw2 "MQTT Switch 2" (all,mqtt) {mqtt=">[mysensor:/testsw/2:command:off:default],>[mysensor:/testsw/2:command:on:default]"}
     Switch mqttsw3 "MQTT Switch 3" (all,mqtt) {mqtt=">[mysensor:/testsw/3:command:*:Switch ${itemName} was turned ${command}]"}
    
    String mqttsw1s "MQtt Switch 1 Status [%s]" (all,mqtt) {mqtt="<[mysensor:/testsw/1:state:default]"}
     String mqttsw2s "MQtt Switch 2 Status [%s]" (all,mqtt) {mqtt="<[mysensor:/testsw/2:state:default]"}
    String mqttsw3s "MQtt Switch 3 Status [%s]" (all,mqtt) {mqtt="<[mysensor:/testsw/3:state:default]"}
                                       
     String sketch20 "Sketch name 20 [%s]"  (all,mqtt) {mqtt="<[mysensor:MyMQTT/20/255/V_SKETCH_NAME:state:default]"}
    

    Switch 1 : default is replaced with RED/Green and this text is output to the topic /testsw/1.
    Toggling this switch will result in RED/Green in the status field.

    Switch 2: the original statement.
    Toggling this switch will result in ON/OFF messages shown in the broker (e.g. MyMQTT)

    Switch 3: copied from manual : https://github.com/openhab/openhab/wiki/MQTT-Binding
    Toggling this switch will result in a well formed Message in status and broker.

    This line resolves the secret of the 2 publishers : OpenHab counts every ">" as a separate publisher.

    Furthermore the browser used seems to affect the results. It is mentioned somewhere in the documentation that browsers behave different. I'm using Opera 12.17 - for some items
    manual refreshing is required. Chrome does this automatically.

    However - the line "String sketch20....." should have been functional despite of all this. I can't see an obvious explanation for failure.

    Maybe you can adapt the above skeleton files for your needs.



  • Good morning.

    I did what u said. But i dont see the status of my switch.

     Switch mqttsw1 "MQTT Switch 1" (all,mqtt) {mqtt=">[mysensor:MyMQTT/20/3/V_TRIPPED:command:on:RED],>[mysensor:MyMQTT/20/3/V_TRIPPED:command:off:Green]"}
    Switch mqttsw2 "MQTT Switch 2" (all,mqtt) {mqtt=">[mysensor:MyMQTT/20/3/V_TRIPPED:command:off:default],>[mysensor:MyMQTT/20/3/V_TRIPPED:command:on:default]"}
    Switch mqttsw3 "MQTT Switch 3" (all,mqtt) {mqtt=">[mysensor:MyMQTT/20/3/V_TRIPPED:command:*:Switch ${itemName} was turned ${command}]"}
    
    String mqttsw1s "MQtt Switch 1 Status [%s]" (all,mqtt) {mqtt="<[mysensor:MyMQTT/20/3/V_TRIPPED:state:default]"}
    String mqttsw2s "MQtt Switch 2 Status [%s]" (all,mqtt) {mqtt="<[mysensor:MyMQTT/20/3/V_TRIPPED:state:default]"}
    String mqttsw3s "MQtt Switch 3 Status [%s]" (all,mqtt) {mqtt="<[mysensor:MyMQTT/20/3/V_TRIPPED:state:default]"}
    
    String sketch20 "Sketch name 20 [%s]"  (all,mqtt) {mqtt="<[mysensor:MyMQTT/20/3/V_TRIPPED:state:default]"}
    

    The sitemap is the same as yours.

    mqtt-test.JPG

    As u can see there is no red/green and no well formed text-message.

    Thanks anyway! Would be very nice if we get this to work.



  • It seems your broker does not response to OpenHab or the binding is not effective.

    Your installation is different from mine - you are running OpenHab on your raspberry , I'm running OpenHab on my desktop.
    We both use OpenHab 1.6.1.
    Probably you are running your MQTT Broker (presumably mosquitto?) on your raspberry - so do I.
    You are running MyMQTT on Android, so do I.
    (by the way -- I am not able to publish something from MyMQTT despite MyMQTT says "Message published" - nothing arrives at the broker. You got similar experiences?)

    For a basic debugging environment I use mosquitto_sub in an extra terminal on my Raspberry with

    mosquitto_sub -t /#
    

    which should show all messages arriving at the broker.
    First test with mosquitto_pub in another terminal:

    mosquitto_pub -t /testsw/1 -m "switch1"
    

    If this Message shows up we got our topic instantiated (and the broker is working).

    mosquitto_pub -t /testsw/1 -m "ON" -r
    

    Now sending a retained message. If OpenHab connects to the broker, this message will be sent immediately

    in the OpenHab log you should see this:

    11:15:07.844 INFO  runtime.busevents[:26] - mqttsw1s state updated to switch1.
    11:16:21.289 INFO  runtime.busevents[:26] - mqttsw1s state updated to ON
    

    Toggling some switch should give the followin log:

    12:00:03.976 DEBUG o.o.b.m.i.MqttItemBinding[:44] - Publishing command OFF to /testsw/1
    12:00:03.991 DEBUG o.o.i.t.m.i.MqttBrokerConnection[:437] - Publishing message 6 to topic '/testsw/1'
    12:00:03.994 INFO  runtime.busevents[:22] - mqttsw1 received command OFF
    12:00:04.004 INFO  runtime.busevents[:26] - mqttsw1s state updated to Green
    

    what does your log show?



  • I use the MQTT Ethernet-Ethernet Gateway as broker http://www.mysensors.org/build/mqtt_gateway

    And with MyMQTT on my Smartphone i can see that its working.

    Later i will test the other thing.



  • This may be the fault. The MQTT Gateway is not a broker - it is just a special form of client, it "only" translates messages from the MySensors network into MQTT acceptable forms an supplies Ethernet access. It does not perform any broker function.
    To install a broker you should spend a little time with Mosquitto (http://mosquitto.org/) or http://jpmens.net/2013/09/01/installing-mosquitto-on-a-raspberry-pi/
    In a short way: To install MQTT on your raspberry:

    sudo apt-get update
    sudo apt-get upgrade
    

    to be up to date.

    sudo apt-get install mosquitto mosquitto-clients
    

    this should be enough to get your broker up and running with default parameters.

    Replace the IP-adress in OpenHab accordingly and you should be done.



  • Its not a broker????

    "The MQTT gateway is basically a Ethernet Gateway with modified software which makes it act as a MQTT broker. "
    

    This text in the build instructions has to be fixed. In no minute i thought about installing mosquitto.

    But i hope the installation of mosquitto will get it to work.


  • Plugin Developer

    @Marcus It does act as a broker, only with very limited functions, you do not have to subscribe and also no QOS is done. But it is a broker.

    Just try to connect an mqtt client to it, and you will see messages being received by the client. (for example mqtt.fx)



  • @John
    I use MyMQTT on my smartphone is this a client? There are messages coming in.

    Do i need mosquitto for make mysensors work with openhab or not. Thats the only thing that is interesting for me at the moment.



  • Hi Marcus, I have to confess I mingled up the names and got a little lack of information. I referred to something I tried several months ago - i didn't fit my needs, so I changed back to the serial Interface - which performed reasonably good and i lost contact to the MySensors-MQTT side via Ethernet.

    To my surprise i read there shall be some basic broker functionality in the Gateway sketch - which sounds really good. It will take a while to reactivate my Ethernetshield and give it a try. Sadly my holidays are over tomorrow and there will be not much spare time to test it.

    Nevertheless trying Mosquitto would be interesting, e.g. to talk to the MySensors broker directly and to check the OpenHab->Broker connectivity.



  • Hmm, now i am nearly at the beginning. It would be nice if i dont need mosquitto.

    Maybe here are others who can help.

    Thank u anyway for ur help.

    Are we both the only who want to use openhab???

    Is there no other way to check if openhab recieves the messages from the broker (ethernet gateway)?



  • I am also using openHab 😉 but serial way



  • Is there a big difference between serial and ethernet?



  • @Marcus it works fine for me



  • @Crazy Do u need Mosquitto?



  • I to have had this same problem using openhab and MQTT Gateway. I could toggle relays and such but could not receive any information back from the gateway things such as sketch info or versions. So I decided to pull from that and try PiDome. I like the way PiDome works with the Serial Gateway. Everything seems to be more dynamic. I did try PiDome with the MQTT Gateway and got the same results as with Openhab I could publish information to the gateway but couldn't receive for some reason. Would like to find out what could be happening myself. However right now I'm waiting on parts.



  • @Marcus serial is working fine with piDome, openHab and Vera. No need for mosquito which i never installed and used before.



  • Thank u for your answers.

    I love the look of openhab. So i will try the it with mosquitto.

    If it will not work then i will try pidome and serial gateway.

    If i have new infos i will post them here!



  • Good morning community.

    Here is what i did now for installing mosquitto on my raspberry pi.

    This infos are from here (http://jpmens.net/2013/09/01/installing-mosquitto-on-a-raspberry-pi/).

      curl -O http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
    
      sudo apt-key add mosquitto-repo.gpg.key
    
      rm mosquitto-repo.gpg.key
    
      cd /etc/apt/sources.list.d/
    
      sudo curl -O http://repo.mosquitto.org/debian/mosquitto-repo.list
    
      sudo apt-get update
    
      sudo apt-get install mosquitto mosquitto-clients python-mosquitto
    

    Now mosquitto is running.

    With:

    sudo /etc/init.d/mosquitto stop
    

    I can stop it.

    With

    sudo /etc/init.d/mosquitto start
    

    I can start it.

    But what to do now???
    How do i connect mosquitto to my MQTT-Ethernet-Gateway?
    How do i connect mosquitto to Openhab?

    Please help!



  • MQTT-Ethernet-Gateway is mqtt brocker, not client 😞

    to connect mosquitto try use MQTTClientGateway http://forum.mysensors.org/topic/524/mqtt-client-gateway



  • @b0rmann Please read the whole thread and tell me what to do now!!! I only want openhab and mysensors work together. But i want to use my mqtt-ethernet-gateway. Not the serial way.


  • Plugin Developer

    @Marcus PiDome also supports the mqtt gateway next to the serial gateway, so no need to switch. As far as i know, but i'm not an openhab expert, it should work fine as a mqtt client to connect to the mysensors mqtt gateway.

    See this thread for some examples: http://forum.mysensors.org/topic/303/mqtt-broker-gateway

    The developer of the MQTT gateway has posted some examples in the above thread on how you should be able to use it.

    Cheers!



  • @John Thank u very much. I think i will stop with Openhab and give PiDome a try. it seems to be better described what to do to get it run.

    In the thread u mentioned i looked for some examples but didnt get them to work and no one could help.



  • @Marcus mqtt client gateway is not serial way 🙂

    i have mqtt-client-gateway + raspi (mosquitto + openhab + nodered)


  • Plugin Developer

    @Marcus Wish i could help, too bad it doesn't work. Others are using it successfully as far as i know. Maybe different openhab version install. Well, let me know if there are any issues or help needed with PiDome.



  • @Marcus: Sorry I'm in a hurry so...
    But what to do now??? -> is your broker really ok?

    1. open two terminal windows on your Raspberry.

    2. one window:

      mosquitto_sub -t /test -v

    3. second window:

      mosquitto_pub -t /test -m "test message"

    If it's all fine, the test message should show up in the first window.

    How do i connect mosquitto to Openhab?
    OpenHab -> mosquitto
    If your still got the OpenHab sitemap from above, the swtiches 1+3 should be functional like desribed, switch 2 will result in an errormessage in the log (as "intended").

    Reverse direction (mosquitto -> Openhab).
    You may populate your broker with some messages for the given topic.
    e.g. mosquitto_pub -t MyMQTT/20/255/V_SKETCH_NAME -m "fake sketch name"

    How do i connect mosquitto to Openhab?
    I use the serial Gateway connected via USB to my Raspberry and a little Node.js script.
    If you are interested - let me know.



  • Thank u anyway for your help @tboha . I think this is too much complicated. I tried ur last idea, but i got connection refused error. Really frustrating.... I want to see results. I hope pidome gave me faster results than openhab.



  • Connection refused means (in 99%) your broker is not up or you got the wrong address.
    I supposed you to run mosquitto_sub/pub on the same machine your broker runs on.
    On a different machine you have to add the host address like:

    mosquitto_sub -h 192.168.1.10 -t /topic -m "message".
    

    No - at last its not really complicated, but I think you had just a bad start. MySensors and OpenHab tend to start right out of the box - but you need the right box......



  • Please stop helping me now. Now i have pidome and the first sensor is running after 30 minutes with my ethernet mqtt gateway 😉

    That is what i want. Maybe one day there are nice tutorials for Openhab. Thank u very much for trying to help. If i now start with mosquitto to get openhab run is the same as when i make a patch for a patch....

    It seems that pidome has wait for me it is really nice and not much complicated.

    This thread can be closed here.Unbenannt.JPG



  • @Marcus Try Tim's files and JAR file for serial openHab http://forum.mysensors.org/topic/655/serial-gateway-connection-to-openhab/2
    I added a motion sensor and its fine.


  • Plugin Developer

    @Marcus Good to see you have it working! The MySensors MQTT plugin and serial drivers are quite stable. Some parts of the server can behave a little strange, cause still in heavy development.



  • @John There was a problem with serial....1.6.1.jar it doesnt show this correctly;

    ArduinoUpdate -> 0;0;3;0;9;read: 14-14-0 s=1,c=1,t=16,pt=0,l=1:0
    14;1;1;0;16;0

    i think its related with baud rate for jar file because i saw  these kind of things in terminal ����BO�"U��²e��B&��i�


  • Plugin Developer

    @C.r.a.z.y. That's highly possible, or there was a wrong choice of encoding at the wrong moment.



  • Hi.
    I have OpenHAB, MQTT and battery powered units (http://iot-playground.com/2-uncategorised/10-low-power-door-window-sensor). I cannot receive battery status in Openhab (other things from the same unit are transmitted OK). What is wrong?

    1. I send: gw.sendBatteryLevel(batLevel);
    2. Number node4_bat "Bat [%.1f %%]" <temperature> (node4, GBattery) {mqtt="<[mysensor:MyMQTT/4/255/50:state:default]"}

    I have seen somewhere that battery state is transmitted via '50'?!?



  • Hi. I have figured it out. It is presented as "mysensor:MyMQTT/4/255/V_:state:default". No number in current version from mysensors!!!
    The next step was to edit MyMQTT.cpp: char V_50[] PROGMEM = ""; into char V_50[] PROGMEM = "50";. Now I get battery status via "mysensor:MyMQTT/4/255/V_50:state:default".

    So in conclusion I have answered my own questions and have solved them...



  • coming back to the initial issue, is there anyone that can post items and maps configuration to test the binary switch example of mysensors? my configuration is arduino uno+w5100 and mqtt gateway, opnhab on windows pc on the same network


Log in to reply
 

Suggested Topics

  • 22
  • 2
  • 5
  • 1
  • 10
  • 135

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts