Control Watchdog
x/control/watchdog component: a soft-PLC watchdog (link-loss protection). Normally it forwards every message downstream as-is and uses it to "feed" (reset) the timer; once no message arrives within timeout, it treats the host/link as lost and automatically emits a preconfigured failsafe JSON downstream (e.g. close valve, stop motor) to drive the device into a safe state. Protocol- and data-format-agnostic, it is typically wired in front of x/iotWrite.
Additional extension library required: rulego-components-iot (opens new window)
# Configuration
| Field | Type | Required | Description |
|---|---|---|---|
| timeout | string | Yes | Feed timeout: if no new message arrives within this duration after the last one, the link is deemed lost and the failsafe is emitted; each received message resets the timer (feeds the dog). e.g. 10s, 500ms; supports ${metadata.xx} |
| failsafe | string(JSON) | Yes | Safety-state JSON emitted on link loss, e.g. {"valve":0,"motor":0} (close valve, stop motor); written to msg.Data via the Success chain — its keys must match the downstream write points' ${msg.xx} |
# Behavior
- Message received: the original message is forwarded downstream (
Success) and the timer is reset. timeoutreached with no message: thefailsafeJSON is emitted via theSuccesschain.- Message count: with continuous feeding, each feed is forwarded once and the alarm is reset, so the failsafe is not triggered; only on a real link loss (timeout) is one extra failsafe emitted after the last forwarded feed.
- The watchdog never blocks the rule chain: both forwarding and the failsafe go through
Success, and the timeout alarm does not take part in the chain's completion counting.
# Relation Type
- Success: Message forwarded, or the failsafe payload emitted.
- Failure: Execution fails (e.g.
failsafenot configured); the message is sent to theFailurechain.
# Example
{
"ruleChain": {
"id": "watchdog_demo",
"name": "Watchdog failsafe demo",
"root": true,
"debugMode": false
},
"metadata": {
"firstNodeIndex": 0,
"nodes": [
{
"type": "x/control/watchdog",
"name": "Host link-loss protection",
"debugMode": false,
"configuration": {
"timeout": "10s",
"failsafe": "{\"valve\":0,\"motor\":0}"
}
}
],
"connections": []
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Full Scenario: Host Link-Loss Protection
Process: the host periodically sends setpoints (doubling as heartbeats); once the host or link fails and no message arrives for 10 seconds, close the valve to 0 and stop the motor to 0, entering the safe state.
{
"ruleChain": {"id": "watchdog-guard", "name": "Host link-loss protection", "root": true},
"metadata": {
"nodes": [
{"id": "e1", "type": "endpoint/modbusServer", "configuration": {
"listen": "tcp://:5020", "unitId": 1
}},
{"id": "wd", "type": "x/control/watchdog", "configuration": {
"timeout": "10s", "failsafe": "{\"valve\":0,\"motor\":0}"
}},
{"id": "w1", "type": "x/iotWrite", "configuration": {
"driver": "modbus", "server": "tcp://192.168.1.100:502",
"points": [
{"name": "valve", "addr": "40001", "type": "UINT16", "value": "${msg.valve}"},
{"name": "motor", "addr": "40002", "type": "UINT16", "value": "${msg.motor}"}
]
}}
],
"connections": [
{"fromId": "e1", "toId": "wd", "type": "ip"},
{"fromId": "wd", "toId": "w1", "type": "Success"}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
The host writes registers via
endpoint/modbusServer(heartbeat + setpoint) → watchdog forwards and feeds →x/iotWritewrites${msg.valve}/${msg.motor}to the device. On link-loss timeout the watchdog emitsfailsafe, and the write node drives valve/motor to 0.
Timing behavior:
| Scenario | Messages | Next node receives |
|---|---|---|
| Continuous feeding (interval < 10s) | each feed forwarded once, alarm reset | one forwarding per feed, no failsafe |
| Link loss (> 10s no message) | last forwarding + timeout failsafe | one forwarding + one failsafe ({"valve":0,"motor":0}) |
More combination examples: IoT Scenarios · Soft-PLC Logic Control