Set time via publish message

Using Time.setTime() could work.

// Expect data to be unix timestamp
void timeHandler(const char *event, const char *data)
{
int timeFromData = atoi(data);
Time.setTime(timeFromData);
}

// In setup()
Particle.subscribe("setTime", timeHandler, MY_DEVICES);

Alternatively, you could make use of Particle.syncTime() and call it routinely. This would be a more straightforward remedy and you wouldn’t need to manually sync the time with a publish.

1 Like