Skip to content

Peripheral Execution Management ​

1. Overview ​

Peripheral Execution (Periph-Exec) is the automation rule engine of the FastBee system, achieving device linkage by configuring Triggers and Actions. Configuration is stored in /config/periph_exec.json.

Factory default rules are all enabled: false, not auto-executing in unknown wiring environments. After adding or importing rules, save as disabled first, confirm target peripheral, pin and action parameters are correct before enabling.

Rule list is for quick verification of triggers, action count, enabled status and manual execution entry. When adding or editing rules, first confirm target peripheral exists and is in expected enabled state.

The diagram maps "triggers, rules, actions, execution results" in the page to the runtime chain. When configuring in the field, prioritize making each rule name readable, trigger condition single and clear, action sequence rollbackable.

When adding rules, follow the lifecycle diagram: disabled save, validate params, manual execute, enable run, abnormal rollback. This prevents driving field loads immediately after saving in unknown wiring environments.


2. Web Interface Operation Guide ​

2.1 View Rule List ​

Rule list displays:

FieldDescription
NameRule display name
StatusEnabled / Disabled
TriggerTrigger type (Timer, Event, Platform, Poll)
ActionsAction count
Trigger CountNumber of times triggered
OperationsExecute Once / Edit / Enable / Delete

2.2 Add Rule ​

  1. Click + Add Rule button
  2. Fill in rule name
  3. Select trigger type and configure trigger parameters
  4. Add actions (one or more)
  5. Save rule

2.3 Edit Rule ​

  1. Find target rule in list
  2. Click Edit button
  3. Modify trigger or actions
  4. Save changes

2.4 Execute Once ​

  1. Find target rule in list
  2. Click Execute Once button
  3. View execution log

Note: Execute once does not depend on rule enabled status, convenient for debugging.

2.5 Enable/Disable Rule ​

  • Enable: Rule joins scheduler, auto-triggers when conditions met
  • Disable: Rule leaves scheduler, no longer auto-triggers

2.6 Delete Rule ​

  1. Find target rule in list
  2. Click Delete button
  3. Confirm deletion

2.7 Backup and Restore ​

The current Peripheral Exec page operates on one rule at a time. To back up or restore periph_exec.json, use Device Configuration > Advanced Configuration > Configuration Import/Export. The page does not provide batch enable/disable controls.


3. Trigger Types ​

Trigger objects use the flat fields below. A rule may contain up to three triggers; they have OR semantics.

triggerTypeTriggerMain fields
0PlatformtriggerPeriphId, operatorType, compareValue
1TimertimerMode, intervalSec, timePoint
4EventeventId, operatorType, compareValue
5PolltriggerPeriphId, operatorType, compareValue, intervalSec, poll timeout/retry fields

3.1 Platform Trigger (triggerType=0) ​

Matches values received from the platform. Set operatorType=1 when the received value should be passed directly to an action.

json
{
  "triggerType": 0,
  "triggerPeriphId": "relay_1",
  "operatorType": 0,
  "compareValue": "on"
}

3.2 Timer Trigger (triggerType=1) ​

timerMode=0 runs at an interval in seconds; timerMode=1 runs once each day at HH:MM.

json
{
  "triggerType": 1,
  "timerMode": 0,
  "intervalSec": 60
}
json
{
  "triggerType": 1,
  "timerMode": 1,
  "timePoint": "08:30"
}

3.3 Event Trigger (triggerType=4) ​

Uses a static or dynamic event ID returned by the event-list APIs. Conditions are optional when the event ID alone is sufficient.

json
{
  "triggerType": 4,
  "eventId": "wifi_connected",
  "operatorType": 0,
  "compareValue": ""
}

3.4 Poll Trigger (triggerType=5) ​

Actively reads a peripheral and evaluates the returned value. intervalSec is in seconds; timeout and inter-poll delay are in milliseconds.

json
{
  "triggerType": 5,
  "triggerPeriphId": "dht_temp",
  "operatorType": 2,
  "compareValue": "35",
  "intervalSec": 5,
  "pollResponseTimeout": 1000,
  "pollMaxRetries": 2,
  "pollInterPollDelay": 100
}

operatorType values are 0 equal, 1 not equal, 2 greater than, 3 less than, 4 greater than or equal, 5 less than or equal, 6 inside range, 7 outside range, 8 contains and 9 does not contain.


4. Action Types ​

Actions also use a flat structure. targetPeriphId identifies the target, actionType selects the operation, actionValue carries its parameter, and syncDelayMs delays that action by up to 10 seconds.

json
{
  "targetPeriphId": "relay_1",
  "actionType": 0,
  "actionValue": "",
  "useReceivedValue": false,
  "syncDelayMs": 0,
  "execMode": 0
}

Common action types include GPIO high/low (0/1), blink (2), PWM (4), system restart (6), generic peripheral command (10), NeoPixel effect (11), command script (15), Modbus coil/register write (16/17), Modbus poll (18), sensor read (19), event emission (21), display (24-27) and UART send (29). The Web page filters actions by active feature and target peripheral type.


5. Configuration File Format ​

All execution rules stored in /config/periph_exec.json:

json
{
  "rules": [
    {
      "id": "rule_001",
      "name": "Temperature Alarm",
      "enabled": false,
      "execMode": 0,
      "triggers": [
        {
          "triggerType": 5,
          "triggerPeriphId": "dht_temp",
          "operatorType": 2,
          "compareValue": "35",
          "intervalSec": 5,
          "pollResponseTimeout": 1000,
          "pollMaxRetries": 2,
          "pollInterPollDelay": 100
        }
      ],
      "actions": [
        {
          "targetPeriphId": "relay_fan",
          "actionType": 0,
          "actionValue": "",
          "useReceivedValue": false,
          "syncDelayMs": 0,
          "execMode": 0
        }
      ],
      "protocolType": 0,
      "scriptContent": "",
      "reportAfterExec": true
    }
  ]
}

6. Runtime Availability ​

Peripheral Exec is compiled in the release baseline. Timer, event, platform and poll triggers share the same rule engine. An action is shown and accepted only when its dependency is active: display actions require the display feature, Modbus actions require modbus, scripts require ruleScript/commandScript, and MQTT actions require mqtt. Check /api/features/status on the target device.


7. Troubleshooting ​

IssuePossible CauseSolution
Rule not triggeringTrigger condition not metCheck trigger type and parameters, confirm source peripheral working
Action not executingTarget peripheral disabledEnable target peripheral
Script execution errorSyntax errorCheck script syntax, refer to Rule Script documentation
Modbus action timeoutCommunication failureCheck Modbus wiring, baud rate, slave address
Rule execution too slowToo many actionsReduce action count, use async execution
Trigger count not increasingScheduler not runningConfirm at least one rule enabled
Import config failedJSON format errorCheck JSON syntax, ensure field types correct
MQTT action not sendingMQTT not connectedCheck MQTT connection status

FastBee | fastbee.cn