How to Build an OPC UA SCADA Gateway Agent with OpenClaw on Raspberry Pi
An OPC UA SCADA gateway agent runs OpenClaw on a Raspberry Pi to bridge industrial control systems with AI-powered monitoring. This guide walks through the full setup, from installing python-opcua and configuring OpenClaw to connecting PLCs and building natural-language alert workflows. You get a low-cost, always-on gateway that translates raw sensor data into actionable reports.
What This Architecture Looks Like
The idea is straightforward: a Raspberry Pi sits between your industrial equipment and your network, running two layers of software. The first layer is an OPC UA client (or server) built with python-opcua, which speaks the standard protocol that PLCs, HMIs, and SCADA systems already understand. The second layer is OpenClaw, an open-source AI agent framework that can read data, run shell commands, interact with APIs, and respond in natural language.
Together, these layers create a gateway that does more than pass data packets. It can watch for anomalies, summarize equipment status in plain English, and trigger alerts when readings fall outside expected ranges. Traditional SCADA gateways require dedicated industrial hardware that costs thousands of dollars. A Raspberry Pi 5 with an 8GB RAM configuration runs this entire stack for under $100 in hardware.
OPC UA (Open Platform Communications Unified Architecture) is the IEC 62541 standard for industrial communication. It replaced the older OPC Classic protocol and added cross-platform support, built-in security with encryption and authentication, and the ability to model complex data structures. The industrial IoT gateway market is projected to reach $2.6 billion by 2027, driven largely by the need to connect legacy equipment to modern monitoring systems.
This guide covers the full path from bare hardware to a working gateway agent. You will install the OS, set up python-opcua, deploy OpenClaw, connect the two layers, and configure alert workflows that pipe results into a persistent workspace for team review.
What to check before scaling openclaw raspberry pi opc ua scada industrial gateway agent
Before you start, gather the hardware and verify your network environment.
Hardware:
- Raspberry Pi 5 (4GB or 8GB RAM). A Pi 4 with 8GB works but runs roughly 2x slower for agent orchestration tasks.
- USB SSD (32GB or larger). SD cards work for initial testing, but the frequent small reads and writes from both OPC UA polling and OpenClaw operations degrade SD card lifespan quickly.
- Official 5V 5A USB-C power supply for Pi 5 (5V 3A for Pi 4).
- Ethernet cable for reliable connectivity to your industrial network. WiFi adds latency and drops that you do not want on a SCADA link.
Network environment:
- Access to your PLC or SCADA server's OPC UA endpoint (typically a URL like
opc.tcp://192.168.1.100:4840). - Firewall rules that allow OPC UA traffic between the Pi and your control system.
- Outbound internet access for OpenClaw's LLM API calls (OpenAI, Claude, or another provider).
Software you will install:
- Raspberry Pi OS Lite (64-bit). The desktop environment wastes RAM that the agent stack needs.
- Node.js 24 (required by OpenClaw).
- Python 3.11+ with pip (for python-opcua).
- OpenClaw agent framework.
If your control environment is air-gapped, you can pre-download packages on another machine and transfer them via USB. OpenClaw itself needs internet access only for LLM API calls, so you could route those through a controlled proxy.
Installing python-opcua on Raspberry Pi
Start with a fresh Raspberry Pi OS Lite (64-bit) installation. Use Raspberry Pi Imager to flash the image, and pre-configure your hostname, SSH credentials, and network settings during the imaging step so you can work headless from the start.
Update the system and install Python dependencies:
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-pip python3-venv git curl build-essential
Create a virtual environment for your OPC UA code to keep dependencies isolated:
python3 -m venv ~/opcua-env
source ~/opcua-env/bin/activate
pip install opcua
The python-opcua library is a pure Python implementation of the OPC UA specification. It supports both client and server modes, runs on ARM without compiled dependencies, and handles the full OPC UA address space. One important performance detail: on a Raspberry Pi, the initial address-space XML parsing can take over two minutes. The library supports a cache file that reduces subsequent startups to a few seconds:
from opcua import Server
server = Server(shelffile="opcua_cache")
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
For a gateway scenario, you will typically run a client that connects to your existing PLC's OPC UA server and reads tag values. Here is a minimal client that connects and reads a temperature node:
from opcua import Client
client = Client("opc.tcp://192.168.1.100:4840")
client.connect()
temp_node = client.get_node("ns=2;i=3")
temperature = temp_node.get_value()
print(f"Current temperature: {temperature}")
client.disconnect()
Replace the node ID (ns=2;i=3) with the actual node address from your PLC's address space. Most SCADA systems provide a node browser or export file that lists available tags.
Give Your Gateway Agent a Workspace
Store industrial logs, AI-generated reports, and equipment health summaries in a persistent workspace your whole team can search. 50GB free storage, no credit card, and an MCP server your agents can talk to directly. Built for openclaw raspberry opc scada industrial gateway agent workflows.
Setting Up OpenClaw as the Agent Layer
With python-opcua handling the industrial protocol, the next step is installing OpenClaw to add reasoning and alerting capabilities. OpenClaw is an open-source AI agent framework that runs locally, connects to cloud LLM providers for inference, and uses a skills system to extend its capabilities.
Install Node.js 24 and OpenClaw:
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt install -y nodejs
curl -fsSL https://openclaw.ai/install.sh | bash
openclaw onboard --install-daemon
The --install-daemon flag registers OpenClaw as a systemd service so it starts automatically on boot. Verify the installation:
openclaw status
systemctl --user status openclaw-gateway.service
Performance tuning for Pi deployments:
- Reduce GPU memory allocation by adding
gpu_mem=16to/boot/firmware/config.txt. The gateway does not need graphics processing. - If running on a 2GB Pi, configure 2GB of swap space and set swappiness to 10 to avoid thrashing.
- Enable Node.js compile cache for faster CLI startup times.
- Disable Bluetooth and other unused services to free resources.
OpenClaw does not run LLM inference locally. It sends prompts to your configured provider (OpenAI, Anthropic, or others) and processes the responses. This means the Pi's limited compute is spent on orchestration and OPC UA polling, not on model weights. The LLM API key is configured during the openclaw onboard step.
Bridging OPC UA Data into OpenClaw Workflows
The core integration is a Python script that polls OPC UA nodes and feeds the readings to OpenClaw for analysis. There are several architectural approaches depending on your monitoring requirements.
Approach 1: File-based data bridge. Write OPC UA readings to a JSON or CSV file on disk. Configure an OpenClaw skill to watch that file and analyze new entries. This is the simplest approach and keeps the OPC UA client and the agent loosely coupled.
Approach 2: Shell command integration. OpenClaw can execute shell commands directly. Create a Python script that reads OPC UA values and prints them to stdout, then call that script from within an OpenClaw conversation. The agent receives the raw data and can reason about it immediately.
Approach 3: Webhook-triggered analysis. Run a lightweight HTTP server alongside your OPC UA client. When readings cross a threshold, POST the data to OpenClaw's local endpoint for processing.
For most industrial monitoring setups, the file-based approach works well because it provides a persistent record of readings and decouples the polling frequency from the agent's analysis cycle. Your OPC UA client can poll every second while OpenClaw analyzes aggregated data every five minutes.
Here is an example polling script that writes readings to a JSON log:
import json
import time
from datetime import datetime
from opcua import Client
client = Client("opc.tcp://192.168.1.100:4840")
client.connect()
nodes = {
"temperature": client.get_node("ns=2;i=3"),
"pressure": client.get_node("ns=2;i=4"),
"flow_rate": client.get_node("ns=2;i=5")
}
while True:
reading = {
"timestamp": datetime.utcnow().isoformat(),
"values": {k: v.get_value() for k, v in nodes.items()}
}
with open("/home/pi/opcua_readings.json", "a") as f:
f.write(json.dumps(reading) + "
")
time.sleep(1)
With readings accumulating in a file, you can instruct OpenClaw to analyze trends, detect anomalies, and generate summaries. The agent reads the file, applies reasoning through its LLM provider, and outputs natural-language reports. Instead of staring at raw tag values, your operations team gets alerts like "Compressor 3 outlet pressure has been trending 12% above baseline for the last 30 minutes. Check the discharge valve."
Why this matters for operations teams: Traditional SCADA alerting uses fixed thresholds. The AI layer adds contextual reasoning. It can correlate multiple sensor readings, account for time-of-day patterns, and explain what the data means rather than just flagging that a number exceeded a limit.
Storing Logs and Reports in a Persistent Workspace
Raw OPC UA readings and AI-generated reports accumulate fast. A Pi running 24/7 can generate gigabytes of log data per month. You need a storage strategy that keeps data accessible for review without filling up the Pi's limited disk.
Local storage works for short-term buffering, but for long-term retention and team access, you want a cloud workspace. Several options exist:
- S3 or MinIO: Good for raw log archival. Cheap per-gigabyte, but no built-in search or AI capabilities.
- Google Drive or Dropbox: Familiar interfaces, but not designed for programmatic agent workflows.
- Fast.io: An intelligent workspace designed for agent-to-human handoff. Upload logs and reports through the API or MCP server, and the platform auto-indexes files for semantic search.
Fast.io fits this use case well because of how it handles the agent-to-human workflow. Your OpenClaw agent generates a daily equipment health report, uploads it to a shared workspace, and your maintenance team reviews it through the web UI without needing SSH access to the Pi. The Intelligence Mode auto-indexes uploaded documents, so team members can ask questions like "What was the average compressor temperature last week?" and get answers with citations pointing to the specific report files.
The free agent plan includes 50GB of storage, 5,000 API credits per month, and 5 workspaces with no credit card required. For a single gateway generating daily reports, that is more than enough capacity. If you are running multiple Pis across a facility, each one can upload to the same workspace, giving your operations team a unified view.
The Fast.io MCP server exposes workspace, storage, AI, and workflow tools through Streamable HTTP at /mcp. Agents that support MCP can interact with Fast.io directly. For OpenClaw specifically, you can write a skill or use a shell script to call the Fast.io API for uploads:
curl -X POST https://api.fast.io/blob \
-H "Authorization: Bearer $FASTIO_TOKEN" \
-F "file=@/home/pi/reports/daily_report_2026-04-13.pdf" \
-F "workspace=scada-gateway-logs"
This approach keeps your Pi lean (only buffering the most recent data locally) while maintaining a complete, searchable archive that your whole team can access. When a maintenance engineer needs to investigate an incident, they search the workspace instead of SSH-ing into a Pi in a factory closet.
OPC UA vs Modbus for Industrial IoT Gateways
If you are building your first industrial gateway, you may be weighing OPC UA against Modbus. Both protocols connect controllers and sensors to higher-level systems, but they serve different design eras and requirements.
Modbus was developed in 1979 by Modicon for PLC communication. Modbus TCP adapts the original serial protocol to Ethernet. It is simple, widely supported, and easy to implement. Data consists of numeric registers with no semantic context. A register at address 40001 is just a number. Your application has to know what that number means.
OPC UA is the IEC 62541 standard designed for Industry 4.0 interoperability. It provides:
- Built-in security with encryption and certificate-based authentication
- Rich data modeling with semantic context (a temperature reading carries its units, range, and engineering description)
- Cross-platform support (runs on Linux, Windows, embedded systems)
- Discovery and browsing (clients can explore the address space without prior configuration)
For an AI gateway agent, OPC UA has a clear advantage: the semantic data model gives the LLM context that Modbus cannot provide. When OpenClaw reads an OPC UA node, it gets not just a value but metadata about what that value represents, what its normal range is, and how it relates to other nodes. This context makes the agent's analysis more accurate without requiring extensive prompt engineering to explain every tag.
That said, many facilities run Modbus on their older equipment. You can run both protocols on the same Pi. Use python-opcua for OPC UA devices and pymodbus for Modbus TCP/RTU devices, then feed both data streams into your OpenClaw analysis pipeline. The AI layer does not care where the data originated, only what it means.
Frequently Asked Questions
Can Raspberry Pi run an OPC UA server?
Yes. The python-opcua library provides a full OPC UA client and server implementation that runs on Raspberry Pi's ARM architecture. A Pi 5 with 4GB RAM handles both client and server roles comfortably. Use the shelf cache option to reduce startup time from over two minutes to a few seconds on subsequent launches.
How do you connect a Raspberry Pi to SCADA systems?
Install python-opcua and configure it as a client that connects to your SCADA server's OPC UA endpoint. You need the server's address (typically opc.tcp://IP:4840), and the node IDs for the tags you want to read. Ensure network firewall rules allow OPC UA traffic between the Pi and the SCADA server.
What is OPC UA vs Modbus for industrial IoT?
OPC UA is a modern IEC 62541 standard with built-in security, semantic data modeling, and cross-platform support. Modbus is a simpler 1979-era protocol that transmits raw numeric registers without context. OPC UA is better for new deployments and AI integration because its data model carries metadata. Modbus remains common on legacy equipment and is easier to implement for basic register reads.
Does OpenClaw run on Raspberry Pi?
OpenClaw runs on Raspberry Pi 4 (8GB recommended) and Pi 5 (4GB or 8GB). It requires 64-bit Raspberry Pi OS and Node.js 24. The agent itself handles orchestration while sending inference requests to cloud LLM providers, so the Pi's limited compute is not a bottleneck. Install via the official script at openclaw.ai/install.sh.
How much does a Raspberry Pi SCADA gateway cost to run?
Hardware costs are under $100 for a Pi 5 with SSD and power supply. Electricity runs about published pricing for 24/7 operation. LLM API costs depend on your analysis frequency, but polling every 5 minutes with a summarization prompt typically costs $5-15 per month with most providers. Compare this to dedicated industrial gateways that start at $500-2,000 for the hardware alone.
Related Resources
Give Your Gateway Agent a Workspace
Store industrial logs, AI-generated reports, and equipment health summaries in a persistent workspace your whole team can search. 50GB free storage, no credit card, and an MCP server your agents can talk to directly. Built for openclaw raspberry opc scada industrial gateway agent workflows.