Timestamped data

You can send your own time with extra virtualwrite’s.

Just note the time when you read your sensor, and the delay in internet travel and the variance in delay are avoided. Conceivably they could add a “time” field, just like a “unit” field, which would be better.

Here is some code (arduino code for 8266)

// ~~~~~ declarations ~~~~~
#include <time.h>

int timezone = -6; // -6 for daylight savings, -7 regular mountain
struct tm * timeinfo;
time_t boottime;
time_t now;

// ~~~~~ setup ~~~~~

configTime(timezone * 3600, 0, “pool.ntp.org”, “time.nist.gov”);
Serial.println(“\nWaiting for time”);
while (!time(nullptr)) {
Serial.print(“.”);
delay(1000);
}
Serial.println(“”);
now = time(nullptr);
Serial.println(ctime(&now));
boottime = now;

// ~~~~~ CAYENNE_OUT_DEFAULT ~~~~~
now = time(nullptr);
// Cayenne.virtualWrite(1, now, “UnixTime”, “Seconds”); // not UTC
long seconds = now - boottime;
hours = seconds / 3600.0;
Cayenne.virtualWrite(0, hours, “Uptime”, “Hours”);
time_t now = time(nullptr);
Serial.print(ctime(&now));
timeinfo = localtime (&now);
float timefloat = timeinfo->tm_hour*100 + timeinfo->tm_min + timeinfo->tm_sec/100.0;
Cayenne.virtualWrite(2, timefloat, “Time”, “HHMM.SS”);

1 Like