MQTT ESP8266 DHT11 invalid data received (SOLVED)

Moderator: leecollings

Post Reply
HvdW
Posts: 663
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

MQTT ESP8266 DHT11 invalid data received (SOLVED)

Post by HvdW »

Hi,

I found a nice description of publishing temperature and humidity to Domoticz using MQTT on The Free Physicist and later on an even nicer one from Paulus Schoutsen on Github to set up MQTT temp/hum readings.

In the script I added this line for testing purposes.

Code: Select all

client.publish( "domoticz/in", "{'idx' : 56, 'nvalue' : 0, 'svalue' : '22;66;3' }");
This resulted in an error code inside Domoticz

Code: Select all

 MQTT: Topic: domoticz/in, Message: {'idx' : 56, 'nvalue' : 0, 'svalue' : '22;66;3' }
Error: MQTT: Invalid data received! 
So I tried

Code: Select all

client.publish( 'domoticz/in', '{"idx" : 57, "nvalue" : 0, "svalue" : "22;66;2" }');
which is not accepted by the Arduino compiler as a correct code.

The problem is that Arduino doesn't accept single quotation marks and Domoticz doesn't accept single quotation marks.
Mixing single and double quotation marks in one line offers a solution for most compilers, but not in this case.

Can you give me an alternative on how to publish to Domoticz in a way that is accepted by both parties?
Last edited by HvdW on Wednesday 01 May 2019 23:54, edited 2 times in total.
Bugs bug me.
HvdW
Posts: 663
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: MQTT ESP8266 DHT11 invalid data received

Post by HvdW »

Hi,
I did another step and used Escape character to force a double quote using \"
Found it on StackExchange
This was my publish line

Code: Select all

client.publish( "domoticz/in", "{\" idx \" : 56, \" nvalue \" : 0,  \" svalue \" : \" 22;66;3 \" }");
Here is the result in the Domoticz logs

Code: Select all

 
2019-05-01 23:20:02.086 MQTT: Topic: domoticz/in, Message: {"idx" : 57, " nvalue " : 0, " svalue " : " 22;66;3 " }
2019-05-01 23:20:02.087 Error: MQTT: Invalid data received!
Failure!
Then I changed spacing around idx, nvalue and svalue

Code: Select all

client.publish( "domoticz/in", "{\"idx\" : 56, \"nvalue\" : 0,  \"svalue\" : \"22;66;3\" }");
Result: SUCCESS!

Code: Select all

2019-05-01 23:27:29.723 MQTT: Topic: domoticz/in, Message: {"idx" : 57, "nvalue" : 0, "svalue" : "22;66;3" } 
Bugs bug me.
Doudy
Posts: 246
Joined: Tuesday 09 August 2016 9:09
Target OS: -
Domoticz version:
Contact:

Re: MQTT ESP8266 DHT11 invalid data received (SOLVED)

Post by Doudy »

Thank you for the code
That save me ;)
RaspberryPi - RFLink - Zwave - WH2600
Domoticz : 2020.2 | Dashticz : V3.12 Master | dzvents : 3.0.2 | Python : 3.7.3
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest