If you are asking a question, please follow this template:
- My goal is: [publish mqtt Temp from esp32 to google iot core ,and then test if I can read back that value by subscribing to the same topic…later want to publish temp from esp32-no1 and then read it by subscribing to the same mqtt topic on esp32-no2]
- My actions are: [publishing temp over mqtt using the following js code // This function reads data from the DHT sensor every 2 second
Timer.set(3000 /* milliseconds */, Timer.REPEAT, function() {
let msg = JSON.stringify({Temperature: dht.getTemp(), Humidity: dht.getHumidity()});
MQTT.pub(esp32_topic, msg, 1);
print(‘Temperature:’, dht.getTemp(), ‘*C’);
print(‘Humidity:’, dht.getHumidity(), ‘%’);
}, null);
3. The result I see is: [it is getting published and I can read the humidity and temperature value on google iot core]]
4. My expectation & question is: [Now I want to subscribe to this topic esp32_topic and pull out the temp and print the temp value on the serial port of the mos tool …I tried the following code MQTT.sub(esp32_topic, function(conn, esp32_topic, msg) {
print(‘Topic:’, esp32_topic, ‘message:’, msg);
let obj = JSON.parse(msg) || {Humidity: 0};
print(‘Humidity data from mqtt:’, obj.Humidity, ‘%’);
}, null);…it does not work]