Example 16: RTC Clock (System NTP)
Example 16: RTC Clock (System NTP)
Experiment Overview
ESP32 does not have an independent RTC clock chip (time is lost on power-off), but after WiFi connection, NTP (Network Time Protocol) can be used to automatically sync network time. FastBee automatically performs NTP time sync after connecting to the network, which can be used for scheduled tasks and time display.
Hardware Wiring
No additional hardware needed for this experiment, utilizing ESP32's WiFi capability to obtain NTP time.
For time retention on power-off, refer to Example 17 (DS1302 External RTC).
JSON Configuration Example
Time-related functions are used through peripheral execution timer triggers:
{
"peripherals": [
{
"id": "tm1637_clock",
"name": "Clock Display",
"type": 47,
"enabled": false,
"pins": [18, 19],
"params": { "brightness": 4 }
}
]
}Peripheral Execution Linkage
Scenario 1: Update Time Display Every Second (Timer Trigger)
Function: Update seven-segment display with current system time every second (with colon blinking)
Web Interface Configuration Steps
Step 1: Ensure TM1637 seven-segment display is configured
- Peripheral ID:
tm1637_clock - Type: Seven-segment display
Step 2: Create Rule
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Clock Display - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 3: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Periodic update Timer Mode Select Fixed Interval By millisecond interval Interval Time 1000Update every 1 second
Step 4: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Display Time
- Target Peripheral: Select
tm1637_clock - Show Colon: ✅ Enable
Click Save button
Scenario 2: Auto Light On at 6 AM Daily (Cron Timer)
Function: Automatically turn on LED at 6 AM every day
Web Interface Configuration Steps
- Create rule, name:
Daily 6AM Light On - Trigger configuration:
- Trigger Type: Select Timer Trigger
- Timer Mode: Select Cron Expression
- Cron Expression:
0 6 * * *(every day at 6:00)
- Action configuration:
- Action Type: Select LOW Level (common-anode LED)
- Target Peripheral: Select
led_d1
- Click Save
Cron Expression Examples
| Cron Expression | Description | Execution Time |
|---|---|---|
0 6 * * * | Every day 6:00 | Every morning at 6 AM |
0 18 * * * | Every day 18:00 | Every evening at 6 PM |
*/5 * * * * | Every 5 minutes | Every 5 minutes |
0 */2 * * * | Every 2 hours | Every 2 hours on the hour |
Notes
- NTP Requires Network: First boot needs network connection to get time, offline mode continues from last sync
- Precision: NTP sync precision is ~±50ms, local crystal drift is ~±2ppm
- Power Loss: ESP32 RTC time is cleared on power-off, needs NTP re-sync on power-up
- Cron Expression: Supports standard 5-field format: minute hour day month weekday
- Timezone: System defaults to UTC+8, can be modified in device configuration
