Calculation of time interval



  • I am trying to calculate time interval by calling millis() function in loop().
    Looks like returned values are affected by smartSleep(). I mean time doesn't grow much during sleep.
    Is there a more reliable way to detect timeout?


  • Hero Member

    @benya the 'sleep' function causes the millis() timer to stop. Using an external clock (rtc) would be the best solution for low power operation. If you know how long you sleep you can do some calculations in the loop. Smartsleep() is not very predictable in this case 😉



  • @AWI If there is no RTC, should I opt to use requestTime() and receiveTime()?


  • Hero Member

    @benya That would be a solution just be aware that you need to wail for reception of the time information.



  • @AWI If node requests time and values before going to sleep, it will receive them upon return from smartSleep?

    void loop()
    {
      requestTime();
      request(1, V_STATUS); 
      request(2, V_STATUS);
      smartSleep(200);
    }
    
    void receive(const MyMessage &message)
    {
    ...
    }
    
    void receiveTime(unsigned long ts)
    {
    ...
    }

Log in to reply
 

Suggested Topics

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts