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…