How to override or detect SNTP_SET_SYSTEM_TIME_US?

vonnieda
Posts: 145
Joined: Tue Nov 07, 2017 3:42 pm

How to override or detect SNTP_SET_SYSTEM_TIME_US?

Postby vonnieda » Tue Feb 13, 2018 11:48 pm

Hi all,

I am using the SNTP module that comes with ESP-IDF / LWIP. It's working well, but I need to know when it has received a time update and set the time. When it does, it calls SNTP_SET_SYSTEM_TIME_US which is defined in $IDF_PATH/components/lwip/include/lwip/port/lwipopts.h.

Is there any way to override this and use my own function, or at least to be notified when it's called so I can do housekeeping?

Thanks,
Jason

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?

Postby loboris » Wed Feb 14, 2018 8:34 am

I've needed the same thing and ended up adding the global variable sntp_is_synced which is set to true before calling SNTP_SET_SYSTEM_TIME_US in "sntp.c".
Not a very elegant solution because I've modified the file in the esp-idf, but it works fine.

vonnieda
Posts: 145
Joined: Tue Nov 07, 2017 3:42 pm

Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?

Postby vonnieda » Wed Feb 14, 2018 5:42 pm

loboris wrote:I've needed the same thing and ended up adding the global variable sntp_is_synced which is set to true before calling SNTP_SET_SYSTEM_TIME_US in "sntp.c".
Not a very elegant solution because I've modified the file in the esp-idf, but it works fine.
Thanks loboris, I was hoping to avoid modifying esp-idf, but it does seem like that's the only option.

Thanks,
Jason

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?

Postby markwj » Tue Feb 27, 2018 1:45 am

I'm going to try to get a change to add an extensible callback mechanism added to ESP IDF master. In the meantime, we'll do it in our own clone.

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?

Postby markwj » Thu Mar 01, 2018 1:07 am

I have implemented something to deal with this in a standard way, and it works well for my use-case. I ended up simply moving the SNTP_SET_SYSTEM_TIME_US(t, us) into a sntp_setsystemtime_us(u32_t t, u32_t us) weak linked function (as well as doing the same with SNTP_SET_SYSTEM_TIME and sntp_setsystemtime, for completeness). That works well, and is easily overridable in user application code.

Code: Select all

extern "C"
  {
  void sntp_setsystemtime_us(uint32_t s, uint32_t us)
    {
    ... settimeofday ...
    }
  }
https://github.com/espressif/esp-idf/pull/1668

vonnieda
Posts: 145
Joined: Tue Nov 07, 2017 3:42 pm

Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?

Postby vonnieda » Fri Mar 02, 2018 3:57 pm

markwj wrote:I have implemented something to deal with this in a standard way, and it works well for my use-case. I ended up simply moving the SNTP_SET_SYSTEM_TIME_US(t, us) into a sntp_setsystemtime_us(u32_t t, u32_t us) weak linked function (as well as doing the same with SNTP_SET_SYSTEM_TIME and sntp_setsystemtime, for completeness). That works well, and is easily overridable in user application code.

Code: Select all

extern "C"
  {
  void sntp_setsystemtime_us(uint32_t s, uint32_t us)
    {
    ... settimeofday ...
    }
  }
https://github.com/espressif/esp-idf/pull/1668
This looks great, thank you! Looking forward to this getting merged!

Who is online

Users browsing this forum: Bing [Bot] and 158 guests