I am receiving Data from an MQTT Server, which is giving me data after some intervals. The Data received is in the form of JSON Object. I want to store the values of the data that I get and then pass it to my Database. But I am getting error Accessing its Keys.
This is my Function which is fetching the JSON Data.
function mqtt_messsageReceived(topic, message, packet) {
if(message !== null && message !== undefined )
{
var myMessages = message;
console.log('Messages are '+ myMessages);
}
};
This is my Console Log JSON Data.
Messages are {"Temp":26.50,"Door":1,"Fan1":0,"Fan2":0,"Time":"22-8-2018 16:05","mac":"5ccf7f5a4ba4"}
I Want to access Temp from this JSON Object.
I have tried doing :
console.log('Temp is '+myMessages.Temp);
But it only gives me an Error - Temp is undefined. I have Tried Fetching many ways, one way was with Object.values
var myMessages = Object.values(message);
All I get is some random numbers
My Messages are 123,34,84,101,109,112,34,58,50,52,46,53,48,44,34,68,111,111,114,34,58,49,44,34,70,97,110,49,34,58,48,44,34,70,97,110,50,34,58,49,44,34,84,105,109,101,34,58,34,50,50,45,56,45,50,48,49,56,32,49,54,58,49,54,34,44,34,109,97,99,34,58,34,53,99,99,102,55,102,53,97,52,98,97,52,34,125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Can anyone Help here ??