Hi guys,
I am brand new to this stuff, so bear with me. I recently pruchased an Arduino Uno, along with a DHT22 temp+hum sensor and some RF24 radios.
They send the data to a Raspberry Pi (based on a Raspian Image file) with Domoticz. I have been following the instructions from http://homeautomationforgeeks.com/project/
I have manged to both send and receive the data, and the Raspberry Pi "Hareceiver" tells me :
Temperature received from node 1: 22.500000
Client mosqpub/617-raspberrypi sending CONNECT
Client mosqpub/617-raspberrypi received CONNACK
Client mosqpub/617-raspberrypi sending PUBLISH (d0, q0, r0, m1, 'home/temperature', ... (9 bytes))
Client mosqpub/617-raspberrypi sending DISCONNECT
On the Domoticz server I tried setting up a "MQTT Client Gateway with LAN interface" device, with IP set to the same as my Raspberry Pi, and port set to 1883 (not certain that this is the correct port). The Domoticz log windows says:
2016-07-08 09:54:37.381 MQTT: Connecting to 192.168.1.248:1883
2016-07-08 09:54:37.485 MQTT: connected to: 192.168.1.248:1883
2016-07-08 09:54:37.586 MQTT: Subscribed
As far as I can tell it seems that Domoticz is subscribing to the MQTT stream. However, how do I proceed from here? How do I add the temp-hum device on the server? What is missing? Do I need to add the node ID, if so.. how?
MQTT + Domoticz
Moderator: leecollings
-
- Posts: 71
- Joined: Saturday 13 July 2013 2:45
- Target OS: Linux
- Domoticz version: 3.5877
- Location: Scotland
- Contact:
Re: MQTT + Domoticz
Well to start with, Domoticz only responds to messages received on the topic domoticz/in
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
-
- Posts: 3
- Joined: Friday 08 July 2016 9:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: MQTT + Domoticz
Yes, thank you. After fiddeling around I manged to make it publish the data to the "domoticz/in" topic.asjmcguire wrote:Well to start with, Domoticz only responds to messages received on the topic domoticz/in
When I subcribe to the MQTT domoticz/in topic with SSH in Raspberry Pi, I see:
- Temperature received from node 1: 23.000000
Client mosqpub/1263-raspberryp sending CONNECT
Client mosqpub/1263-raspberryp received CONNACK
Client mosqpub/1263-raspberryp sending PUBLISH (d0, q0, r0, m1, 'domoticz/in', ... (9 bytes))
Client mosqpub/1263-raspberryp sending DISCONNECT
I can publish a simple message ("mosquitto_pub -d -t 'domoticz/in' -m .... ") on the domoticz/in topic, and it will read it. So the communication is there. But why can't Domoticz handle the data from the sensor?
Maybe there is something wrong the the coding of the hareceiver.cpp file publishing the sensor data to the MQTT broker. Please have a look at it, it is attached.
- Attachments
-
- hareceiver.cpp
- The file publishing sensor data to the MQTT broker
- (2.26 KiB) Downloaded 142 times
-
- Posts: 71
- Joined: Saturday 13 July 2013 2:45
- Target OS: Linux
- Domoticz version: 3.5877
- Location: Scotland
- Contact:
Re: MQTT + Domoticz
I'm not a c++ person, but I do know that Domoticz expects JSON encoded data to be published to the MQTT channel, and the file you provided is just publishing a bit of plain textmongoman wrote:Yes, thank you. After fiddeling around I manged to make it publish the data to the "domoticz/in" topic.asjmcguire wrote:Well to start with, Domoticz only responds to messages received on the topic domoticz/in
When I subcribe to the MQTT domoticz/in topic with SSH in Raspberry Pi, I see:However, Domoticz crash whenever it receives this data. I have to restart the Raspberry Pi and delete the Chrome cache to make it work again.
- Temperature received from node 1: 23.000000
Client mosqpub/1263-raspberryp sending CONNECT
Client mosqpub/1263-raspberryp received CONNACK
Client mosqpub/1263-raspberryp sending PUBLISH (d0, q0, r0, m1, 'domoticz/in', ... (9 bytes))
Client mosqpub/1263-raspberryp sending DISCONNECT
I can publish a simple message ("mosquitto_pub -d -t 'domoticz/in' -m .... ") on the domoticz/in topic, and it will read it. So the communication is there. But why can't Domoticz handle the data from the sensor?
Maybe there is something wrong the the coding of the hareceiver.cpp file publishing the sensor data to the MQTT broker. Please have a look at it, it is attached.
Domoticz expects messages more like:sprintf (buffer, "mosquitto_pub -d -t domoticz/in -m \"%f\"", message.temperature);
These are actual live MQTT messages flying across my network right this second on the domoticz/in topic:{"command":"udevice","idx":431,"nvalue":0,"svalue":"17.9"}
EDIT:{"command":"udevice","idx":431,"nvalue":0,"svalue":"17.9"}
{"command":"udevice","idx":432,"nvalue":0,"svalue":"18.9"}
{"command":"udevice","idx":429,"nvalue":0,"svalue":"17.3"}
{"command":"udevice","idx":428,"nvalue":0,"svalue":"18.3"}
{"command":"udevice","idx":437,"nvalue":0,"svalue":"16.1"}
{"command":"udevice","idx":435,"nvalue":0,"svalue":"18.1"}
{"command":"udevice","idx":433,"nvalue":0,"svalue":"17.8;60.4;0"}
{"command":"udevice","idx":434,"nvalue":0,"svalue":"18.1;64.7;0"}
{"command":"udevice","idx":430,"nvalue":0,"svalue":"16.1;60.6;0"}
{"command":"udevice","idx":440,"nvalue":0,"svalue":"18.8;58.6;0"}
{"command":"udevice","idx":439,"nvalue":0,"svalue":"16.8"}
{"command":"udevice","idx":438,"nvalue":0,"svalue":"16.6"}
{"command":"udevice","idx":657,"svalue":"20325","nvalue":0}
{"command":"udevice","idx":658,"svalue":"3.3","nvalue":0}
Here is the Domoticz log:
Usually - if data has been provided and there is an idx that Domoticz can't find - it will start producing errors which let you know that the idx must be wrong (though that is a bit of a pain when you have more than one domoticz system running).2016-07-14 00:25:15.327 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":431,"nvalue":0,"svalue":"17.8"}
2016-07-14 00:25:15.429 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":432,"nvalue":0,"svalue":"18.9"}
2016-07-14 00:25:15.531 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":429,"nvalue":0,"svalue":"17.3"}
2016-07-14 00:25:15.634 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":428,"nvalue":0,"svalue":"18.3"}
2016-07-14 00:25:15.736 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":437,"nvalue":0,"svalue":"16.1"}
2016-07-14 00:25:15.838 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":435,"nvalue":0,"svalue":"18.1"}
2016-07-14 00:25:15.941 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":433,"nvalue":0,"svalue":"17.7;60.4;0"}
2016-07-14 00:25:16.049 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":434,"nvalue":0,"svalue":"18;64.7;0"}
2016-07-14 00:25:16.151 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":430,"nvalue":0,"svalue":"16.1;60.6;0"}
2016-07-14 00:25:16.254 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":440,"nvalue":0,"svalue":"18.8;58.6;0"}
2016-07-14 00:25:16.356 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":439,"nvalue":0,"svalue":"16.8"}
2016-07-14 00:25:16.459 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":438,"nvalue":0,"svalue":"16.5"}
2016-07-14 00:25:16.566 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":657,"svalue":"20325","nvalue":0}
2016-07-14 00:25:16.669 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":658,"svalue":"3.4","nvalue":0}
2016-07-14 00:25:16.771 MQTT: Topic: domoticz/in, Message: {"idx":672,"svalue":"0;0","nvalue":0}
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
-
- Posts: 3
- Joined: Friday 08 July 2016 9:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: MQTT + Domoticz
Thank you very much, asjmcguire! This is indeed helpful.I'm not a c++ person, but I do know that Domoticz expects JSON encoded data to be published to the MQTT channel, and the file you provided is just publishing a bit of plain text
I created a "Dummy hardware" with a virtual temp+hum sensor, with IDX #2. Used the command you suggested, but swapped the IDX number.
{"command":"udevice","idx":431,"nvalue":0,"svalue":"17.9"}
Worked like a charm! Thanks a lot

