[SOLVED] Variable with timestamp does not update

Hello!
I’m using an ESP32 to send two variables with the pubsubclient-master library.
When I send only the values of the variable, they work well and get updated on my device panel, sending it this way:

msg = {“humidity”:24.00,“temperature”:24.00} //this is a string already formated
client.publish(TOPIC,msg.c_str())

but when I try to send the second variable timestamp, it does not update, but the first one does, like this:

msg = {“humidity”:25.00,“temperature”:{“value”:24.00,“timestamp”:1597740640000}} //this is the string I’m sending…
client.publish(TOPIC, msg.c_str());

every time I use the second code, the variable humidity gets updated normally, but the temperature does not update. Could some one help me, please??

Hello @pedrotalarico22

I don’t see any error in your payload structure. I even tested myself as shown below and it worked ok.

Can you please check, given the timestamp has already passed, that the value is not in the historical data and you’re not seeing it because that ?

Can you please print the payload before calling the publish method so we can make sure it is correct in the serial monitor using the c_str()function ?

–David

Thank you David, for the answer!

I’ve tested the timestamp and it relates to the normal date and hour…
I will explain a little more about my application:

I’m using ESP32 and a SIM800L to send the data from a sensor, besides that, I’m saving the data on an SD card, to when I don’t have access to the internet… that’s why I need to send the timestamp, so when I have access I send all the saved data and then I start to send the new ones…

my routine to send the saved data is this:

void publishMQTT2()
{
String msg = createJsonString2();
Serial.print("Publishing message from SD: ");
Serial.println(msg.c_str());

DateTime a(timestamp1.toInt()/1000);

Serial.print(a.hour());
Serial.print(":");
Serial.print( a.minute());
Serial.print(":");
Serial.print(a.second());

Serial.print(" “);
Serial.print(a.day());
Serial.print(”/");
Serial.print(a.month());
Serial.print("/");
Serial.print(a.year());

status = client.publish(TOPIC, msg.c_str());
Serial.println("Status: " + String(status));//Status 1 se sucesso ou 0 se deu erro
}
String createJsonString2()
{
String data = “{”;
if (!isnan(humidity) && !isnan(temperature))
{
data += ““humidity”:”;
data += String(humidity, 2);
data += “,”;
data += ““temperature”:”;
data += “{”;
data += ““value”:”;
data += String(temperature,2);
data += “,”;
data += ““timestamp”:”;
data += String(timestamp1);
data += “}”;
}
data += “}”;
Serial.println(data);
return data;
}

and my routine to send the real-time data is:

void publishMQTT()
{
String msg = createJsonString();
Serial.print("Publish message: ");
Serial.println(msg);

status = client.publish(TOPIC, msg.c_str());
Serial.println("Status: " + String(status));//Status 1 se sucesso ou 0 se deu erro
}

String createJsonString()
{
String data = “{”;
if (!isnan(humidity) && !isnan(temperature))
{
data += ““humidity”:”;
data += String(humidity, 2);
data += “,”;
data += ““temperature”:”;
data += String(temperature, 2);
}
data += “}”;
return data;
}

by the way that’s my topic:

#define TOPIC “/v1.6/devices/esp32-gsm”
#define MQTT_SERVER “mqtt://things.ubidots.com”
#define MQTT_PORT 1883

and that’s what the Serial print when I send the stored data:

Publishing message from SD:{“humidity”:19.00,“temperature”:{“value”:24.00,“timestamp”:1597825541000}}
1597825541
8:25:41 19/8/2020Status: 1

as the status = 1, the data was delivered, and when I check my variables at the ubidots, the humidity updates, but the temperature does not.

when I send the real-time data my serial print me this:

Publish message: {“humidity”:20.00,“temperature”:24.00}
Status: 1

and the two variables update at ubidots…

Pedro,

Your data is being correctly received. You need to note that as it is historical data, that is, in the past, it will be allocated as such in the middle of your data. With that in mind, you should narrow the time range so you can find it more easily and prove that it is actually there.
Here’s an screenshot of your account. You can see that the value 24 in the temperature variable with timestamp 1597825541000 is present as expected.

Also, as a STEM user, you should be using the broker address industrial.api.ubidots.com instead of things.ubidots.com

Best,

–David

David,

I’m very thankfull for you answer!
Indeed, the data was being received, but as I’m in Brazil, the timestamp that I was sending is 3 hours less than the time here, and that’s why I was not finding the right data…
I was looking for a data that was 3 hours shifted…

To all the support staff, my thank you!

Best regards!