NTP Client Example Application
A NetBurner embedded system application that demonstrates Network Time Protocol (NTP) client functionality, providing synchronized time display with timezone support.
- Warning
- For this example to function, your NetBurner device must have access to the Internet with a working configuration for the IP address, mask and gateway.
Overview
This application connects to an NTP server to synchronize the system clock and displays time information in multiple formats and time zones through the debug serial port. It serves as a practical example of network time synchronization for embedded NetBurner devices.
Features
- NTP Time Synchronization: Automatically connects to NTP servers for accurate time
- Multiple Time Zone Support: Displays time in UTC, local time, and major US time zones
- Interactive Time Zone Selection: Choose between US/Canada or International time zones
- Real-time Display: Continuously updates and displays current time information
- Network Diagnostics: Shows IP configuration and network status
Prerequisites
- NetBurner device with network connectivity
- Proper IP configuration (IP address, subnet mask, gateway)
- Internet access to reach NTP servers
- MTTTY or similar terminal program for monitoring output
Time Zone Features
Supported US Time Zones
The application includes predefined format strings for major US time zones:
- Eastern Time (EST/EDT)
- Central Time (CST/CDT)
- Mountain Time (MST/MDT)
- Pacific Time (PST/PDT)
Time Zone Selection
Users can choose between:
- US/Canada Time Zones: Filtered list of North American zones
- International Time Zones: Complete global time zone database
- Note
- Good example of using the global time zone database timezones.h
Application Flow
- Initialization: System starts and enables network diagnostics
- Network Setup: Waits for active network connection (10-second timeout)
- NTP Synchronization: Connects to NTP server and waits for valid time
- Time Zone Setup: Prompts user to select preferred time zone
- Display Loop: Continuously shows time in multiple formats
Time Display Format
The application displays time information in the following format:
Time[ZONE] = MM/DD/YYYY day: DDD (DAY) HH:MM:SS
Where:
ZONE: Time zone abbreviation
MM/DD/YYYY: Month/Day/Year
DDD: Day of year (1-365/366)
DAY: Day of week abbreviation
HH:MM:SS: Hour:Minute:Second in 24-hour format
Output Examples
Local Time Display
Local time based on SetTimeZone() function:
Time[PST] = 7/21/2025 day: 202 (MON) 15:30:45
UTC Time Display
UTC time =
Time[UTC] = 7/21/2025 day: 202 (MON) 23:30:45
Multiple Time Zone Display
Displaying US time zones with local format strings:
Time[EST] = 7/21/2025 day: 202 (MON) 18:30:45
Time[CST] = 7/21/2025 day: 202 (MON) 17:30:45
Time[MST] = 7/21/2025 day: 202 (MON) 16:30:45
Time[PST] = 7/21/2025 day: 202 (MON) 15:30:45
Key Functions
SetTimeZone()
Interactive function that allows users to select their preferred time zone from either US/Canada or International options.
PrintTimeStruct(struct tm &bt)
Formats and displays time information in a standardized format to the debug serial port.
UserMain(void *pd)
Main application entry point that handles initialization, NTP synchronization, and the main display loop.
Technical Details
Dependencies
init.h: System initialization
time.h: Time manipulation functions
ipshow.h: IP address display utilities
timezones.h: Time zone database and utilities
nbtime.h: NetBurner time functions
NTP Client
The application uses the NtpClientServlet class for NTP operations:
- Waits up to 20 seconds for valid NTP response
- Provides retry mechanism with status updates
- Tracks time since last NTP update
Usage Instructions
- Hardware Setup: Connect NetBurner device to network
- Network Configuration: Ensure proper IP, mask, and gateway settings
- Terminal Connection: Use MTTTY to monitor serial output
- Run Application: Deploy and execute the application
- Time Zone Selection: Follow prompts to select desired time zone
- Monitor Output: View continuous time updates
- Manual Refresh: Press any key to update display on demand
Status Information
The application provides:
- Network connectivity status
- NTP synchronization status with retry notifications
- Time since last NTP update
- IP address configuration display
Troubleshooting
- No Network: Ensure device has proper network configuration
- NTP Timeout: Check internet connectivity and firewall settings
- Invalid Time: Wait for NTP synchronization to complete
- Display Issues: Verify MTTTY terminal settings and baud rate
Development Notes
- Remove
EnableSystemDiagnostics() for production deployment
- Time zone database extensible through
TZRecords structure
- IPv6 support available when compiled with IPV6 flag