Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback when the time is set on SNTP (IDFGH-354) #2349

Closed
cperezvinsite opened this issue Aug 29, 2018 · 5 comments
Closed

Callback when the time is set on SNTP (IDFGH-354) #2349

cperezvinsite opened this issue Aug 29, 2018 · 5 comments

Comments

@cperezvinsite
Copy link

cperezvinsite commented Aug 29, 2018

Environment

ESP32-Wrover-Kit

  • Development Kit: ESP32-Wrover-Kit
  • IDF version 698d3ba
  • Operating System: MacOS

Problem Description

There is some actions that depends on time change, for instance the initialize cron jobs. Then I would recommend an event system based on callbacks in sntp component in order to be capable of find out the time is set.

Expected Behavior

sntp has a funcition to register a callback, then, when the time is set in SNTP_SET_SYSTEM_TIME_US or SNTP_SET_SYSTEM_TIME the callback is called in order to be able to know when the time is set

Actual Behavior

There is no callback

My code

I create this function to be able to matriculate an event
sntp.c

void 
sntp_set_time_callback(void (* callback)(time_t *now))
{
  sntp_time_callback = callback;
}

Then I call the callback on lines 225 or 235 but just if the callback is set

I already have this code, and if you want I could make a pull request in order to add this feature into ESP-IDF

@FayeY FayeY changed the title Callback when the time is set on SNTP [TW#25967] Callback when the time is set on SNTP Sep 2, 2018
@liuzfesp
Copy link
Contributor

liuzfesp commented Sep 4, 2018

Thanks @cperezvinsite for your suggestion. I guess this is not an feature in original LWIP release, right? In IDF v3.2, we have updated the LWIP to v2.0.3 and the goal is to minimize Espressif specific change unless it's a bug or very important feature. So currently I'm not sure we will add it in the future.

@vonnieda
Copy link
Contributor

vonnieda commented Sep 4, 2018

There's an active PR for this and Espressif has said they will merge it: #1668

@X-Ryl669
Copy link
Contributor

X-Ryl669 commented Nov 19, 2018

What about a callback in settimeofday (since SNTP will call it anyway, but any other function that's changing time). IMHO, it's better to hook here because:

  1. If you have a CRON like behaviour, you also want to be informed when the user change the time herself (provided you have this option)
  2. It does not depend on LWIP or any version of it, so there's much less maintenance to the code
  3. You can set your callback to null when the time is first set so it won't be called continuously by the NTP client
  4. You don't need to call gettimeofday since timeval will already be available (so it's faster)

In the #1668, I've provided example code, it's 4 lines.

@projectgus projectgus changed the title [TW#25967] Callback when the time is set on SNTP Callback when the time is set on SNTP (IDFGH-354) Mar 12, 2019
@KonstantinKondrashov
Copy link
Collaborator

Hi @cperezvinsite. We added this feature in 7e5be1b. There has been added the void __attribute__((weak)) sntp_sync_time(struct timeval *tv)() function which you can define in your code to update time yourself.
Or use the sntp_set_time_sync_notification_cb() function to set a callback function to notify about the time synchronization process.
Also you can use sntp_get_sync_status() function to get time synchronization status.

@Alvin1Zhang
Copy link
Collaborator

@cperezvinsite Thanks for reporting the issue, and feel free to reopen the issue if you still have the question. Thanks.

0xFEEDC0DE64 pushed a commit to 0xFEEDC0DE64/esp-idf that referenced this issue May 5, 2021
Executing python2 get.py behind proxy give error "IOError: [Errno socket error] [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants