Incorrect time from emoncms.org....sometimes

Now that my DHCP issues with the Nanode have been resolved, I've had some time to fine tune my configuration. I've recently switched from having a local emoncms server running to using emoncms.org (my local pc steadfastly refused to update emoncms). My emoncms.org account is set up, nanode is posting to it, time offset on the account is set to +1 hour. All seems ok.

I've noticed that my GLCD time is incorrect when I'm up and about early in the morning. Around 6-6:30am, the time reads approximately 20 minutes early. However, when I'm home from work at 6pm, the time is correct and appears to remain correct until midnight, not that I sit and watch it for six hours, but I did make a special effort to keep an eye on it the other night :)

The wife hasn't noticed any errors in the time during the day, but she also didn't realise there was a clock on it.

Petrik's picture

Re: Incorrect time from emoncms.org....sometimes

 

Have noticed the same - early in the morning the emonGLCD goes backwards sometimes, time is synchronized using nanodeRF and emonCMS.

 

 

 

edllew's picture

Re: Incorrect time from emoncms.org....sometimes

This is a bug which is also affecting me.  I think it is because:

http://emoncms.org/time/local.json?apikey= [YOUR APIKEY HERE]

returns a time string like:

t9,28,39

The code in NanodeRF_Power_RTCrelay_GLCDtemp.ino expects formating like this instead:

t09,28,39

where it is doing some parsing:

    char tmp[] = {line_buf[1],line_buf[2],0};
    byte hour = atoi(tmp);
etc.

The problem could be fixed there, but should really be fixed at the time server on emoncms.org.

 

edllew's picture

Re: Incorrect time from emoncms.org....sometimes

I also notice that at the moment (17:12 local time, aka 5:12 PM USA west coast, or 00:12 in the UK I think) the time server is returning to me:

t-7,11,21

My local time time offset in hours on my EmonCMS account page is set to -7.

Again, this could be corrected for on the emonGLCD, but would best be corrected on emoncms.org.  I poked around the emoncms codebase a little, but struck out trying to find where the time server calculations go on.

edllew's picture

Re: Incorrect time from emoncms.org....sometimes

To fix this I changed NanodeRF_Power_RTCrelay_GLCDtemp.ino:

in my_callback() I replaced the 6 lines calculating hour, minute, second with:

    //Time received can be: t-7,11,21  or  t9,28,39  or  t09,28,39  .  Null terminated.
    int j = int (line_buf[3]==','); //j is true/1 if comma in 4th byte
    byte hour = (atoi(line_buf+1) + 24) % 24;  //make hour non-negative
    byte minute = atoi(line_buf+3+j);
    byte second = atoi(line_buf+6+j);

So far it works for me at my local time offset of -7 hours, as well as at some other random values I tested at.

 

 

RobertK's picture

Re: Incorrect time from emoncms.org....sometimes

A nice solution! I would prefer to do the test this way:

    int j = (line_buf[3]==',') ? 1: 0;

(using the ternary operator. It specifically sets j to either 0 or 1.  I think it is safer and clearer.).

Petrik's picture

Re: Incorrect time from emoncms.org....sometimes

Wow - thanks, just programmed this in. ;-)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.