Now the next step is to setup the hareceiver.cpp file to send the received temp+hum data from the actual DHT22 sensor.
How do I implement this? I have tried experimenting, but being a noobie I can't get the syntex right.
I guess I have to manipulate the line
into something likesprintf (buffer, "mosquitto_pub -d -t home/temperature -m \"%f\"", message.temperature);
How do I get it right? Please see attached hareceiver.cpp file.sprintf (buffer, "mosquitto_pub -d -t 'domoticz/in' -m '{"command":"udevice","idx":2,"nvalue":0,"svalue":\"%f\""}', message.temperature);
- Attachments
-
- hareceiver.cpp
- hareceiver.cpp
- (2.26 KiB) Downloaded 148 times
-
- Posts: 1
- Joined: Friday 23 September 2016 17:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: MQTT + Arduino + Domoticz
Hello,
I try to publish the following from my Arduino Uno to a MQTT server:
client.publish("domoticz/in",{"command":"udevice","idx":7,"nvalue":0,"svalue":"17.9"})
but Arduino did not accept this.
I get the following error: mqtt_try:31: error: expected '}' before ':' token
I changed it in the following :
client.publish("domoticz/in","{'command':'udevice','idx':7,'nvalue':0,'svalue':'17.9'}");
This is accepted by Arduino en send tot Domoticz, but in the Domoticz log i can see that there is an error.
2016-10-18 16:01:47.164 MQTT: Topic: domoticz/in, Message: {'command':'udevice','idx':7,'nvalue':0,'svalue':'17.9'}
2016-10-18 16:01:47.165 Error: MQTT: Invalid data received!
Anyone who can tell me how to send this message to Arduino?
I try to publish the following from my Arduino Uno to a MQTT server:
client.publish("domoticz/in",{"command":"udevice","idx":7,"nvalue":0,"svalue":"17.9"})
but Arduino did not accept this.
I get the following error: mqtt_try:31: error: expected '}' before ':' token
I changed it in the following :
client.publish("domoticz/in","{'command':'udevice','idx':7,'nvalue':0,'svalue':'17.9'}");
This is accepted by Arduino en send tot Domoticz, but in the Domoticz log i can see that there is an error.
2016-10-18 16:01:47.164 MQTT: Topic: domoticz/in, Message: {'command':'udevice','idx':7,'nvalue':0,'svalue':'17.9'}
2016-10-18 16:01:47.165 Error: MQTT: Invalid data received!
Anyone who can tell me how to send this message to Arduino?
-
- Posts: 331
- Joined: Wednesday 21 December 2016 9:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: current
- Contact:
Re: MQTT + Domoticz
For anyone finding this: the Beta of Domotics supports normal MQTT messages. If you want to use MQTT, use the Domoticz Beta.
-
- Posts: 87
- Joined: Wednesday 21 December 2016 19:03
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Israel
- Contact:
Re: MQTT + Domoticz
Can you elaborate where I can find more info how to subscribe to other topics rather then domoticz/in? And how to parse?blauwebuis wrote:For anyone finding this: the Beta of Domotics supports normal MQTT messages. If you want to use MQTT, use the Domoticz Beta.
Sent from my SM-G950F using Tapatalk
Who is online
Users browsing this forum: No registered users and 1 guest