MQTT Broker gateway


  • Code Contributor

    How to Set-up MQTTGateway with OpenHAB

    What is MQTTGateway:
    MQTTGateway will act as a broker, a server. And any MQTT clients should be able to connect to it (Please let me know if you experience problems).
    MQTTGateway is a very simple implementation. It will not care if the client subscribes to anything or not.
    Every node package it receives it will publish to the client. Sketch name and version is also implemented.
    Most clients handle this well and just ignores messages it hasn't been subscribed yet.
    There are some settings in MQTT that can be good to take a look at.
    You will need to configure TCP_IP and TCP_PORT.
    MQTTGateway will also give nodes an ID between MQTT_FIRST_SENSORID and MQTT_LAST_SENSORID. The last position is stored in EEprom.

    As standard MQTT_SEND_SUBSCRIPTION is enabled. This basically means that the broker will send a empty payload to the node upon a subscribe package. This can be useful. Just keep in mind that you can receive empty payload packages.

    The MQTTGateway will also present its SketchName and SketchVersion.

    Lets get started!
    First follow https://github.com/openhab/openhab/wiki/Quick-Setup-an-openHAB-Server You can setup and try with DEMO configuration first.

    Then we need to unpack org.openhab.binding.mqtt into addons folder * NOTE (During development of MQTTGateway I found a bug inside openhab mqtt client which is solved in 1.6.0 nightly build. Use this nightly addon if you experience problems)

    • openhab.cfg
      All you need to do here is to add

      mqtt:mysensor.url=tcp://192.168.0.234:1883
      mqtt:mysensor.clientId=MQTT

    ClientID does not matter at all (just keep it short). And IP and Port is self explanatory.

    Now you can start OpenHAB, it will connect but nothing more will happen.
    This is because we hasn't subscribed to anything and OpenHAB will just ignore every incoming package.

    So here comes a sample configuration of OpenHAB.

    • items/test.items

      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 "Sketch name 20 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/20/255/V_SKETCH_NAME:state:default]"}
      String sketch21 "Sketch name 21 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/21/255/V_SKETCH_NAME:state:default]"}
      String sketch22 "Sketch name 22 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/22/255/V_SKETCH_NAME:state:default]"}
      String sketch23 "Sketch name 23 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/23/255/V_SKETCH_NAME:state:default]"}
      String sketch24 "Sketch name 24 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/24/255/V_SKETCH_NAME:state:default]"}
      String sketch25 "Sketch name 25 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/25/255/V_SKETCH_NAME:state:default]"}
      String sketch26 "Sketch name 26 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/26/255/V_SKETCH_NAME:state:default]"}
      String sketch27 "Sketch name 27 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/27/255/V_SKETCH_NAME:state:default]"}
      String sketch28 "Sketch name 28 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/28/255/V_SKETCH_NAME:state:default]"}
      String sketch29 "Sketch name 29 [%s]" (sketch,all) {mqtt="<[mysensor:MyMQTT/29/255/V_SKETCH_NAME:state:default]"}

    We also need to create a sitemap :

    • sitemap/test.sitemap

      sitemap demo label="Menu"
      Frame label="test" {
      Group item=node1 label="Temp hum node"
      Group item=node2 label="Switch node"
      Group item=sketch label="Sketch names"
      Group item=all label="Everything"
      }

    and a simple transformation file :

    • transform/1on0off.map

      1=ON
      0=OFF

    If everything worked and I didn't forget anything just fire up :

    http://[Openhab]:8080/openhab.app?sitemap=test

    After you restart one of your node's the data and sketch name should be visible.
    Openhab will forget everything after every restart. Use persistence to fix this (https://github.com/openhab/openhab/wiki/rrd4j-Persistence)


  • Mod

    @Damme Hey man, thanks for the extensive documentation!
    Would you mind if I split this post into its own topic? I think your MQTT broker deserves its own topic; let's reserve this thread for OpenHAB+MQTT related stuff.

    Update Split done!


  • Code Contributor

    @Yveaux sure



  • So have I got this right.....?

    This will mean that I can build an arduino with an ethernet port and a radio, and this will then plug in to an ethernet port and be what my other ardiuno sensors will connect to, and it will send everything to my Vera?


  • Code Contributor

    @Homer For Vera you should build http://mysensors.org/build/ethernet_gateway

    MQTTGateway is a MQTT broker (server), used for mqttclient like openhab for example.



  • @Damme said:

    @Homer For Vera you should build http://mysensors.org/build/ethernet_gateway

    MQTTGateway is a MQTT broker (server), used for mqttclient like openhab for example.

    Ok. I was hoping that this device would enable me to have some of my sensors connected to ethernet so I can power them as well. Rather than sending information over wireless, they would do so via ethernet.

    There isn't a way to do as I have described above, right?


  • Code Contributor

    @Homer I'm sorry but I don't think I really understand your question.
    read http://mysensors.org/build/network
    Each node (with sensors) talk wireless to A gateway, which then talks to a controller (in your case Vera) this can be via RS232 OR ethernet.

    If you have something that talks MQTT (like openhab) as a controller, then your choice could be sensors <-> MQTTgateway <-> openhab instead.


  • Code Contributor

    I can confirm it's working with UIPEthernet.h and the ENC28J60 module as well. You need to turn off debugging in MyConfig.h to make the code fit.


  • Code Contributor

    @ToSa Thanks! I havn't had time to get and test that module.


  • Code Contributor

    @ToSa said:

    I can confirm it's working with UIPEthernet.h and the ENC28J60 module as well. You need to turn off debugging in MyConfig.h to make the code fit.

    Maybe that was a little too fast - it starts up and starting OpenHAB finds the gateway and connects. When I reset a node it appears that the gateway crashes (OpenHAB reports disconnect) and only a reset of the gateway helps to get it to work again. Problem is it's hard to debug without debugging enabled due to code size 😞


  • Code Contributor

    @ToSa if possible you could make a tcpdump over the mqqt port and I'll look at it. Also a serial dump from the node would be great


  • Code Contributor

    @Damme said:

    @ToSa if possible you could make a tcpdump over the mqqt port and I'll look at it. Also a serial dump from the node would be great

    After changing the include from Ethernet.h to UIPEthernet.h the sketch fits into the m328 only with DEBUG (and TCPDUMP) turned off:

    DEBUG / TCPDUMP turned off:
    Sketch uses 30,626 bytes (99%) of program storage space. Maximum is 30,720 bytes.
    Global variables use 1,330 bytes (64%) of dynamic memory, leaving 718 bytes for local variables. Maximum is 2,048 bytes.

    DEBUG / TCPDUMP turned on:
    Sketch uses 32,354 bytes (105%) of program storage space. Maximum is 30,720 bytes.
    Global variables use 1,393 bytes (68%) of dynamic memory, leaving 655 bytes for local variables. Maximum is 2,048 bytes.
    processing.app.debug.RunnerException: Sketch too big;

    The only thing I have right now to look at is the OpenHAB output (appears that it's not happening when I reset a node but rather random):

    pi@openhab ~/runtime $ ./start.sh
    Launching the openHAB runtime...
    osgi> 19:54:19.384 INFO o.o.c.internal.CoreActivator[:61] - openHAB runtime has been started (v1.6.0).
    19:54:39.316 INFO o.o.i.t.mqtt.MqttService[:106] - MQTT Service initialization completed.
    19:54:39.322 INFO o.o.i.t.m.i.MqttBrokerConnection[:112] - Starting MQTT broker connection 'mysensor'
    19:54:42.838 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'logging.persist'
    19:54:46.082 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'exec.persist'
    19:54:46.261 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'rrd4j.persist'
    19:54:46.494 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'db4o.persist'
    19:54:47.009 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'test.items'
    19:55:01.187 INFO o.o.i.s.i.DiscoveryServiceImpl[:72] - mDNS service has been started
    19:55:10.219 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'test.sitemap'
    19:55:19.042 INFO o.o.io.rest.RESTApplication[:143] - Started REST API at /rest
    19:55:24.936 INFO o.o.u.w.i.s.WebAppServlet[:79] - Started Classic UI at /openhab.app
    19:55:35.271 ERROR o.o.i.t.m.i.MqttBrokerConnection[:478] - Error starting consumer
    org.eclipse.paho.client.mqttv3.MqttException: Connection lost
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138)
    Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    19:55:35.298 ERROR o.o.i.t.m.i.MqttBrokerConnection[:532] - MQTT connection to broker was lost
    org.eclipse.paho.client.mqttv3.MqttException: Connection lost
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138)
    Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    19:55:35.305 ERROR o.o.i.t.m.i.MqttBrokerConnection[:536] - MQTT connection to 'mysensor' was lost: Connection lost : ReasonCode 32109 : Cause : Connection reset
    19:55:35.310 INFO o.o.i.t.m.i.MqttBrokerConnection[:543] - Starting connection helper to periodically try restore connection to broker 'mysensor'
    19:55:45.317 INFO o.o.i.t.m.i.MqttBrokerConnection[:112] - Starting MQTT broker connection 'mysensor'


  • Code Contributor


  • Code Contributor

    @Damme said:

    @ToSa wireshark dump https://www.wireshark.org/ or tcpdump http://www.tcpdump.org/

    Thought you were referring to the "#define TCPDUMP" in MyMQTT.h 🙂

    I did "sudo tcpdump host 10.0.1.99 -i eth0 -w dump.pcap" on the RPi that is running the OpenHAB runtime (10.0.1.6 is the IP of the RPi with OpenHAB / 10.0.1.99 is the IP of the MQTT gateway) and then did the following:

    • power-on MQTT gateway
    • start OpenHAB and wait until startup finished
    • power-on node with DallasTemperature

    The pcap file is attached (not knowing a lot about the protocol it looks like a series of keep-alive messages only and suddenly a connection reset): dump2.pcap

    I do not see any messages arriving at OpenHAB... looking at the debug output from the node it appears that the "find parent" message is correctly handled by the gateway but the "node ID request" is not.

    ** OpenHAB output: **

    pi@openhab ~/runtime $ ./start.sh
    Launching the openHAB runtime...
    osgi> 21:55:31.305 INFO o.o.c.internal.CoreActivator[:61] - openHAB runtime has been started (v1.6.0).
    21:55:50.955 INFO o.o.i.t.mqtt.MqttService[:106] - MQTT Service initialization completed.
    21:55:50.974 INFO o.o.i.t.m.i.MqttBrokerConnection[:112] - Starting MQTT broker connection 'mysensor'
    21:55:57.178 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'logging.persist'
    21:55:59.989 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'exec.persist'
    21:56:00.137 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'rrd4j.persist'
    21:56:00.303 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'db4o.persist'
    21:56:01.162 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'test.items'
    21:56:13.732 INFO o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'test.sitemap'
    21:56:16.231 INFO o.o.i.s.i.DiscoveryServiceImpl[:72] - mDNS service has been started
    21:56:31.603 INFO o.o.io.rest.RESTApplication[:143] - Started REST API at /rest
    21:56:37.387 INFO o.o.u.w.i.s.WebAppServlet[:79] - Started Classic UI at /openhab.app
    21:59:50.613 ERROR o.o.i.t.m.i.MqttBrokerConnection[:532] - MQTT connection to broker was lost
    org.eclipse.paho.client.mqttv3.MqttException: Connection lost
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138)
    Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    21:59:50.621 ERROR o.o.i.t.m.i.MqttBrokerConnection[:536] - MQTT connection to 'mysensor' was lost: Connection lost : ReasonCode 32109 : Cause : Connection reset
    21:59:50.625 INFO o.o.i.t.m.i.MqttBrokerConnection[:543] - Starting connection helper to periodically try restore connection to broker 'mysensor'
    22:00:00.633 INFO o.o.i.t.m.i.MqttBrokerConnection[:112] - Starting MQTT broker connection 'mysensor'

    ** The serial debug output of the node shows (more than that but always repeating as I did several resets of the node): **

    sensor started, id 255
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:
    send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:
    req node id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,st=fail:


  • Code Contributor

    @ToSa Thats odd. Everything looks good...(almost, there are some excess of trailing 0x00 but shouldn't matter, but I'll look at that anyways..)
    Can you compile with myconfig debug enabled, but define tcpdump disabled? or is it too big that way too?


  • Plugin Developer

    @Damme

    I'm currently busy implementing an mqtt client plugin, and i'm going to use mysensors for it's first predefined implementation so i have a couple of questions

    I took a look at the api page and saw this in the mqtt documentation:

    [MQTT_BROKER_PREFIX]/[NodeID]/[SensorID]/V_[SensorType]
    

    Does this means as example:

    MyMQTT/[0-255]/[0-255]/[STRING]/[VALUE]
    

    OR this?

    MyMQTT/[0-255]/[0-255]/[0-endvarindex]/[VALUE]
    
    • Are variable types defined by their index used or by name?
    • Also it states it keeps track of node id's how are these reported by the broker, should the controller still hand out free id's?

    [EDIT]
    I currently do not have the hardware present to at least set it up to test and look at what exactly is happening.
    [/EDIT]


  • Code Contributor

    @John MyMQTT/[0-255]/[0-255]/[STRING]/[VALUE]

    MQTT.cpp :

    sprintf(&buffer[buffsize],"/%i/%i/V_%s", msg.sender, msg.sensor, getType(convBuf, &vType[msg.type]));
    

    note V_%s -> MyMQTT/[0-255]/[0-255]/V_[STRING]/[VALUE]
    also note there is no trailing / before payload, as http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html
    http://mqtt.org/wiki/doku.php/topic_format
    I choose not to have trailing slash, but if needed its easy to make it configurable.

    and get type translates from this list

      char V_0[] PROGMEM = "TEMP";		//V_TEMP
      char V_1[] PROGMEM = "HUM";		//V_HUM
      char V_2[] PROGMEM = "LIGHT";		//V_LIGHT
      char V_3[] PROGMEM = "DIMMER";		//V_DIMMER
      char V_4[] PROGMEM = "PRESSURE";	//V_PRESSURE
      char V_5[] PROGMEM = "FORECAST";	//V_FORECAST
      char V_6[] PROGMEM = "RAIN";		//V_RAIN
      char V_7[] PROGMEM = "RAINRATE";	//V_RAINRATE
      char V_8[] PROGMEM = "WIND";		//V_WIND
      char V_9[] PROGMEM = "GUST";		//V_GUST
      char V_10[] PROGMEM = "DIRECTON";	//V_DIRECTON
      char V_11[] PROGMEM = "UV";		//V_UV
      char V_12[] PROGMEM = "WEIGHT";		//V_WEIGHT
      char V_13[] PROGMEM = "DISTANCE";	//V_DISTANCE
      char V_14[] PROGMEM = "IMPEDANCE";	//V_IMPEDANCE
      char V_15[] PROGMEM = "ARMED";		//V_ARMED
      char V_16[] PROGMEM = "TRIPPED";	//V_TRIPPED
      char V_17[] PROGMEM = "WATT";		//V_WATT
      char V_18[] PROGMEM = "KWH";		//V_KWH
      char V_19[] PROGMEM = "SCENE_ON";	//V_SCENE_ON
      char V_20[] PROGMEM = "SCENE_OFF";	//V_SCENE_OFF
      char V_21[] PROGMEM = "HEATER";		//V_HEATER
      char V_22[] PROGMEM = "HEATER_SW";	//V_HEATER_SW
      char V_23[] PROGMEM = "LIGHT_LEVEL";	//V_LIGHT_LEVEL
      char V_24[] PROGMEM = "VAR1";		//V_VAR1
      char V_25[] PROGMEM = "VAR2";		//V_VAR2
      char V_26[] PROGMEM = "VAR3";		//V_VAR3
      char V_27[] PROGMEM = "VAR4";		//V_VAR4
      char V_28[] PROGMEM = "VAR5";		//V_VAR5
      char V_29[] PROGMEM = "UP";		//V_UP
      char V_30[] PROGMEM = "DOWN";		//V_DOWN
      char V_31[] PROGMEM = "STOP";		//V_STOP
      char V_32[] PROGMEM = "IR_SEND";	//V_IR_SEND
      char V_33[] PROGMEM = "IR_RECEIVE";	//V_IR_RECEIVE
      char V_34[] PROGMEM = "FLOW";		//V_FLOW
      char V_35[] PROGMEM = "VOLUME";		//V_VOLUME
      char V_36[] PROGMEM = "LOCK_STATUS";	//V_LOCK_STATUS
      char V_37[] PROGMEM = "DUST_LEVEL";	//V_DUST_LEVEL
      char V_38[] PROGMEM = "VOLTAGE";	//V_VOLTAGE
      char V_39[] PROGMEM = "CURRENT";	//V_CURRENT
      char V_40[] PROGMEM = "";		//
      char V_41[] PROGMEM = "";		//
      char V_42[] PROGMEM = "";		//
      char V_43[] PROGMEM = "";		//
      char V_44[] PROGMEM = "";		//
      char V_45[] PROGMEM = "";		//
      char V_46[] PROGMEM = "";		//
      char V_47[] PROGMEM = "";		//
      char V_48[] PROGMEM = "";		//
      char V_49[] PROGMEM = "";		//
      char V_50[] PROGMEM = "";		//
      char V_51[] PROGMEM = "";		//
      char V_52[] PROGMEM = "";		//
      char V_53[] PROGMEM = "";		//
      char V_54[] PROGMEM = "";		//
      char V_55[] PROGMEM = "";		//
      char V_56[] PROGMEM = "";		//
      char V_57[] PROGMEM = "";		//
      char V_58[] PROGMEM = "";		//
      char V_59[] PROGMEM = "";		//
      char V_60[] PROGMEM = "Started!\n";	//Custom for MQTTGateway
      char V_61[] PROGMEM = "SKETCH_NAME";	//Custom for MQTTGateway
      char V_62[] PROGMEM = "SKETCH_VERSION"; //Custom for MQTTGateway
      char V_63[] PROGMEM = "UNKNOWN"; 	//Custom for MQTTGateway
      char V_64[] PROGMEM = "FW_CREQ"; 	//Custom for MQTTGateway
      char V_65[] PROGMEM = "FW_CRES"; 	//Custom for MQTTGateway
      char V_66[] PROGMEM = "FW_REQ"; 	//Custom for MQTTGateway
      char V_67[] PROGMEM = "FW_RES"; 	//Custom for MQTTGateway
    

    The MQTTgateway hands out ID's; configured in MQTT.h:

      #define MQTT_FIRST_SENSORID	20  		// If you want manually configured nodes below this value. 255 = Disable
      #define MQTT_LAST_SENSORID	254 		// 254 is max! 255 reserved.
      #define MQTT_BROKER_PREFIX	"MyMQTT"	// First prefix in MQTT tree, keep short!
      #define MQTT_SEND_SUBSCRIPTION 1		// Send empty payload (request) to node upon MQTT client subscribe request.
      // NOTE above : Beware to check if there is any length on payload in your incommingMessage code:
      // Example: if (msg.type==V_LIGHT && strlen(msg.getString())>0) otherwise the code might do strange things.

  • Plugin Developer

    @Damme
    Clear!

    And how about the internal messages? Are these somewhat compatible with the Serial API? Like this one now has a "I_GATEWAY_READY" internal var, this one complies then with the "Started!\n" message?

    Also about the presentation (if the node does it), are these also passed through?

    I know it's a bit question banging... But i just want to do it right.


  • Code Contributor

    @John No worries! 🙂
    Presentation is On Todo.. Or Rather To think About list is presentation . I dont do anything with that as it is (Just ignores it). I havn't had any good idea for that yet.

    Internal is nothing more or less, it connects and set a variable that it is connected. 🙂 But sure, there could be transport for internal messages also.
    I do have an experimental version there I can send internal messages to reboot node, reboot gateway and set clear read eeprom values. (over mqtt-protocol) but this s not finnished yet.. Ideas are welcome!


  • Code Contributor

    @John About Presentation ; My idea was that next version of the variable system I will either store some bytes in the MQTT gateway about what S_types to V_types, or hopefully the next protocol contains both those so the GW doesnt have to remember. And then add an extra directory to the MQTT path ( MyMQTT/[0-255]/[0-255]/S_[STRING]/V_[STRING]/[VALUE]


  • Plugin Developer

    I think maybe it depends on the next protocol implementation. Personally i wouldn't mind if the full path mapping was /[0-255]/[0-255]/etc.. to keep (prog)mem print smaller (use the V_ and S_ array index values). It could leave space for more specific things or some extra gateway specific functions.

    it would be nice if the mqtt gateway output was "cloned" to the serial output. Controllers should/could be able to map the S_ and V_ types internally. I'm not aware of the openhab config if that would allow this, or that such a setup would require a lot of coding at openhab side.

    [EDIT]
    It would be more difficult to read though if a path would only exist of numbers. But could also introduce easier maintainability in your library because you wouldn't have to keep track on type namings.
    [/EDIT].


  • Code Contributor

    @John That was my first aproach, and I might set a define configuration to choose if the MQTT gateway should translate or not. As you say, the footprint would be much smaller.
    Might be next version of the MQTT, slectable address layout 🙂


  • Plugin Developer

    @Damme
    That would be really cool 🙂

    It would be nice though if there was a way to identify node id's with AUTO turned on. Maybe i'm missing something or do you have to know up front with auto enabled which node id is going to be assigned?

    I'm just asking this because of identifying new/existing nodes in the network. Is it the V_SKETCH_NAME i can refer to?

    And i hope some last questions protocol specific:

    • Version compatibility is 3.1?
    • All session are clean by default?

  • Code Contributor

    @John upon node startup it translates gw.sendSketchInfo("Battery Meter", "1.0"); into MyMQTT/20/255/V_SKETCH_NAME and version

    so you could have a list as in my first post and it would get filled up with all your sketch names

    @John ; Yes and I hope so 🙂 (I might have missed some stuff, I do not take regard of QOS etc)
    if its not working,, I'll try to fix it 🙂


  • Plugin Developer

    @Damme
    Thanks for all the info. It becomes more clear now, All nodes users add are persistent anyway.


  • Code Contributor

    @ToSa I'll update mqtt later with option to not translate V_TYPE into name string but to keep it as a byte, that would save a lot of memory and might solve problem you have. I'll keep you posted


  • Hero Member

    As I understand it:

    MySensors_formats.gif

    The packet on the left would be from the node, the packet on the right would be to the node. Besides swapping sender and destination, the difference is that in 1.4 the gateway does not have the information to binary encode the value, so it sends the value as a string (payload type 0).
    EDIT: added alternate MQTT respresentation of V_code as numeric


  • Code Contributor

    @Zeph but soon there will be a choise to translate v_ to text string or keep it as a byte value


  • Hero Member

    At first, I thought MQTT would be a great extension to the functionality, in particular because it might systematize the idea of routing messages to more than one destination - eg: to both a HA controller and to a cloud storage service.

    So I saw these possible advantages of MQTT:

    • Route to multiple destinations, dynamically updated
    • Subscription wildcards to filter for desired subsets
    • Possibly easier to build plug-ins for some HA controllers

    As I look deeper into it, I'm coming to wonder about that.

    • There are lighter weight ways to send to more than one destination
    • Does subscription wildcarding meet the filtering needs well (below)?
    • Is it easier or not?

    I'm wondering what subscription wildcards really get used - how valuable is the type of filtering functionality offered by MQTT for our purposes? The meaingful patterns I would imagine are:

    • everything
    • everything from one node
    • everything from one child of one node
    • everything of type V_RAIN from one child of one node (ie: one variable)
    • everything of type V_RAIN from anywhere

    Are any of these (or other options) in use except "everything"? Do you anticipate that they will be?

    Just as "route to multiple destinations" could be lighter, filtering could be done differently as well. For example, suppose you wanted to receive all report of inside temperature (7 sensors in your network) or humidity (5 sensors), but not outside temp or humidity and not other v codes. That might take 12 subscriptions - and they would have to be manually set up, or make use of manually entered metadata tables in the controller plug-in (eg: the plug-in might be configured to know which nodes had temp and/or humidity, and which ones were considered "inside", if it was written to handled that).

    I could imagine that even if the subscription filtering wasn't highly useful, MQTT might make it easier to create plug-ins for some HA controllers, than using semicolon separated values (serial text format). Is that the case?

    I'm very open to hearing other advantages of MQTT, I'm not against it, just trying to understand the benefits vs cost aspect better.


  • Hero Member

    The other extension that occurs to me, in the gateway-as-transparent-switch model, is that if we ever wanted to encode binary values OTA from the gateway to the node, the plug-in would have to tell the gateway which payload_type to use. In the Semicolon Separted Values format, that could be another parameter, eg:

    <node id>;<child id>;<command>;<ack>;<v_code>;<payload_type>;<value>
    

    Or it could be added to one of the other fields with a comma sub-delimiter, etc.

    How would a controller plug in tell the MQTT gateway to use payload type P_UNIT16 to send to node 7?

    I'm thinking that it would be done in the value string, rather than encoded into the topic. So maybe the value string goes from "321" to "4,321" or something like that.


  • Plugin Developer

    @Damme
    What happens if a node does not receive it's address when it requests one (because of failed send). It is not registered within the broker?


  • Code Contributor

    @Damme said:

    @ToSa I'll update mqtt later with option to not translate V_TYPE into name string but to keep it as a byte, that would save a lot of memory and might solve problem you have. I'll keep you posted

    I could not follow the discussions the last few days - will definitely have a look over the weekend and let you know if that worked. Thanks!


  • Plugin Developer

    @Damme
    When the MQTT gateway prints information about itself like "started", is this done with node id 0 or 255?


  • Code Contributor

    @John 'started' is only a internal log message, I've changed how that part works.

    I've also fixed a couple of bugs and will test the changes tomorrow before I publish them.
    New functionallity there user can choose of MQTT should translate ID to V_TYPE or not too.


  • Plugin Developer

    @Damme
    Ok, my plugin will then just try to reconnect.

    Ok, i will check that then probably the day after tomorrow, i will make my code take no translation as first and if not found try the naming (internally), because the server takes over the semantics anyway because it also is going to include a MQTT broker service.

    Currently the MQTT implementation is being tested with an end user. Maybe he will help test the new possibility without V_TYPE translation when your changes are implemented.


  • Plugin Developer

    @Damme
    When does exactly the messages like "MyMQTT/[NODEID]/255/V_SKETCH_NAME" and/or "MyMQTT/[NODEID]/255/V_SKETCH_VERSION" appear? is this only when an address is assigned or always when a node is started?


  • Code Contributor

    @John then node is started, There was a bug not processing that message which is fixed now.
    hasn't been pulled to official yet but can be found at https://github.com/Damme/MQTTGateway/commit/f10843f5efd9c37900624fe57275be11c69e3942


  • Plugin Developer

    @Damme
    Thnx, was struggling with this with a user. Will need to wait for the next release :).



  • @Damme when will the new release be available?



  • Dear colleagues,

    I have been using OpenHAB for a couple of days now, everything is going the right way, I've been using it with mosquitto broker for Windows, everything is solid, working well an fast. Decided to go a step further and use the MQTT Gateway presented here.

    I've made a MQTT Gateway but get the "Not connected to broker" message from OpenHAB. First of all, the Gateway is an arduino uno with a w5100 shield on top in which I inserted the RF module (NRF24L01). Configured my ip in the gateway sketch (192.168.1.11) and uploaded to the arduino.

    The first test was to connect with a phone (using MQTT from Playstore - used it many times before) and with a PC (using WMQTT Utility - used it many times before) and things don't look that promising, the problem beeing that client somethimes disconnects, and I cannot receive the message published in a topic (topic that I am subscribed to on the phone, pc and tablet using MQTT clients). I somethimes get the message in the serial monitor of the arduino, somethimes not.

    Configured openhab.cfg to use the mqtt broker at 192.168.1.11 (before I was using mosquitto on pc 192.168.1.10 and working without problems) and everythime I change state of something in the dashboard of openhab I get this Broker Connection not Started even if after starting openhab I get serial output from arduino for some time, after this everything drops. Here is the serial output:serial_output.txt

    Last two entries are: I opened the MQTT client on my phone, connected to MQTT Gateway and subscribed to topic home/# and the last one is me publishing from the phone to topic home/test the message "test message". None of the messages come back to the clients on the phone, tablet, pc, all of them subscribed to home/#

    And here is the output from openhab: openhab_output.txt Ignore the samsung connect stuff, I have pull it off the network, i have managed to get it working well.

    Best regards,

    Adrian


  • Code Contributor

    @adrianmihai83 "home/openHAB/out/Temperature_GF_Corridor/state" is probobly long string, 47 chars. I have not investigated exacly how long it can be but keep it short. And the adress layout is also wrong, is should be something like MyMQTT/21/1/V_LIGHT . MQTTGateway is not compatible with the mosquitto broker you're using.



  • @Damme , your instructions were highly appreciated, got it working the first time. I will start creating the network now, I guess that everything will be ok. Will follow this forum for info and knowledge.

    Now I will migrate openHAB to Rasberry Pi and add all the sensors one by one, there are a few.

    A question though: I am using the humidity sketch and get MyMQTT/0/1/V_TEMP and MyMQTT/0/0/V_HUM reading fine but I cannot get sketch name... I don't know what I am doing wrong... Read above and I guess I have to wait for new version?

    Thank you.

    Adrian

    Edit: Read more about Rasbery Pi capabilities regarding openHAB and I think I will use a cubietruck... Does anybody use one, cubieboard 2 or cubietruck?


  • Code Contributor

    @adrianmihai83 Sketch-name was a bug that I fixed in development branch, thought @hek updated master branch also. I can post the fix later on in here.



  • Maybe a dumb question but I don't figure things, here is my problem:

    Uploaded the relay sketch to the same arduino that I used for humidity/temperature node (I don't know if this is relevant, the network has only one node, this one). Modified the pin that the relay is connected to: #define RELAY_1 4.

    I am using the MQTT Gateway openHAB and cannot activate the relay...

    Serial output of relay sketch is:
    repeater started, id 0
    send: 0-0-0-0 s=255,c=0,t=18,pt=0,l=3,st=ok:1.4
    send: 0-0-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    send: 0-0-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Relay
    send: 0-0-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 0-0-0-0 s=1,c=0,t=3,pt=0,l=3,st=ok:1.4

    Serial output of gateway is:
    Started!
    0;0;3;0;9;read: 0-0-0 s=255,c=0,t=18,pt=0,l=3:1.4
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=6,pt=1,l=1:0
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=11,pt=0,l=5:Relay
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=12,pt=0,l=3:1.0
    0;0;3;0;9;read: 0-0-0 s=1,c=0,t=3,pt=0,l=3:1.4

    My openHAB configuration is:

    Switch node2_sw1 "sw2" (node2,all) {mqtt=">mysensor:MyMQTT/0/1/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/0/1/V_LIGHT:command:OFF:0]"}

    What am I doing wrong?

    Thank you!



  • If I run the MQTTGateway my temperature shows in fahrenheit when I run the same nodes on a SerialGateway it is showing Celsius why will this be the case?



  • Downloaded from https://github.com/Damme/MQTTGateway latest MQTT Gateway (the one that responds on serial with "Ok!" not "Started!", with the modifications to MySensors.cpp) but no difference, still no sketch name and with the above settings, openHAB cannot control the relay sensor...

    I used the same arduino that is working with Temp_Humidity sensor so the setup is good, the relay pins are specified in the sketch. I used the Clean_Eeprom_Config before uploading, I even used other Arduino Uno, no diffrerence, still cannot control the relay sensor from openHAB.

    Anyone has a clue, a hint or something? The serial output from both the sensor and the gateway, together with openHAB configuration are two posts up.

    Edit: 3 hours later and managed to make many of the sensors (Door, Distance, Dust, Gas, Humidity, Light, Motion) everyone working in conjunction with MQTT Gateway and openHAB except the Relay one...

    Any help is appreciated.

    Regards,
    Adrian



  • Callback for incomming messages does not occur so I guess that the message does not get to the relay sensor. Is there someone that is using this with MQTT Gateway and openHAB?



  • @adrianmihai83 I was testing this today and it was working with the MQTTGateway. Here is my config file same as above:

    Switch node2_sw2 "Study Lights" (node2,all) { mqtt=">[mysensor:MyMQTT/2/1/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/2/1/V_LIGHT:command:OFF:0],<[mysensor:MyMQTT/2/1/V_LIGHT:command:MAP(1on0off.map)]" }

    Here is the info from the serial port monitor.

    upload-805fea56-06b2-4632-a2c0-fb8cd80a8ec5



  • Will test it tomorrow morning and come back with result, what i see is exactly the same configuration, the only difference is that your's is on the 3'rd node and mine on 1'st node. Anyway, will see.

    Thank you for your answer.

    I am still waiting for my other NRF24L01 ( I ordered 30 pcs), they will arive this week. Maybe there is a problem running the sketch on node one, id 0. Tomorrow I will go and buy 2 of the NRF24 from a store even if they are 4 times more expensive, this not working is killing me 🙂



  • Why is the broker offering me the same id for all of the sensors? I start the first one, broker offers me id 0, without disconnecting it I connect the second sensor and the gateway offers me same id, id=0.

    I have cleared eeprom to both of them and see the requesting id first time i power them up, but still same id for both...

    Edit 1:

    Defined static ID and the relay works, didn't modify anything, just static ID 2 to the relay...

    Edit 2:

    Just tested with ID 0, 1 and 2 and I can confirm that the relay does NOT work with ID 0, it's almost a week now and I have tried everything and the answer was as simple as this: does not work with ID 0.


  • Hero Member

    By ID do you mean node ID? If so, the gateway has node ID 0, so I'm not surprised if it's not good for other nodes.

    But you may be talking about a child ID or something else.



  • Yes, I am talking about node ID, but what I can tell you is that until two days ago I didn't assigned node ID manual and I didn't have 3 NRF's to test with gateway + 2 nodes. Only when I got other RF's and made a couple of sensors saw that the gateway is assigning node ID 0 to all of the sensors, and all sensors worked, for example:

    1. temp humidity node had Node ID 0 and Child 0 and 1, and from openHAB I could use them at MYMQTT/0/0/V_HUM and MYMQTT/0/1/V_TEMP
    2. motion sensor at MYMQTT/0/2/V_MOTION
    3. and do on, other 2 sensors, all I had to take care is that all of them had distinct Child ID

    Only when I got other NRF's and could make sensors and use them in paralel saw that the gateway is offering NODE ID 0 to all of my sensors, I don't know why, checked MYMQTT.h and it was set to auto assign Node ID, even in the statemant gateway.begin() assumes that the gateway should auto assign Node ID, and gw.begin(incomingMessage, AUTO, true) states it clear that relay sensor should get Node ID from the gateway.

    All I did is manual assigned nodes for every one and workking like a charm. I simply like it this way, it let's more control, it's simply more "my way".

    Now I want to combine some of the sensors and use a Mega2560 for this, hoping for a nice outcome.


  • Plugin Developer

    This post is deleted!

  • Code Contributor

    @John Could you send me log from MQTTgateway also? (or tcpdump)


  • Plugin Developer

    This post is deleted!


  • I have a next problem:
    OpenHAB (192.168.1.3) <-> Arduino GW mqtt (192.168.1.234:1883)<-> Arduino TEMP (DHT)

    org.eclipse.paho.client.mqttv3.MqttException: ═х єфрхЄё  яюфъы■ўшЄ№ё  ъ ёхЁтхЁє
    at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNet
    workModule.java:75)
    at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(Cli
    entComms.java:538)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNet
    workModule.java:66)
    at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(Cli
    entComms.java:538)
    at java.lang.Thread.run(Unknown Source)

    with ping everything is ok.
    test


  • Plugin Developer

    This post is deleted!


  • I connected the serial to MQTT GW:
    If I have connected Wiznet, I've got "0;0;3;0;9;check wires",
    if i disconnected Wiznet then got "Started!"


  • Plugin Developer

    @Damme
    You can forget about my posts, after some quite intensive debugging i found out there was an ugly inconsistent race condition going on in my app. Issue is gone now.



  • Could anyone help me with running MQTTGateway with enc28j60 ethernet module? Should a gateway respond to ping? Openhab says 'no route to host'. Should i change anything else than Ethernet.h to UIPEthernet.h in source code ?


  • Code Contributor

    I just wanted to say hello again to everyone. I had to disappear for a while. Just had too much for my brain to handle. So all my automation project were on halt but will be continued again.

    I know there are lot of bugs in this GW and I will hopefullt start developing soon again. Just write your experience you had so far and I'll try to keep up 🙂

    //Damme


  • Plugin Developer

    @Damme Good luck!



  • @Damme I tried today the mysensor 1.4.1 library, uploaded with Arduino 1.5.8 to UNO with Ethernet Shield (W5100) and an NRF24L01+pa+lna. Compilation and upload worked fine.
    I can ping the IP address defined in the MQTTGateway.ino sketch.
    I maintained on my RPI the openhab.cfg file with the url and port number from the gateway.
    When starting the openhab it shows:
    ... - MQTT Service initialization completed.
    ... - Starting MQTT broker connection 'mysensor'.

    Then a couple of message later:
    ...Mqtt Exception
    Caused by: java.net.SocketTimeoutException: connect timed out

    Any suggestion what I could look at.

    I also tried to work with the development library of Mysensors but did not get very far with that. My ultimate goal is to something like a moteino with the RFM69HW radio module in connection with either openhab or pidome.
    I have a quite a bit of hardware lying around here so I am happy to do any testing if somebody gives me some guidance.
    Thanks.



  • This post is deleted!


  • Thanks for the mqtt broker. Just a tip to people who might fall in to the same pit as I:

    The mqtt broker gateway doesn't distribute node ids unless you're connected to it using a mqtt client. I.e. if you did what I did, installed the gateway and wanted to test that the sensors found the gateway and was distributing the code then it doesn't work until you've connected to it. I had to go through the source code to figure it out.

    If you don't have openhab or simply want to test, this is what I did on my raspberry (but should work similarly on others)

    // install mosquitto client
    sudo apt-get install mosquitto-clients

    // Start the client, replace the 10.0.0.200 with your ip. The port will default to 1883

    mosquitto_sub -h 10.0.0.200 -d -t hello/world -v

    You should be able to see messages:
    Received PUBLISH (d0, q0, r0, m0, 'MyMQTT/20/0/V_LIGHT_LEVEL', ... (2 bytes))



  • Hi All

    Just a simple question:

    Are there any limitation in how many MQTT connections/sessions the MQTT Gateway can handle?

    If so, can this be changed?



  • Hello. I am new to Mysensors, openhab and mosquitto.. I have a working knowledge of arduino and nrf24l01, and currently am running a wireless(nrf) twitter controlled heating scheduler, and am sending multiple temp (ds18b20) sensors to Xively feed.

    I am really hooked on the idea of mqtt and openhab, and i thought that mysensors seemed like a good solution for implementing that idea.

    My progress so far is to install the DallasTemperatureSensor by MySensors node to one nano, and the ethernet gateway sketc as a first step, and now i have installed the mqttgateway again from the build page, and i have a working install of mosquitto and openhab on a rasp pi b+.

    I am just having difficulty getting it all stuck together. I have created the sitemap items and transform files as above and can access the openhab sitemap for the above configuration. i just don't know if i need to configure other items? how can i test each step? and can i use mosquitto with the setup that i have outlined. There seems to be conflicting info about what can and cannot be done with mosquitto and mysensors.

    1 do i need to modify the sketch of the temp node? i have some output from the serial that suggests that it is communicating with the gateway.
    2 do i need to modify the gateway with info of the mosquitto server?
    3 what can i do to test each step of the transit from temp sensor to openhab?

    Thanks for any and all responses.



  • Hello!

    I've downloaded the 1.4.1 version of the library and tested it via OpenHab.
    I'm still not getting the sketch_name correctly via MQTT and Openhab. Is it still an open bug?

    Thanks!

    Simon



  • Hi Simon,
    I had the same problem
    I tried several time clean Eeprom and flash sketch again but with no results
    Only after cleaning of Eeprom with the following scratch my sensor is starting work correctly
    I recommend to try it:
    Clearing EEPROM

    Igor



  • @mwhansen Hi, I am also struggling with this, seems it can only handle one connection now which makes it extremely hard to debug or check node ids


  • Code Contributor

    @Gambituk To connect to a external MQTT server (mosquitto) use this MQTT gateway version:
    http://forum.mysensors.org/topic/524/mqtt-client-gateway/



  • Thanks @celonunes I eventually found that version of gateway via somebody else. i have another post with some issues i found with that version. http://forum.mysensors.org/topic/921/strange-value-being-sent-from-controller-using-mixed-temp-relay-node it's not really resolved, but i have some kind of workaround.


  • Code Contributor

    @mwhansen @alexeinz The MQTT gateway can handle up to four simultaneous socket connections, this is the limit of Arduino ethernet shield (Wiznet W5100).

    The problem is that openhab don't get along with the way the gateway handles multiple client packages. I will send a fix for this problem in the next few days.



  • @celonunes actually, i figured a way around it using mosquitto bridge
    that way its much more robust too, so I am good 🙂
    can post my conf if anyone interested.


  • Code Contributor

    Those are the most recent changes to MQTT gateway:

    • Fixed node id distribution by the gateway (reported by @viking)
    • Fixed the problem with openhab and multiple MQTT clients
    • Fixed the appearance of garbage in messages sent from MQTT to a node


  • I can't change on-off manually for button with relay sketch, if i try, connection is lost, switching from screen never works again until restart everything.

    2015-03-05 15:51:29.200 [INFO ] [runtime.busevents ] - node2_sw2 received command OFF
    2015-03-05 15:51:32.624 [INFO ] [runtime.busevents ] - node2_sw2 received command ON

    Openhab 1.6.2 or 1.7.0 same result.

    **My main problem is losing connections with nodes. I also tried serial binding and same result.
    **
    Mysensors+Openhab useless with mqtt and also serial binding


  • Code Contributor

    @C.r.a.z.y. Could you send the serial output from the gateway? And a more complete log from openhab showing errors?


  • Admin

    @C.r.a.z.y. said:

    I can't change on-off manually for button with relay sketch, if i try, connection is lost, switching from screen never works again until restart everything.

    Are you sure it isn't a powering issue of the "button-node" where radio shuts down when you press the button? Are you controlling a physical relay?



  • @celonunes You can find MQTT and serial logs in the zip files openhab 1.6.2 and 1.7.0 logs-1.7.0.zip logs-1.6.2.zip

    @hek My nodes are working perfect when i only plug serial usb to any usb socket of a computer-printer-usb hub even a mobile phone charger 🙂 they are good without server/controller



  • @hek My relay powered from nano icp headers maybe this makes trouble for wifi , i will change this and give update.

    My button is not normal button , its an ir distance sensor which trigers the relay.



  • I can't seem to get openhab to communicate with my MQTT gateway. I can connect to the gateway with the MyMQTT Android app and I receive messages from my light sensor node including the sketch name and light level. I can ping my gateway without issue as well.

    However, OpenHab never seems like it notices the gateway. No data in the sketch name or node result. I've used the sitemap, items, and config files as described above and I've also customized them to match my sensor node more specifically. Both without success. The only change I've made is my sensor node is defined as node ID 20 within it's sketch.

    When using start_Debug.bat what should I see in the command line window to indicate OpenHab even sees or connects to the gateway. I see no indication that it attempts to connect to the IP address of my gateway.

    Thanks



  • Maybe if you can share your items, sitemap, and rules if any.





  • can you also please paste a sample of what you see in myMQTT or screenshot maybe? or it can be easier to copy and paste from a terminal window? are you using raspberry pi or something else?



  • @hooraysimpsons unplug the power and restart your modem, check your dhcp menu if it has ip for Ardiuno.

    Check your mqtt from serial monitor, you must see "gateway started..."



  • mosquitto_sub -h localhost -v -t '#'
    This is what i use to see what is happening on mqtt broker, i am using a raspberry pi and mosquitto installed on the same pi. you can also swap localhost for ip address ie 192.168.0.5 etc



  • @C.r.a.z.y. it sounds like he is getting as far as the mqtt broker, so the gateway must be working. ?



  • Crazy- I was thinking my network connection as a source of the problem. On my router homepage the gateway does not show up as being given an IP. However, the MyMQTT Android App sees the gateway without issue so the routing across my network from phone to gateway is successful. I have attached a screenshot of the MyMQTT andoird app output.

    2015-03-08 14.55.12.png

    I am trying to run OpenHab on a windows PC. I don't have mosquitto running at all. My understanding is that it is not required.



  • Group all
    Group node1 (all)
    Group node2 (all)
    Group sketch (all)

     Number node1_light  "Light Level"     (node1,all)  {mqtt="<[mysensor:MyMQTT/20/0/V_LIGHT_LEVEL:state:default]"}
    

    Try changing the first line of items like this above.. and in sitemap change node1_temp to node1_light

    Also see if activating any of the switches in openhab publishes to myMQTT ?



  • Restarting the modem and checking wires of arduino solved my problem before.
    I am sure mqtt have to be in dhcp list.



  • I have restarted my router with no effect. The gateway still does not show up as an active client (using DDWRT) but I still have a connection from phone to gateway.

    Added the above line. I've used one before like it but went back to what was given at the beggining of this thread to start anew. I also tried with the following edits
    "Light Level"
    "Light Level [%s]"
    "Light Level [%.1f]"

    None of which make a difference. The reason I think OpenHab doesn't even see the gateway is because nothing shows up in sketch name either which should work even if the above line was incorrect.

    I have done the testing with the Android App turned off as well since I know OpenHab had some issues earlier if other clients were accessing the gateway.

    I still see no reference to my gateway's IP in any of the OpenHab output/logs. So I'm not sure it is even trying.

    The only error message in my openhab log is:
    11:23:46.951 [ERROR] [sphere.cpr.AtmosphereFramework:2215 ] -

    I tried clearing the EEPROM in the gateway. I changed it's Mac address and removed the DHCP lease for it from my router. Still no evidence of the gateway on my router status page but also still able to connect to it with my phone.

    Another update:
    I installed Mosquitto and I see the light sensor level using mosquitto_sub -h 192.168.1.134 -t MyMQTT


  • Code Contributor

    @hooraysimpsons Your gateway seems to be working fine. Do you see something like this on your openhab logs?

    2015-02-27 17:48:06.349 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
    2015-02-27 17:48:06.350 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mysensor'
    


  • @celonunes Nope. I figured it out. In my openhab config file there was space prior to my MQTT related lines

    " mqtt:mysensor.url=tcp://192.168.1.134:1883"
    " mqtt:mysensor.clientId=OpenhabMQTT"
    Instead of
    "mqtt:mysensor.url=tcp://192.168.1.134:1883"
    "mqtt:mysensor.clientId=OpenhabMQTT"

    Removed the space and now I get my light sensor output value. I still don't get the sketch name coming through but I'll look into that later.



  • @celonunes @hek
    I installed this https://github.com/lurch/rpi-serial-console
    pi@raspberrypi ~ $ rpi-serial-console status
    Serial console on /dev/ttyAMA0 is disabled

    Now my nodes are working perfect when i use manual button or ui but my logs are not correct

    My config:

    add on : org.openhab.binding.serial_1.6.0.201411271703.jar
    String Arduino "Arduino" { serial="/dev/ttyUSB0" }

    As you see there are "fails" but nodes are working.

    015-03-09 12:37:51.725 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1

    2015-03-09 12:37:56.726 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 52-52-0 s=255,c=0,t=18,pt=0,l=5:1.4.1
    52;255;0;0;18;1.4.1
    0;0;3;0;9;read: 52-52-0 s=255,c=3,t=6,pt=1,l=1:0
    52;255;3;0;6;0

    2015-03-09 12:37:58.768 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 52-52-0 s=255,c=3,t=11,pt=0,l=14:Relay & Button
    52;255;3;0;11;Relay & Button
    0;0;3;0;9;read: 52-52-0 s=255,c=3,t=12,pt=0,l=3:1.0
    52;255;3;0;12;1.0
    0;0;3;0;9;read: 52-52-0 s=1,c=0,t=3,pt=0,l=5:1.4.1
    52;1;0;0;3;1.4.1
    0;0;3;0;9;read: 52-52-0 s=2,c=0,t=3,pt=0,l=5:1.4.1
    52;2;0;0;3;1.4.1

    2015-03-09 12:37:59.700 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-09 12:37:59.822 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-09 12:38:00.106 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:0

    2015-03-09 12:38:00.546 [INFO ] [runtime.busevents ] - S2 received command OFF
    2015-03-09 12:38:00.661 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1

    2015-03-09 12:38:00.967 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1

    2015-03-09 12:38:01.161 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-09 12:38:01.339 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-09 12:38:01.649 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:0

    2015-03-09 12:38:01.782 [INFO ] [runtime.busevents ] - S2 received command OFF
    2015-03-09 12:38:01.894 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1

    2015-03-09 12:38:02.076 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1



  • Just want to make sure I'm understanding this correctly since I feel the MQTT terminology is new to me.

    The MQTT Broker is the MQTT server so if I wanted to use this with openhab on a pi I would just need the MQTT plugin and then point it to the IP of the gateway?

    I have the ethernet module ordered so I can't test myself yet.


  • Code Contributor

    @C.r.a.z.y. You are using the raspberry serial port to connect the openhab with the arduino and the arduino is running the SerialGateway sketch, is that right?


  • Code Contributor

    @Chaotic said:

    The MQTT Broker is the MQTT server so if I wanted to use this with openhab on a pi I would just need the MQTT plugin and then point it to the IP of the gateway?

    That's right.



  • I have ENC28J60-I/SO connected by ethernetcable to my Asus RT-n66u in LAN 4. But It will not show up in my router... On my ENC28J60 there is a red light on D1 and the ethernet port has a green light and a yellow flashing light.

    Serial monitor says "
    Started!
    0;0;3;0;9;read: 20-20-0 s=255,c=0,t=17,pt=0,l=5:1.4.1
    0;0;3;0;9;read: 20-20-0 s=255,c=3,t=6,pt=1,l=1:0
    0;0;3;0;9;send: 0-0-20-20 s=255,c=3,t=6,pt=0,l=1,st=ok:M
    0;0;3;0;9;read: 20-20-0 s=255,c=3,t=11,pt=0,l=18:Temperature Sensor
    0;0;3;0;9;read: 20-20-0 s=255,c=3,t=12,pt=0,l=3:1.0

    . But nothing more. I have followed the MQTT gateway guide and set an static ip in the sketch.. DHCP is on in my router.

    The only thing I see in my router is : That the cable is connected to something and that its 10 Half duplex.

    I have also tried to connect it to other LAN ports but no difference

    What could be wrong?


  • Code Contributor

    @msebbe Did you try to ping the gateway static IP?



  • @celonunes

    Yes, both from windows cmd and from the router ui with this result:

    PING 192.168.1.197 (192.168.1.197): 56 data bytes

    --- 192.168.1.197 ping statistics ---
    5 packets transmitted, 0 packets received, 100% packet loss

    Could be that I have not changed the MAC adress cause I tried to figure out how to do it but I dont understand this part from the MQTT gateway sketch:

    *1 -> NOTE: Keep first byte at x2, x6, xA or xE (replace x with any hex value) for using Local Ranges.

     #define TCP_PORT 1883						// Set your MQTT Broker Listening port.
     IPAddress TCP_IP ( 192, 168, 1, 197 );				// Configure your static ip-address here
     uint8_t TCP_MAC[] = { 0x02, 0xDE, 0xAD, 0x00, 0x00, 0x42 };	// Mac-address - You should change this! see note *2 above!

Log in to reply
 

Suggested Topics

  • 2
  • 6
  • 2
  • 10
  • 17
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts