I have been using Electric Imp for a while now and I really like it. I am facing an issue with the Time and Date reporting. I am using date() function in my AGENT side of the device to get the UTC time but occasionally it reports erroneous time. I am not able to fix it as it is intermittent.
To extract the details out of the date() I am using:
var = date();
server.log(var.year);
server.log(var.month);
server.log(var.day);
server.log(var.hour);
server.log(var.min);
server.log(var.sec);
but the logs shows a widely different time than the current UTC time.
Can you give examples? Not sure how that could be wrong. Cut & paste from the log would be best as we can see the time on the log lines plus the logged numbers.
and when I do a server.log(dateCreated); and run with couple of minutes delay it throws the logs like this.
2015-08-26 13:07:45 UTC-4 [Agent] 2015-7-26 7:7:41
2015-08-26 13:09:46 UTC-4 [Agent] 2015-8-26 9:9:43
2015-08-26 13:12:29 UTC-4 [Agent] 2015-8-25 0:12:28
2015-08-26 13:15:13 UTC-4 [Agent] 2015-7-26 17:12:28
2015-08-26 13:26:10 UTC-4 [Agent] 2015-8-26 8:26:8
Not sure why it’s not working for you. Here’s the code I just tried and it works fine:
`
function printTime(){
local d = date();
server.log(format("%d-%02d-%02d %d:%02d:%02d", d.year, (d.month+1), d.day, d.hour, d.min, d.sec));
imp.wakeup(5, printTime);
}