Bot TutorialsGrok BotChatGPTClaudeGeminiCopilotPerplexityMore botsGuidesArticlesPapersIndustrialSearch

Read OPC UA tags securely with a bot

OPC UA, unlike Modbus, has built-in security: certificates, encryption and user roles. Use all of it.

1. Ask for a read-only identity

Have the server owner create a user (or certificate identity) whose role can browse and read only the needed nodes. No write, no method calls, no history update.

2. Require SignAndEncrypt

Connect with security policy Basic256Sha256 (or a newer policy your server supports) and mode SignAndEncrypt. Refuse None. Add the bot's client certificate to the server's trust list and the server's certificate to yours.

openssl req -x509 -newkey rsa:2048 -nodes -days 365 \
  -keyout bot-key.pem -out bot-cert.pem \
  -subj "/CN=ops-bot" -addext "subjectAltName=URI:urn:site:ops-bot"

3. Read tags with Python (asyncua)

Install asyncua from your offline wheel cache:

import asyncio, os
from asyncua import Client

URL = "opc.tcp://scada01.ops.local:4840"
NODES = ["ns=2;s=Line1.Filler.Speed", "ns=2;s=Line1.Filler.RejectCount"]

async def main():
    c = Client(URL)
    await c.set_security_string(
        "Basic256Sha256,SignAndEncrypt,bot-cert.pem,bot-key.pem,server-cert.pem")
    c.set_user("ops-bot-ro")
    c.set_password(os.environ["OPCUA_RO_PASSWORD"])   # never hard-code it
    async with c:
        for n in NODES:
            node = c.get_node(n)
            print(n, await node.read_value())

asyncio.run(main())

4. Browse instead of guessing node IDs

Use a GUI client or asyncua's browse functions to export the node list once, review it with the controls engineer, and give the bot only that allow-list.

5. Check that writes really fail

On a test server, confirm the account gets BadUserAccessDenied on a write. Record the result in your validation notes. Never perform this test on production.

Questions

Is OPC UA safe by default?

Only if configured: many servers ship allowing security mode None or anonymous access. Turn those off for any bot connection.

Where these facts come from

Checked Oct 29, 2026. Tutorials are educational. Follow your site's safety procedures, management-of-change process and the equipment maker's manual. Never test against live production equipment without authorization.

Industrial control with bots: all lessons → Next: 6. Bot-written shift reports and alarm summaries →

Related: 1. Ground rules: what a bot may and may not do in OT2. Run a local LLM on an air-gapped Linux box3. Sneakernet: move models and updates across the gap safely4. Read Modbus TCP data with a bot (read-only)5. Read OPC UA tags securely with a bot6. Bot-written shift reports and alarm summaries7. Audit logs that a bot cannot rewrite8. Human-in-the-loop: approval gates before anything movesCan AI control a PLC?Run AI offline on LinuxGuidesScripts & templates