Example 10: Timer Interrupt
About 2 min
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 Label | GPIO Pin | Connected Device |
|---|---|---|
| D1 | GPIO15 | LED (for demonstrating timer effect) |
JSON Configuration Example
{
"peripherals": [
{
"id": "timer_led",
"name": "Timer LED",
"type": 12,
"enabled": false,
"pins": [15],
"params": { "initialState": 1 }
}
]
}Peripheral Execution Linkage
Scenario 1: Fixed Interval Blink (Timer Trigger)
Function: Toggle LED state every 1 second for blinking effect
Web Interface Configuration Steps
Step 1: Create Rule
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
1 Second Timer Blink - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Execute at time intervals Timer Mode Select Fixed Interval By millisecond interval Interval Time 10001000ms = 1 second
Step 3: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Toggle Level
- Target Peripheral: Select
timer_led
Click Save button
Scenario 2: Periodic Status Report (Timer Trigger)
Function: Report system status to cloud platform every 5 seconds
Web Interface Configuration Steps
- Create rule, name:
5 Second Status Report - Trigger configuration:
- Trigger Type: Select Timer Trigger
- Timer Mode: Select Fixed Interval
- Interval Time:
5000(5 seconds)
- Action configuration:
- Action Type: Select System Report
- Report Type:
status
- Click Save
Scenario 3: Daily Timed Light On (Cron Expression)
Function: Automatically turn on light at 8 AM every day
Web Interface Configuration Steps
- Create rule, name:
Daily 8AM Light On - Trigger configuration:
- Trigger Type: Select Timer Trigger
- Timer Mode: Select Cron Expression
- Cron Expression:
0 8 * * *(every day at 8:00)
- Action configuration:
- Action Type: Select LOW Level (common-anode LED, LOW to light)
- Target Peripheral: Select
timer_led
- Click Save
Timer Mode Reference
| Timer Mode | Parameter | Example | Description |
|---|---|---|---|
| Fixed Interval | interval (ms) | 1000 = 1s | Trigger at fixed time interval |
| Daily Timer | Time point | 08:00 | Trigger at fixed time daily |
| Cron Expression | cron | "0 8 * * *" | Flexible time expression |
Timer Parameter Description
| Parameter | Description | Example |
|---|---|---|
| interval | Fixed interval (ms) | 1000 = 1 second |
| cron | Cron expression | "0 8 * * *" = every day at 8 AM |
Notes
- Minimum Interval: Recommend not less than 100ms, too short will affect system performance
- Cron Requires NTP: Using Cron expressions requires the device to have synced time via NTP
- Parallel Rules: You can create multiple timer rules with different intervals, they do not interfere
- Precision: Software timer precision is ~±10ms, not suitable for microsecond-level precision requirements
- Task Blocking: Timer-triggered actions should not contain long blocking operations
