RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • AI Agent Framework
  • TPCLAW Agent Platform (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • AI Agent Framework
  • TPCLAW Agent Platform (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

    • Extension Components Overview
    • filter

    • action

    • transform

    • external

    • ai

    • ci

    • IoT

      • IoT Components Overview
      • Input Endpoints

      • Protocol Acquisition

      • Time-Series Database

      • 控制

        • Control Timer
        • Control Watchdog
          • Configuration
          • Behavior
          • Relation Type
          • Example
          • Full Scenario: Host Link-Loss Protection
      • IoT Scenarios
    • Stream Processing

    • Service Discovery

    • file

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • Agent Framework

  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

  • StreamSQL

目录

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.
  • timeout reached with no message: the failsafe JSON is emitted via the Success chain.
  • 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. failsafe not configured); the message is sent to the Failure chain.

# 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": []
  }
}
1
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"}
    ]
  }
}
1
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/iotWrite writes ${msg.valve}/${msg.motor} to the device. On link-loss timeout the watchdog emits failsafe, 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

Edit this page on GitHub (opens new window)
Last Updated: 2026/07/29, 10:24:31
Control Timer
IoT Scenarios

← Control Timer IoT Scenarios→

Theme by Vdoing | Copyright © 2023-2026 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式