The use of the ESP8266 in the world of IoT

User avatar
By dacb
#19372
Artem Pastukhov wrote:I will post full script tomorow if you wish.


Hi Artem, That's great, although it is the DS18B20 library that I haven't ever been able to get to work alongside MQTT. Maybe in another thread you could post that. This thread is about using Node-red w/ frankenstein directly.
User avatar
By Mikejstb
#19418 I hope this is not too off topic, but can you explain about the cjson structure that you're passing as the mqtt payload?
In pretty ignorant about json, and my only mqtt payload experience is sending simple strings.
Is it right to say that the cjson is a structure?
Is the end result a nicely organized payload with a lot of labeled (maybe "labeled" is the wrong word) diverse data, all in one mqtt message?
What does it actually look like when the mqtt broker receives it?
Like if you were to use something like mqttspy to watch your topic.
Always trying to learn new techniques and tricks!
Thanks
User avatar
By Artem Pastukhov
#19429
dacb wrote:
Artem Pastukhov wrote:I will post full script tomorrow if you wish.


Hi Artem, That's great, although it is the DS18B20 library that I haven't ever been able to get to work alongside MQTT. Maybe in another thread you could post that. This thread is about using Node-red w/ frankenstein directly.


Here it is https://github.com/pastukhov/nodemcu-mqttpir
Any contribution is welcome.
User avatar
By Artem Pastukhov
#19431
Mikejstb wrote:I hope this is not too off topic, but can you explain about the cjson structure that you're passing as the mqtt payload?
In pretty ignorant about json, and my only mqtt payload experience is sending simple strings.
Is it right to say that the cjson is a structure?
Is the end result a nicely organized payload with a lot of labeled (maybe "labeled" is the wrong word) diverse data, all in one mqtt message?
What does it actually look like when the mqtt broker receives it?
Like if you were to use something like mqttspy to watch your topic.
Always trying to learn new techniques and tricks!
Thanks

Yes,
Code: Select allJSON (/ˈdʒeɪsən/ JAY-sən),[1] or JavaScript Object Notation, is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML.
You can read more on Wikipedia.
If you get any JSON object you should parse it first like this
Code: Select allvar Object = JSON.parse("{\ "Status\": 0, \"Type\": \"PIR\", \"SensorID\": 10643050 });
and after that you can address any field of object:
Code: Select all console.log(Object.Status);

And also you can construct an object and send it to remote host
Code: Select allvar Obj = {};
Obj.Status=1;
var json=JSON.stringify(Obj);
console.log(json);
You will get {\"Status\":1} on console.