← Back to Blog

How to Run an AI IoT & MQTT Agent with OE Runtime

Subscribe to sensor feeds and publish commands to IoT devices via MQTT. OE Runtime lets you run a local AI agent that monitors device data, evaluates thresholds, and publishes automated responses — no IoT platform subscription required.

📡
Step 1
Read Sensor Data
Subscribe to the sensor topic and read the latest 5 messages with device ID, value, unit, and timestamp.
Step 2
Evaluate & Publish Command
Analyse readings against thresholds and publish the appropriate control command as a JSON payload.
Step 3
Report
Summarise sensor readings, threshold breaches, commands published, and current system status.

The Agent YAML

Create a file called agent.yaml inside an iot-messaging/ directory:

name: IoT Agent
description: Publish commands and read sensor data via MQTT
instructions: |
  You are an IoT agent. Subscribe to sensor data feeds and publish commands to devices via MQTT.
  Format all messages as JSON. Always read current state before publishing any commands.
  Complete all steps fully before writing your report.
steps:
  - name: Read Sensor Data
    content: |
      Subscribe to the sensor data topic and read the latest 5 messages.
      Extract: device ID, sensor type, value, unit, and timestamp for each message.
  - name: Evaluate and Publish Command
    content: |
      Analyze the sensor readings:
      - If any temperature reading exceeds 30°C, publish a cooling command to the control topic
      - If any humidity reading exceeds 80%, publish a ventilation command
      - Otherwise publish a status check ping to the control topic
      All commands must be JSON with fields: action, device_id, timestamp, triggered_by.
  - name: Report
    content: |
      Summarize IoT activity:
      - Sensor readings received (device, value, unit)
      - Any threshold breaches detected
      - Commands published (topic, payload)
      - Current system status (normal / alert)
connectors:
  - connection_name: MQTT Broker
    connection_type: mqtt

The Config File

Create oe-config.json in the same directory:

{
  "llm": {
    "provider": "openai",
    "model": "gpt-4o",
    "apiKey": "YOUR_OPENAI_API_KEY"
  },
  "server": {
    "enabled": false,
    "port": 3333,
    "apiKey": "your-secret-api-key"
  },
  "connectors": [
    {
      "connection_name": "MQTT Broker",
      "connection_type": "mqtt",
      "broker": "mqtt://localhost:1883",
      "clientId": "oe-runtime",
      "topic": "devices/#",
      "username": "YOUR_MQTT_USER",
      "password": "YOUR_MQTT_PASSWORD"
    }
  ]
}

Replace the broker URL with your MQTT broker address. This works with any MQTT broker including Mosquitto, HiveMQ, AWS IoT Core, and Azure IoT Hub. Remove username/password fields if your broker does not require authentication.

Download OE Runtime

OE Runtime — Direct Downloads

Run the Agent

Windows

# Run the agent
oe-runtime-win.exe iot-messaging/agent.yaml --config iot-messaging/oe-config.json

macOS

# Make executable (first time only)
chmod +x oe-runtime-macos

# Run the agent
oe-runtime-macos iot-messaging/agent.yaml --config iot-messaging/oe-config.json

Linux

# Make executable (first time only)
chmod +x oe-runtime-linux

# Run the agent
oe-runtime-linux iot-messaging/agent.yaml --config iot-messaging/oe-config.json

macOS Gatekeeper: On first run, macOS may block the binary. Go to System Settings → Privacy & Security → click "Allow Anyway" next to oe-runtime-macos.

Running as an API Server

Add --serve to start OE Runtime as an HTTP server on port 3333:

oe-runtime-win.exe --serve --config iot-messaging/oe-config.json

Then send a request:

curl -X POST http://localhost:3333/run \
  -H "Content-Type: application/json" \
  -d '{"yaml": "iot-messaging/agent.yaml", "params": {}}'

Or import the Postman collection (download above) to test all endpoints visually.

Use Cases

Build your own agents with OE Runtime

Download OE Runtime and run any AI agent locally or as a server — no cloud required.

Get OE Runtime →