My final setup to get MySensors and OpenHab communicating via MQTT
-
Eric,
Thanks for posting. It looks exactly what I need to follow.Can you describe how the hardware(Ethernet Shield and nRF24L01, SPI pins) are connected?
Also where to look for them in the header file?Follow this guide Ethernet Gateway
-
Hi,
Thanks for the help.I keep getting these messages on the COM port for the MQTT Gateway. What does it mean and what should I do to proceed? Thx.
0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.0.1-beta
0;255;3;0;9;TSM:INIT
0;255;3;0;9;!TSM:INIT:TSP FAIL
0;255;3;0;9;TSM:FAILURE
0;255;3;0;9;TSM:FAILURE:PDT
0;255;3;0;9;TSM:FAILURE:RE-INIT
0;255;3;0;9;TSM:INIT
0;255;3;0;9;!TSM:INIT:TSP FAIL
0;255;3;0;9;TSM:FAILURE
0;255;3;0;9;TSM:FAILURE:PDT
0;255;3;0;9;TSM:FAILURE:RE-INIT -
Update on this. It seems to be working after I found I did not modify the MyConfig.h being used.
After uncommenting #define MY_SOFTSPI
I got below.0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.0.1-beta
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY
IP: 192.168.1.108
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,ID=0,PAR=0,DIS=0,REG=1
IP: 192.168.1.108
0;255;3;0;9;Attempting MQTT connection...
0;255;3;0;9;MQTT connected
0;255;3;0;9;Sending message on topic: mygateway1-out/0/255/0/0/18
0;255;3;0;9;TSF:SANCHK:OK
IP: 192.168.1.108
0;255;3;0;9;Attempting MQTT connection...
0;255;3;0;9;MQTT connected
0;255;3;0;9;Sending message on topic: mygateway1-out/0/255/0/0/18 -
Update on this. It seems to be working after I found I did not modify the MyConfig.h being used.
After uncommenting #define MY_SOFTSPI
I got below.0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.0.1-beta
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSM:INIT:TSP OK
0;255;3;0;9;TSM:INIT:GW MODE
0;255;3;0;9;TSM:READY
IP: 192.168.1.108
0;255;3;0;9;MCO:REG:NOT NEEDED
0;255;3;0;9;MCO:BGN:STP
0;255;3;0;9;MCO:BGN:INIT OK,ID=0,PAR=0,DIS=0,REG=1
IP: 192.168.1.108
0;255;3;0;9;Attempting MQTT connection...
0;255;3;0;9;MQTT connected
0;255;3;0;9;Sending message on topic: mygateway1-out/0/255/0/0/18
0;255;3;0;9;TSF:SANCHK:OK
IP: 192.168.1.108
0;255;3;0;9;Attempting MQTT connection...
0;255;3;0;9;MQTT connected
0;255;3;0;9;Sending message on topic: mygateway1-out/0/255/0/0/18@zuolan Good that you found the problem. Don't forget to comment out define MY_SOFTSPI again
-
@zuolan Good that you found the problem. Don't forget to comment out define MY_SOFTSPI again
@Martin-Tellblom Something is still not right. I looked at the MQTT messages using
mosquito_sub -v -t 'mygateway1-out/#'
I got below:
mygateway1-out/0/255/0/0/18 2.0.1-beta
...
mygateway1-out/255/255/3/0/3 (null)
...
It seems the (null)is where the message body should have been. So the payload is missing.The sensor node is the 'LightSensor' sketch taking an analog data
// Enable debug prints to serial monitor
#define MY_DEBUG// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69#include <SPI.h>
#include <MySensors.h>#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 0unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
int lastLightLevel;void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Light Sensor", "1.0",true);// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
}void loop()
{
int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;Serial.println(lightLevel);
if (lightLevel != lastLightLevel) {
send(msg.set(lightLevel));
lastLightLevel = lightLevel;
}
sleep(SLEEP_TIME);
}Why the sensor node is not returning the voltage reading?
What am I doing wrong?Thanks,
-
@Martin-Tellblom Something is still not right. I looked at the MQTT messages using
mosquito_sub -v -t 'mygateway1-out/#'
I got below:
mygateway1-out/0/255/0/0/18 2.0.1-beta
...
mygateway1-out/255/255/3/0/3 (null)
...
It seems the (null)is where the message body should have been. So the payload is missing.The sensor node is the 'LightSensor' sketch taking an analog data
// Enable debug prints to serial monitor
#define MY_DEBUG// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69#include <SPI.h>
#include <MySensors.h>#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 0unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
int lastLightLevel;void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Light Sensor", "1.0",true);// Register all sensors to gateway (they will be created as child devices)
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
}void loop()
{
int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;Serial.println(lightLevel);
if (lightLevel != lastLightLevel) {
send(msg.set(lightLevel));
lastLightLevel = lightLevel;
}
sleep(SLEEP_TIME);
}Why the sensor node is not returning the voltage reading?
What am I doing wrong?Thanks,
@zuolan
Hi , mygateway1-out is used when sending commands to MySensors devices. In my setup I have renamed it like this:// Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "MySensors" //Changed from "MySensors-in" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "MySensors-out"You should subscribe to the topic that the Gateway is Publishing (i.e MySensors-in)
-
@zuolan
Hi , mygateway1-out is used when sending commands to MySensors devices. In my setup I have renamed it like this:// Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "MySensors" //Changed from "MySensors-in" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "MySensors-out"You should subscribe to the topic that the Gateway is Publishing (i.e MySensors-in)
@Martin-Tellblom
OK. I will. Can you post an example of messages you are getting so I have a rough idea?Many thanks.
-
@Martin-Tellblom
OK. I will. Can you post an example of messages you are getting so I have a rough idea?Many thanks.
@zuolan
This is how my Light sensor present itself and submitting data:MySensors/100/255/0/0/17 2.0.0 MySensors/100/255/3/0/6 0 MySensors/100/255/3/0/6 Light Sensor MySensors/100/255/3/0/12 1.0 MySensors/100/100/0/0/16 null MySensors/100/100/1/0/23 7 <--This is the actual light valueSo in my case to monitor the light value in openhab I use this address: MySensors/100/100/1/0/23
-
@zuolan
This is how my Light sensor present itself and submitting data:MySensors/100/255/0/0/17 2.0.0 MySensors/100/255/3/0/6 0 MySensors/100/255/3/0/6 Light Sensor MySensors/100/255/3/0/12 1.0 MySensors/100/100/0/0/16 null MySensors/100/100/1/0/23 7 <--This is the actual light valueSo in my case to monitor the light value in openhab I use this address: MySensors/100/100/1/0/23
@Martin-Tellblom
OK. I am not getting any from 'mygateway1-in/#'. Let me check.Just to be clear, in the above sketch
sendSketchInfo("Light Sensor", "1.0",true);
send(msg.set(lightLevel));
should have caused messages in 'mygateway1-in/#'?
Thanks,
-
@Martin-Tellblom
OK. I am not getting any from 'mygateway1-in/#'. Let me check.Just to be clear, in the above sketch
sendSketchInfo("Light Sensor", "1.0",true);
send(msg.set(lightLevel));
should have caused messages in 'mygateway1-in/#'?
Thanks,
@zuolan
Hi.That's correct, whats shown is the presentation and the last row the LightValue, MySensors/100/100/1/0/23
First of all I don't think there is any problem at all in your sensor sketch, the only thing I have changed in my is that I have changed is that I added this row:
#define MY_NODE_ID 100What I think the problem is that you are subscribing the wrong topic:
As I mentioned before my MQTT settings are:
// Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "MySensors" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "MySensors-out"Observerve that the MQTT topics is case sensative ie MySensors is NOT the same as mysensors.
I use MQTT-SPY (java based listener) to look at the messages and here you can look at every message sent when subscribing to # (And there is a BIG differense if you publish to MySensors or /MySensors). I suggest that you use MQTT-SPY and subscribe to both /# and # and that should catch all messages that comes to your broker (exept system messages)
Here you can se the differense between using the correct upper and lowercase and not. The first picture subribes to MySensors/#

