MQTT Broker gateway
-
Hi Folks,
New to mysensors and am impressed. I've been playing with OpenHAB and MQTT so this sounds like an interesting project. My question though, which might have been answered but I'm finding it hard to find the answer, is - is this bidirectional? As in if I had a 'sensor' on the Arduino network and that went over the radio network, hit the gateway and then got picked up by OpenHAB, could I then, if I had a 'actuator' or a 'do-er' node on the network, send a message to MQTT from OpenHAB to change the status of that actuator device? So for instance to start a motor controlling blinds for instance? Or is it a read only system?
Thanks
It works both ways.
-
Thanks :)
-
How can I implement MQTT for MQ-2 Gas sensor the correct way? In the mysensor sketch there is only one child ID and one V_VAR1 but 3 different outputs: LPG, CO and Smoke? I'm only receiving CO value and not all 3 in openhab.
@kunall There is V_VAR1-5 actually
V_VAR1 24 Custom value V_VAR2 25 Custom value V_VAR3 26 Custom value V_VAR4 27 Custom value V_VAR5 28 Custom valuePersonally I would set up each value you want as a S_CUSTOM if you can't figure out another sensor type that fits.
For smoke you can use S_SMOKE
For Air Quality S_AIR_QUALITY
Not sure what you'd want to use for CO2 through -
@kunall There is V_VAR1-5 actually
V_VAR1 24 Custom value V_VAR2 25 Custom value V_VAR3 26 Custom value V_VAR4 27 Custom value V_VAR5 28 Custom valuePersonally I would set up each value you want as a S_CUSTOM if you can't figure out another sensor type that fits.
For smoke you can use S_SMOKE
For Air Quality S_AIR_QUALITY
Not sure what you'd want to use for CO2 through -
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 addmqtt: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)@Damme
how to run MySensors ( MQTT gateway) on the arduino due + Wiznet5100 + NRf24l01?
Get the error:Arduino: 1.5.8 (Windows 8), Board: "Arduino Due (Programming Port)" In file included from Z:\arduino-1.5.8-new\libraries\DigitalIO/DigitalIO.h:31:0, from EthernetGateway.ino:41: Z:\arduino-1.5.8-new\libraries\DigitalIO/DigitalPin.h:30:20: fatal error: avr/io.h: No such file or directory #include <avr/io.h> ^ compilation terminated. Ошибка компиляции. This report would have more information with "Show verbose output during compilation" enabled in File > Preferences. -
-
@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.
@hooraysimpsons this solved my problem too! Everything else in my setup was a quick job but problem solving this issue took half a day. It should be more widely circulated..
-
Ok,forget my last post, I have a new problem:
When I uplaod the EthernetGW Sketch to my arduino nano I can see MQTT messages coming in from one node int the arduino serial monitor. So now I uploaded the MQTTGW sketch to my nano because I would like to use openhab. But after uploading the sketch all info I get from serial monitor is "Started!", nothing else is showing up.
I can still ping the MQTT gateway but it seems like it´s not receiving any mqtt message, at least no the state of my node. Could you please help and support me here? Thanks in advance! -
Hello,
I have made this gateway with W5100.
Everything looks OK, except random connection failures.
Clients - MyMQTT (android), Openhab are loosing contact with the broker time after time.
The issue can occur every 5 - 60 mins.Any ideas what could be the problem?
Thank you in advance.
-
Hi,
Was hoping someone could help a MQTT and openHab newb here. i have Openhab configured and running with Phillips Hue and Wemo, and trying to integrate MySensors. I build the 1.5 version MQTT gateway using the W5100 module, and all is working (can ping the gateway noproblem, and receiving data from a sensor). The problem is, i'm not sure how to add the line into the items and sitemap file....
Here is the output that I am getting from the MQTT serial monitor. The sensor I have connected is a 3-in-1 with motion PIR, and DHT22 temp/humid and a hard configured Node_ID of 3 (or, should be).
0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.3 0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0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t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.4 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0Can someone help me get the information to display in OpenHab? Please.
-
Contact contact_99 "Contact node 99 sensor 3: [MAP(de.map):%s]" { mqtt="<[mysensors:sensor-gw1-out/99/3/1/0/16:state:MAP(mqttToCloseOpen.map)]" }this is an item which
reads a message from mqtt broker:- < input, reads message
- mysensors => mqtt connection as decribes in opnehab.cfg
- sensor-gw1-out => topics as configured in your mqtt gateway sketch
- 99/3/1/0/16 have a look at serial api: node 99, child 3 etc
I found it very helpful to subscribe myself to the mqtt broker and read the incoming messages there
-
Hi @dakky
Thanks for the help. So far, I can get my temperature and humidity to update, but I cannot get my motion sensor on the same node to update at all.
Here are the lines I have in default.items
/* MySensors MQTT */ Number node1_temp "Temp [%.1f °C]" (node1) {mqtt="<[mysensor:MyMQTT/1/1/V_TEMP:state:default]"} Number node1_humid "Humid [%.1f %%Rh]" (node1) {mqtt="<[mysensor:MyMQTT/1/0/V_HUM:state:default]"} Contact node1_motion "Motion Sensor 3: [MAP(1on0off.map):%s]" (node1) { mqtt="<[mysensors:MyMQTT/1/2/V_TRIPPED:state:MAP(1on0off.map)]" }And here is my default.sitemap file
Frame label="Sensor Data" { Text label="Sensors" icon="mysensors" { Group item=node1 label="Man Cave Climate" icon="temperature" Chart item=node1_humid period=W refresh=10000 }And finally, this is what I am reading from screen when the message appear on the MQTT broker sketch. The node_id is 1, not 3 like I originally though.
>>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30 0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:47.1 MyMQTT/1/0/V_HUM >>30 16 00 10 4D 79 4D 51 54 54 2F 31 2F 30 2F 56 5F 48 55 4D 34 37 2E 31 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 MyMQTT/1/2/V_TRIPPED >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 MyMQTT/1/2/V_TRIPPED >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30 0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:21.8 MyMQTT/1/1/V_TEMP >>30 17 00 11 4D 79 4D 51 54 54 2F 31 2F 31 2F 56 5F 54 45 4D 50 32 31 2E 38 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 MyMQTT/1/2/V_TRIPPED >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30 0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0 MyMQTT/1/2/V_TRIPPED >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30Any ideas on what I am missing? Also, when trying to implement persistence, I went with MySQL as per directions here but the data doesn't actually go into the chart. Other than adding mysql to the openhab.cfg file, what else is there? The log isn't showing any errors from what I can see.
Thanks!
-
Typing from tablet => short Version
Contact items needs Open or Closed not On vor Off. Make a new map translating 0 to closed etc and it should work. or use the correct item: switch seems a better choice
https://github.com/openhab/openhab/wiki/Explanation-of-items#itemtype -
Hi @dakky
well, some luck. I made a new map contact.map with
0=Closed
1=Open
-=unknownso far the swtich now shows "Unknown" all the time; but no status updates from the sensor (even though it is showing in serial console as 1, and 0 when it is off).
Not sure why it isn't updating like it should now. Might have to reboot the server.
-
Ok, got it. Had to do the following to my items and sitemap to get a PIR to work right:
entry in default.items
Switchnode6_motion "LR Motion Test [MAP(motion.map):%s]" (FF_Living,All) {mqtt=">[mysensor:MyMQTT/6/1/V_TRIPPED:command:ON:1],>[mysensor:MyMQTT/6/1/V_TRIPPED:command:OFF:0],<[mysensor:MyMQTT/6/1/V_TRIPPED:command:MAP(motion.map)]"}and default.sitemap
Text item=node6_motion label="PIR Test LR [%s]" icon="pir"And last, the transform file (named motion.map)
1=ON 0=OFFAt least now it registers the data in text as On or Off. Thanks again @dakky
-
Is there a way to redirect all the messages from the serial console of the wifi gateway to some tcp port so they can be read via putty?
-
Hello, sorry to reopen this post, but maybe someone can help me! I'm still waiting the arrival of my arduinos to make my nodes and gateways, but I already installed openhab to start configuring the layout and MQTT. All is working, I can post to MTQQ from openhab and used the tutorial on this post to make the same button send and recieve.
The problem is that when I click the button with the code "sw2 send + recieve example" openhab enters in loop mode, it seems that keeps sending and reviving the same MTQQ request. I use MQTT.fx to test the MTQQ posts, and when I click the button, the program also crashes and takes my CPU to max.
Can any one help me?
Best Regards
Soloam -
Hello, the problem persists, the map function keeps sending the same request over and over again, If I make a click in a few seconds my mqtt client is full of requests, over 500 with the same message. Wasn't it supposed to send only one message for click?