Skip to content

Example 10: Timer Interrupt ​

Experiment Overview ​

Use FastBee's Timer Trigger to implement periodic task execution, such as periodic data acquisition, periodic status reporting, periodic peripheral control, etc. No hardware timer configuration needed, achievable through peripheral execution rules.

Hardware Wiring ​

This experiment does not require additional hardware, using the onboard LED or other peripherals to demonstrate timing functionality.

Board LabelGPIO PinConnected Device
D1GPIO15LED (for demonstrating timer effect)

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "timer_led",
      "name": "Timer LED",
      "type": 12,
      "enabled": false,
      "pins": [15],
      "params": { "initialState": 1 }
    }
  ]
}

Peripheral Execution Linkage ​

Function: Toggle LED state every 1 second for blinking effect

Web Interface Configuration Steps ​

Step 1: Create Rule

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

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Timer TriggerExecute at time intervals
    Timer ModeSelect Fixed IntervalBy millisecond interval
    Interval Time10001000ms = 1 second

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Toggle Level
    • Target Peripheral: Select timer_led
  3. Click Save button


Scenario 2: Periodic Status Report (Timer Trigger) ​

Function: Report system status to cloud platform every 5 seconds

Web Interface Configuration Steps ​

  1. Create rule, name: 5 Second Status Report
  2. Trigger configuration:
    • Trigger Type: Select Timer Trigger
    • Timer Mode: Select Fixed Interval
    • Interval Time: 5000 (5 seconds)
  3. Action configuration:
    • Action Type: Select System Report
    • Report Type: status
  4. Click Save

Scenario 3: Daily Timed Light On (Cron Expression) ​

Function: Automatically turn on light at 8 AM every day

Web Interface Configuration Steps ​

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

Timer Mode Reference ​

Timer ModeParameterExampleDescription
Fixed Intervalinterval (ms)1000 = 1sTrigger at fixed time interval
Daily TimerTime point08:00Trigger at fixed time daily
Cron Expressioncron"0 8 * * *"Flexible time expression

Timer Parameter Description ​

ParameterDescriptionExample
intervalFixed interval (ms)1000 = 1 second
cronCron expression"0 8 * * *" = every day at 8 AM

Notes ​

  1. Minimum Interval: Recommend not less than 100ms, too short will affect system performance
  2. Cron Requires NTP: Using Cron expressions requires the device to have synced time via NTP
  3. Parallel Rules: You can create multiple timer rules with different intervals, they do not interfere
  4. Precision: Software timer precision is ~±10ms, not suitable for microsecond-level precision requirements
  5. Task Blocking: Timer-triggered actions should not contain long blocking operations

FastBee | fastbee.cn