Two questions:
Question 1: I am using a BME280 sensor with an esp32 trying to send data to Ubidots using MQTT. Connection is fine, using the library UbidotsEsp32Mqtt.h. All readings normal.
Background: ESP is in deep sleep, wakes up, performs reading of temp and humidity, stores the values in variables. Correct values is saved, I run a function to send these values to Ubidots with the following code:
if (!ubidots.connected()) {
ubidots.reconnect();
}
ubidots.add("temperature", tempToSend);
ubidots.publish(DEVICE_LABEL);
ubidots.add("humidity", humToSend);
ubidots.publish(DEVICE_LABEL);
/* Close MQTT client cleanly */
ubidots.disconnect();
Problem is: only temp value is being sent, humidity value is not being sent at the same moment, just once in a while, or not at all.
Using ubidots.setDebug(true) it seems that the values are being published:
From Serial monitor:
15:38:32.172 -> publishing to TOPIC:
15:38:32.172 -> /v2.0/devices/bme280
15:38:32.172 -> JSON dict: {"temperature": [{"value": 25.688}]}
15:38:32.172 -> publishing to TOPIC:
15:38:32.172 -> /v2.0/devices/bme280
15:38:32.172 -> JSON dict: {"humidity": [{"value": 37.97}]}
15:38:42.215 -> ets Jun 8 2016 00:22:57
Question 2:
On another esp32 I run an hcsr04 sensor, which is in deep sleep, wakes up once in a while to read sensor and check it against a given value.
If the value is above a threshold, it is meant to send a value, and text. Following is my code simplified to test those two actions.
void sendMQTTmessage(int value, char* text) {
if (!ubidots.connected()) {
ubidots.reconnect();
}
ubidots.add("topic", value, text);
ubidots.publish(DEVICE_LABEL);
/* Close MQTT client cleanly */
ubidots.disconnect();
}
if(reading > threshold) {
//send MQTT
value = reading;
text= "Text!"; //test value
sendMQTTmessage(value, text);
esp_deep_sleep_start();
}
In this test Ubidots is not receiving anything, but if I completely remove everything associated with the “text” variable, and just sending the int value, it works just fine. I cannot get it to send a context. Any ideas what I am doing wrong?
I have checked the API labels in Ubidots countless times, for both devices and variables. They match the ones I put into my code.