Skip to content

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:

json
{
  "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

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Clock Display
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 3: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Timer TriggerPeriodic update
    Timer ModeSelect Fixed IntervalBy millisecond interval
    Interval Time1000Update every 1 second

Step 4: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Display Time
    • Target Peripheral: Select tm1637_clock
    • Show Colon: ✅ Enable
  3. 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 ​

  1. Create rule, name: Daily 6AM Light On
  2. Trigger configuration:
    • Trigger Type: Select Timer Trigger
    • Timer Mode: Select Cron Expression
    • Cron Expression: 0 6 * * * (every day at 6:00)
  3. Action configuration:
    • Action Type: Select LOW Level (common-anode LED)
    • Target Peripheral: Select led_d1
  4. Click Save

Cron Expression Examples ​

Cron ExpressionDescriptionExecution Time
0 6 * * *Every day 6:00Every morning at 6 AM
0 18 * * *Every day 18:00Every evening at 6 PM
*/5 * * * *Every 5 minutesEvery 5 minutes
0 */2 * * *Every 2 hoursEvery 2 hours on the hour

Notes ​

  1. NTP Requires Network: First boot needs network connection to get time, offline mode continues from last sync
  2. Precision: NTP sync precision is ~±50ms, local crystal drift is ~±2ppm
  3. Power Loss: ESP32 RTC time is cleared on power-off, needs NTP re-sync on power-up
  4. Cron Expression: Supports standard 5-field format: minute hour day month weekday
  5. Timezone: System defaults to UTC+8, can be modified in device configuration

FastBee | fastbee.cn