jeelabs / el-client

Arduino client for esp-link's REST, MQTT, and command interface
BSD 2-Clause "Simplified" License
83 stars 46 forks source link

How do I publish epoch time in MQTT #35

Closed swilson86 closed 7 years ago

swilson86 commented 7 years ago

Probably a simple answer, but I want to publish the Epoch time when my Arduino/esp-link boots up. This is invaluable as a debug tool so I know if a station is going down at a certain millis time, UpSince thingy in Node-Red, etc.

In the loop() in Arduino might start like: (which doesn't work)

define pubTopicEpoch "Rain/E/Epoch" // Publish station start time for failure analysis

uint32_t epoch; int EpochPublished = 0;

void loop() { esp.Process();

// Publish the startup time once if (connected && EpochPublished == 0) { epoch = cmd.GetTime(); mqtt.publish(pubTopicEpoch,epoch); // topic,payload,payloadlen,qos,retain EpochPublished = 1; } // more code }