Page 1 of 1

MQTT ESP8266 DHT11 invalid data received (SOLVED)

Posted: Tuesday 30 April 2019 23:26
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?

Re: MQTT ESP8266 DHT11 invalid data received

Posted: Wednesday 01 May 2019 23:35
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" } 

Re: MQTT ESP8266 DHT11 invalid data received (SOLVED)

Posted: Thursday 01 December 2022 18:59
by Doudy
Thank you for the code
That save me ;)