Iiot bridge

From tinh2/skills-hub-registry · View interactive version

Iiot bridge is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Generate a production-grade Industrial IoT protocol bridge — OPC UA ↔ MQTT Sparkplug B, Modbus → MQTT, or direct PLC (Rockwell/Siemens/Beckhoff) → cloud (AWS IoT Core / Azure IoT Hub / GCP IoT / self-hosted HiveMQ)..

How to use this skill

Skill file

Industrial IoT Bridge Generator

You generate a production-grade protocol bridge that moves plant-floor data into a modern broker / cloud platform with industrial standards (Sparkplug B, OPC UA, MQTT 5.0) and security (TLS, X.509 mutual auth, RBAC) built in from the start.

OT/IT integration is the #1 friction point in Industry 4.0 deployments — multiple SCADA hosts each requiring request/response gateways, manual config that grows linearly with device count. This skill outputs a publish-subscribe bridge that breaks that pattern.

============================================================

=== PRE-FLIGHT ===

============================================================

Gather and verify before generating:

Recovery:

============================================================

=== PHASE 1: TOPIC SCHEMA & NAMESPACE DESIGN ===

============================================================

Generate the topic schema based on Sparkplug B (the only widely-accepted industrial MQTT topic standard) OR the ISA-95 / Unified Namespace pattern if the user is going broader than Sparkplug.

Sparkplug B topic format (Eclipse Tahu spec):

spBv1.0/{group_id}/{message_type}/{edge_node_id}/{device_id}

Message types:
  NBIRTH — Edge node online (publishes ALL metric definitions)
  NDATA  — Edge node metric value update
  NDEATH — Edge node going offline (sent as LWT)
  DBIRTH — Device online (under an edge node)
  DDATA  — Device metric value update
  DDEATH — Device offline
  NCMD   — Inbound command to edge node
  DCMD   — Inbound command to device

ISA-95 / Unified Namespace pattern (for non-Sparkplug deployments):

{enterprise}/{site}/{area}/{line}/{cell}/{asset}/{metric}
e.g., acme/austin-plant/packaging/line-3/filler-2/torque

Reserve subtrees:
  .../events    — discrete state changes (Start, Stop, Alarm)
  .../alarms    — ISA-18.2 alarms
  .../commands  — write-back operations

Generate topics.yaml documenting the chosen schema. The schema is the contract for everything downstream — get it right at the start.

VALIDATION: All generated topics validate against the Sparkplug B spec OR the ISA-95 pattern, no special characters, no wildcards in publishers, ≤ 5 levels deep.

FALLBACK: If the user has an existing topic schema (legacy MQTT deployment), generate a translator layer rather than forcing migration.

============================================================

=== PHASE 2: BRIDGE CORE WITH SPARKPLUG LIFECYCLE ===

============================================================

Generate the bridge code. Default to Python (best industrial library support). Use Node only if user requests it.

Required dependencies:

Sparkplug B lifecycle implementation is non-negotiable:

# On startup:
1. Connect to broker with LWT = NDEATH topic (so broker auto-publishes our death)
2. Publish NBIRTH with ALL metric definitions and current values + bdSeq counter
3. For each device: publish DBIRTH with that device's metrics
4. Then start publishing DDATA on change

# On metric value change:
1. Increment seq number (0-255, wraps)
2. Publish DDATA with only the changed metrics (publish-on-change, NOT poll)

# On graceful shutdown:
1. Publish DDEATH for each device
2. Publish NDEATH for the edge node
3. Disconnect cleanly

# On broker reconnect:
1. Repeat NBIRTH/DBIRTH (consumers need fresh schema after death/birth)
2. Reset seq counter
3. Increment bdSeq (birth/death sequence — top-level continuity)

Common bugs to PREVENT by construction:

VALIDATION: Run the bridge against a local HiveMQ + Sparkplug B Inspector (or Chariot Edge); confirm NBIRTH appears, DDATA flows, and DDEATH publishes on graceful shutdown. Pull the network cable and verify NDEATH appears via LWT.

FALLBACK: If Sparkplug B is overkill for the use case, generate plain MQTT with the ISA-95 topic schema — but emit a warning that interop with industrial consumers (Ignition, HiveMQ Distributed Tracing) will be limited.

============================================================

=== PHASE 3: SECURITY & CERTIFICATE PROVISIONING ===

============================================================

Generate the security stack. Defaults that ship to production:

Generate security/:

security/
├── ca/
│   ├── generate_ca.sh           # one-time root CA generation
│   └── sign_client.sh           # per-edge-node cert signing
├── certs/
│   └── .gitignore               # certs NEVER committed
├── broker_acl.yaml              # HiveMQ/EMQX ACL
└── README.md                    # rotation runbook

VALIDATION: Bridge fails closed if cert is missing or expired (does NOT silently fall back to plaintext). ACL prevents an edge node from publishing under another node's topic prefix.

FALLBACK: For air-gapped OT networks with no PKI, generate a PSK-based config — but mark explicitly as "lab/PoC only".

============================================================

=== PHASE 4: STORE-AND-FORWARD BUFFERING ===

============================================================

OT networks drop. Bridges that don't buffer lose data. Generate a persistent queue (SQLite or RocksDB) that:

  1. Writes every outbound message to disk before publishing.
  2. On broker disconnect, accumulates messages.
  3. On reconnect, drains the queue in order, respecting the original timestamps (not the replay time).
  4. Has a configurable retention cap (default 7 days) and overflow policy (drop-oldest with a logged warning).

This is the difference between a hobby script and a production bridge.

VALIDATION: Test by killing the broker for 60 seconds and confirming all messages arrive in order after reconnect with original timestamps preserved.

============================================================

=== PHASE 5: DOCKER-COMPOSE TEST RIG ===

============================================================

Generate docker-compose.yml so the entire stack runs locally for testing:

services:
  hivemq:
    image: hivemq/hivemq4:latest
    ports: ["1883:1883", "8883:8883", "8080:8080"]
    volumes: [./security/certs:/opt/hivemq/conf/certs:ro]

  modbus-sim: # mock PLC for testing
    image: oitc/modbus-server:latest

  opcua-sim:
    image: opensimroot/opcua-server:latest

  sparkplug-inspector:
    image: cirruslink/sparkplug-inspector:latest
    ports: ["3000:3000"]

  bridge:
    build: .
    environment:
      - MQTT_HOST=hivemq
      - SOURCE_TYPE=opcua
      - SOURCE_ENDPOINT=opc.tcp://opcua-sim:4840

VALIDATION: docker-compose up brings up the full stack; Sparkplug Inspector at localhost:3000 shows the bridge's NBIRTH/DDATA flow within 30 seconds.

============================================================

=== PHASE 6: OBSERVABILITY ===

============================================================

Generate basic observability so failures don't hide:

VALIDATION: Scrape /metrics and confirm at least messages_published_total increments after a source change.

============================================================

=== SELF-REVIEW ===

============================================================

Score 1–5:

Most common failure: forgetting to re-publish NBIRTH after reconnect → consumers see ghost edge nodes. Verify explicitly.

============================================================

=== LEARNINGS CAPTURE ===

============================================================

Append to ~/.claude/skills/iiot-bridge/LEARNINGS.md:

<YYYY-MM-DD> — <source → destination, e.g., "OPC UA → HiveMQ Sparkplug B">

============================================================

=== STRICT RULES ===

============================================================

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.