Skip to content

Setting a callback for SNTP time sync event [feature request] #7616

Closed
@JakubRakus

Description

@JakubRakus

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12]
  • Core Version: [2.7.4]
  • Development Env: [Platformio]
  • Operating System: [Ubuntu]

Settings in IDE

  • Module: [Nodemcu]
  • Flash Mode: [dio]
  • Flash Size: [4MB]
  • lwip Variant: [v2]
  • Reset Method: [nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200] (serial upload only)

Problem Description

Function settimeofday_cb() sets a callback executed every time when settimeofday() is invoked. SNTP synchronization event change system time using settimeofday() - which is ok, but if I run settimeofday() manually also callback function is invoked. There is no mechanism to show what was the source of callback - network synchronization or manual set.

Expected Behavior

I can see at least three possible solutions:

  1. Add a parameter to callback function declaration - maybe some pointer to bool type variable which will be set to true if SNTP was a source of sync.
  2. Add another settimeofday-like function which do the same, but do not fire any callback.
  3. Expose ESP SDK function sntp_set_time_sync_notification_cb() from lwip/apps/sntp/sntp.c which sets a callback ONLY for SNTP synchronization.

Personally I prefer the 3rd one (only because I tested it in "plain" not "Arduino-based" ESP projects and works like a charm).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions