I am wanting to get a timestamp with the current time (from inside a timer function), and am using Timer.now()
combined with Timer.fmt()
see code below. But it looks like the Unix time is reset whenever the code is flashed, as I get dates from 1970 (or Unix timestamps starting from 0). I don’t know it this has to do at all with Mongoose OS, but I haven’t found info anywhere about the problem. Have looked at this thread for instance, but it didn’t help me as I have sntp in my libs already. I’m very grateful for any help thanks.
Timer.set(interval_pH, Timer.REPEAT, function() {
let pH = get_pH();
let timestamp_pH = Timer.now();
let datetime_pH = Timer.fmt("%Y-%m-%d %H:%M:%S", timestamp_pH);
print('pH from mJS: ', pH);
print('datetime pH: ', timestamp_pH);
let json_str = '{pH: ' + JSON.stringify(pH) +'datetime_pH: ' + JSON.stringify(datetime_pH) +'}';
// Publish data to pub/sub
if (pH !== 0) {
MQTT.pub(eventsTopic, json_str, 1);
}
}, null);