logo elektroda
logo elektroda
X
logo elektroda

ESP32 to ArduinoDUE: Minimizing Time Sync Frequency for Efficient Communication

powerT 918 4
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19264188
    powerT
    Level 9  
    Welcome.

    ESP32 WiFi (reads weather data from openWeatherMap and current time from pool.ntp.org). On top of that, it does a lot of other things - everything works fast and lovely (not web server related because I don't need that) and sends a lot of data to the Arduino DUE. These parse them nicely, split by code where needed, but ................. (weather data is updated every 3h, current date data every 12h, but current time every 1 second and I want to change that).

    I need to minimise communication to a minimum as the DUE will also have something on it, and for now I have it that the DUE doesn't have a clock module (I just don't want one) - this data comes from the ESP32. I send it every second to keep it reasonably up to date.

    My question : is there a physical possibility after sending from ESP32 the current time to DUE e.g. 12h 10m 11s to make it for an hour by some physical internal (no update) method to walk this clock by itself. It does not have to be very accurate, a discrepancy of 1 or 2 minutes is tolerable, after an hour it will correct itself.

    To this structure I write the time read from the ESP

    
    struct Czas                         
    {                                           
        int       godzina = 0;            // godzina [ h ]
        int       minuta  = 0;            // minuta [ m ] 
        int       sekunda = 0;          // sekunda [ s ] 
        char      wschod[10];         // wschód słonca [HH:MM]
        char      zachod[10];          // zachód słońca [HH:MM] 
    } czas;       
    
    .
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 19264272
    khoam
    Level 42  
    powerT wrote:
    My question : is there any physical possibility after sending from ESP32 the current time to DUE e.g. 12h 10m 11s to make it for an hour by some physical internal (no update) method this clock goes by itself. It does not have to be very accurate, a discrepancy of 1 or 2 minutes is tolerable, after an hour it will correct itself.

    As far as I understood the question, you would like to rely only on the internal RTC clock in the ESP32 for about 1h. If accuracy is not required, then simply retrieve the time with the command gettimeofday () when necessary and send to Due. Of course, this time should be set beforehand with the command settimeofday () or adjtime (), after it has been retrieved by NTP (if you are not already doing so). More is hard to say without seeing the code.
  • ADVERTISEMENT
  • #3 19264299
    powerT
    Level 9  
    No no no, not on the ESP. The Esp takes the time ( in the meantime it embraces the TFT display and the MAX7219) - that's all hunky-dory, and it sends the time and date to the Arduino DUE, and I want it to do that just for synchronisation purposes. Because the DUE is supposed to handle the time by itself for an hour, I found myself some DueTimer.h library under the DUE and am just embracing it. DUE has a lot of relays and other sensors on its head, and sometimes ESP helps it because it also sends some data there (some calculations are time-consuming) - I know you can connect a clock module there, but I already have so many cables ... I know you can connect the clock module there, but I already have so many cables there ... I'll try something with the DueTimer because I think it's simpler to count microseconds, at first glance it looks cool.
  • ADVERTISEMENT
  • #4 19264317
    khoam
    Level 42  
    powerT wrote:
    No no, not on the ESP. The Esp takes the time ( in the meantime it engulfs the TFT display and MAX7219) - that's all hula, and it sends the time and date to the Arduino DUE, and I want it to do that just for synchronisation.
    .
    If it's supposed to do it "just for synchronisation purposes" then decide for yourself how often ESP should do it. Sorry, but again I don't understand the problem ie why is this even a problem if you are already sending time from ESP to Due.
  • #5 19264347
    powerT
    Level 9  
    Because it has to send it e.g. every hour (then I disable the threads for a while so that only the communication works between ESP and DUE, - so what if the ESP sends it if the DUE doesn't care because it is doing something else, I need to synchronise these communication times) and I need a clock on the DUE

    Thanks, you guided me :) .

    I found something else under DUE. Because what you wrote was for ESP. For DUE there is such a library "rtc_clock.h"
    It's all working now... I'm not going to head around and pat the code (reinvent the wheel).

    
    void saveParsedData()
    {
        switch ( ParseCodeFromEsp )                                                   // kod odebrany przez ESP
        {
            // wyciete
            case    95  :   czas.godzina        = int(ParseFloatFromEsp);       break;  // zapisz godzinę z serwera NTP
            case    96  :   czas.minuta         = int(ParseFloatFromEsp);       break;  // zapisz minutę z serwera NTP
            case    97  :   czas.sekunda       = int(ParseFloatFromEsp);      break;  // zapisz sekundę z serwera NTP
            // wyciete
            default     :   break;
        }
    
        if( ParseCodeFromEsp == 97)
        {
            rtc_clock.set_time(czas.godzina, czas.minuta, czas.sekunda);          // aktualizacja zegara DUE
        }
    }
    /code]
    
    działa. Miłego wieczorka
    .
ADVERTISEMENT