|
NetBurner 3.5.8
PDF Version |
Example Path: examples/NTPClient
A NetBurner application that synchronizes its clock from an Internet time server using the Network Time Protocol (NTP) and serves a small web dashboard for viewing the time in any time zone.
The device runs an NtpClientServlet that keeps the system clock synchronized with an NTP server. A web page reads that clock live and displays it for a user-selected time zone, alongside a UTC/US world clock and the current NTP sync status. The same information is also logged to the debug serial port. It serves as a practical example of network time synchronization and of using the global time zone database in timezones.h.
Browse to http://<device-ip>/ to reach the dashboard:
settz.html) listing every zone from the timezones.h database, grouped into US/Canada and International using each record's bUsCanada flag. Selecting a zone applies its POSIX TZ string with tzsetchar().All dynamic values are supplied by <!--CPPCALL ... --> data providers in the C++ source; no page markup is built in C++. The pages use a self-contained stylesheet (plain CSS, no framework or CDN) so they render directly from the device with no external dependencies.
The world-clock table uses predefined POSIX format strings for the major US time zones:
The picker offers the complete TZRecords[] database, split into:
bUsCanadaShowNtpStatus(), ShowSelectedClock(), ShowWorldClock(), EmitTimeZoneOptions()CPPCALL data providers that write the dynamic values for each tag straight to the HTTP socket with fdprintf().
SetTzPost() / SyncNowPost()POST handlers that apply a selected time zone (tzsetchar()) or force an NTP refresh (RefreshNow()), then redirect back to the dashboard.
UserMain(void *pd)Main entry point: initializes the stack, starts the web server, synchronizes NTP, and logs the selected-zone time to serial.
init.h: System initializationhttp.h / httppost.h: Web server and POST handlingfdprintf.h: Writing dynamic values to the HTTP sockettime.h: Time manipulation functionsipshow.h: IP address display utilitiestimezones.h: Time zone database and utilitiesnbtime.h: NetBurner NTP/time functionsThe application uses the NtpClientServlet class for NTP operations:
TimeIsValid() reports whether the clock has been setGetSecsSinceUpdate() tracks time since the last NTP updateRefreshNow() forces an immediate synchronizationEnableSystemDiagnostics() for production deployment.TZRecords structure.