And this one subscribes to mysensors/#

-
@zuolan
Hi.That's correct, whats shown is the presentation and the last row the LightValue, MySensors/100/100/1/0/23
First of all I don't think there is any problem at all in your sensor sketch, the only thing I have changed in my is that I have changed is that I added this row:
#define MY_NODE_ID 100What I think the problem is that you are subscribing the wrong topic:
As I mentioned before my MQTT settings are:
// Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "MySensors" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "MySensors-out"Observerve that the MQTT topics is case sensative ie MySensors is NOT the same as mysensors.
I use MQTT-SPY (java based listener) to look at the messages and here you can look at every message sent when subscribing to # (And there is a BIG differense if you publish to MySensors or /MySensors). I suggest that you use MQTT-SPY and subscribe to both /# and # and that should catch all messages that comes to your broker (exept system messages)
Here you can se the differense between using the correct upper and lowercase and not. The first picture subribes to MySensors/#

And this one subscribes to mysensors/#

@Martin-Tellblom
Thanks again.I installed mqttspy and changed #define MY_NODE_ID 100.
I subscribe to the following topics:
mygateway1-in
/#I'm still not getting any messages in mygateway1-in.
Especially not this one: "MySensors/100/255/3/0/6 Light Sensor" that you are getting.
All the messages I can see still in mygateway1-out/255/255/3/0/3 topic.
So I think data from my Light Sensor node is not getting through.Your thoughts? And how to debug this?
On the COM port of the Light Sensor I got below. Do you see any indication showing it is sending data to mqtt? What about the !TSM:FALILURE?
!TSM:CHKID:FAIL (ID=255)
!TSM:FAILURE
TSM:PDT
TSM:INIT
TSM:RADIO:OK
TSM:FPAR
TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSP:MSG:READ 0-0-255 s=255,c=3,t=8,pt=1,l=1,sg=0:0
TSP:MSG:FPAR RES (ID=0, dist=0)
TSP:MSG:PAR OK (ID=0, dist=1)
TSM:FPAR:OK
TSM:ID
TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
TSM:ID
TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
TSM:ID
TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
TSM:ID
TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
!TSM:CHKID:FAIL (ID=255)
!TSM:FAILURE
TSM:PDT
TSM:INIT
TSM:RADIO:OK
TSM:FPAR -
@zuolan
Hi.That's correct, whats shown is the presentation and the last row the LightValue, MySensors/100/100/1/0/23
First of all I don't think there is any problem at all in your sensor sketch, the only thing I have changed in my is that I have changed is that I added this row:
#define MY_NODE_ID 100What I think the problem is that you are subscribing the wrong topic:
As I mentioned before my MQTT settings are:
// Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "MySensors" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "MySensors-out"Observerve that the MQTT topics is case sensative ie MySensors is NOT the same as mysensors.
I use MQTT-SPY (java based listener) to look at the messages and here you can look at every message sent when subscribing to # (And there is a BIG differense if you publish to MySensors or /MySensors). I suggest that you use MQTT-SPY and subscribe to both /# and # and that should catch all messages that comes to your broker (exept system messages)
Here you can se the differense between using the correct upper and lowercase and not. The first picture subribes to MySensors/#

And this one subscribes to mysensors/#

I actually have the problem below solved. Since I already finished writing, so I am leaving this here for other people.
More information on this.
Although the Light Sensor data is not getting through, the Light Sensor node does cause all these MQTT messages to be sent.
Before I turn on the Light Sensor node, there is no MQTT message on the mqttspy and on the GatewayW5100MQTTClient COM port it is very quiet and I got this:
After I turn on the Light Sensor node the MQTT messages started comming and on the GatewayW5100MQTTClient COM port:
0;255;3;0;9;Starting gateway (RNNGA-, 2.0.0)
0;255;3;0;9;TSM:INIT
0;255;3;0;9;TSM:RADIO:OK
0;255;3;0;9;TSM:GW MODE
0;255;3;0;9;TSM:READY
IP: 192.168.1.108
0;255;3;0;9;No registration required
0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
IP: 192.168.1.108
0;255;3;0;9;Attempting MQTT connection...
0;255;3;0;9;MQTT connected
0;255;3;0;9;TSP:SANCHK:OK
0;255;3;0;9;TSP:SANCHK:OK
0;255;3;0;9;TSP:SANCHK:OK
0;255;3;0;9;TSP:SANCHK:OK<<Light Sensor Turned on>>
0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
0;255;3;0;9;TSP:MSG:BC
0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
0;255;3;0;9;TSP:CHKUPL:OK
0;255;3;0;9;TSP:MSG:GWL OK
0;255;3;0;9;TSP:MSG:SEND 0-0-255-255 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=bc:0
0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
0;255;3;0;9;TSP:MSG:BC
0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
0;255;3;0;9;TSP:MSG:GWL OK
0;255;3;0;9;TSP:MSG:SEND 0-0-255-255 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=bc:0
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
0;255;3;0;9;TSP:MSG:BC
0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
0;255;3;0;9;TSP:CHKUPL:OK
0;255;3;0;9;TSP:MSG:GWL OK
0;255;3;0;9;TSP:MSG:SEND 0-0-255-255 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=bc:0
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
.......So question is why the messages from Light Sensor do not get through (or I am still not capturing them) while causing messages being sent on mygateway1-out/255/255/3/0/3?
See next post.
-
@zuolan
Hi.That's correct, whats shown is the presentation and the last row the LightValue, MySensors/100/100/1/0/23
First of all I don't think there is any problem at all in your sensor sketch, the only thing I have changed in my is that I have changed is that I added this row:
#define MY_NODE_ID 100What I think the problem is that you are subscribing the wrong topic:
As I mentioned before my MQTT settings are:
// Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "MySensors" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "MySensors-out"Observerve that the MQTT topics is case sensative ie MySensors is NOT the same as mysensors.
I use MQTT-SPY (java based listener) to look at the messages and here you can look at every message sent when subscribing to # (And there is a BIG differense if you publish to MySensors or /MySensors). I suggest that you use MQTT-SPY and subscribe to both /# and # and that should catch all messages that comes to your broker (exept system messages)
Here you can se the differense between using the correct upper and lowercase and not. The first picture subribes to MySensors/#

And this one subscribes to mysensors/#

@Martin-Tellblom
Your advice of changing the MY_NODE_ID made the difference. I foolishly left it in the MyConfig.h file so it is conflicting with the gateway.
So on mqttspy I now get this!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thanks so much for helping me.
-
On the topic of editing header files, I found (maybe this is obvious for other people) many including the #define MY_SOFTSPI should be done in the sketch (before the corresponding header file is included?). In this way you don't have to worry about changing it back or conflict.
-
Thats good that you found the problem.
-
Thanks.
I now try to get MQTT to talk to openhab by following the RelayActuator example. I only have the openhab demo running.
I am not sure I have enough information in the above instruction to comple the mqtt.items file. For the following MQTT topics setup of mine,
I will try the following for the first line:
String Garage_Door "Garage Door [%s]" (gGarage, Windows) {mqtt="<[broker:mygateway1-out/102/1/1/0/2:state:MAP(1closed0open.map)]"}For the second line I am really stuck about how the do the "/2/2/0/0/2/"part:
Switch MQTTTestSwitch "MQTT Test Switch" (gBasement) {mqtt=">[broker:mygateway1-in/2/2/0/0/2:command:ON:1],>[broker:mygateway1-in/2/2/0/0/2:command:OFF:0]"}How should one figure out?
OK. To answer my own question the information is clearly here:
https://www.mysensors.org/download/serial_api_20#sensor-typesI will be reading up.
-
@Meshx86 said:
s distribution, i can't get openhab to distribute Address to the nodes when connecting, the MQTT Gateway sketch of my sensors doesn't do that right ?
Any tips that would be great
Set a static node id using
#define MY_NODE_ID 2020 in this case is the node id.