I have created a Publisher Script using Paho MQTT JavaScript API which publishes values to two topics MyHome/Temp and MyHome/Hum. The script is running successfully and publishing data to CloudMQTT broker. In my Subscriber script I have subscribed to these two topics and printing them in Console as following:
function onConnect() {
console.log("onConnect");
client.subscribe("MyHome/Temp");
client.subscribe("MyHome/Hum");
}
function onMessageArrived(message) {
console.log(message.destinationName +" : "+ message.payloadString);
}
It is printing both the topic names and corresponding values. Now I want to extract the values of both topics using message.payloadString and store in variable as following:
function onMessageArrived(message) {
var temp = message.payloadString;
var hum = message.payloadString;
...
}
But I am getting only on value in both variable i.e. the value of last topic 'hum'. Can anyone please help me solving this.