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
How to override or detect SNTP_SET_SYSTEM_TIME_US?
Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?
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.
Not a very elegant solution because I've modified the file in the esp-idf, but it works fine.
Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?
Thanks loboris, I was hoping to avoid modifying esp-idf, but it does seem like that's the only option.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,
Jason
Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?
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.
Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?
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.
https://github.com/espressif/esp-idf/pull/1668
Code: Select all
extern "C"
{
void sntp_setsystemtime_us(uint32_t s, uint32_t us)
{
... settimeofday ...
}
}
Re: How to override or detect SNTP_SET_SYSTEM_TIME_US?
This looks great, thank you! Looking forward to this getting merged!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.
https://github.com/espressif/esp-idf/pull/1668Code: Select all
extern "C" { void sntp_setsystemtime_us(uint32_t s, uint32_t us) { ... settimeofday ... } }
Who is online
Users browsing this forum: Baidu [Spider] and 59 guests