Skip to content

Instantly share code, notes, and snippets.

@id
Created April 30, 2026 14:44
Show Gist options
  • Select an option

  • Save id/bd338903fd33ac380289048b4e1961a3 to your computer and use it in GitHub Desktop.

Select an option

Save id/bd338903fd33ac380289048b4e1961a3 to your computer and use it in GitHub Desktop.
Provisioning a Neuron via REST API

A fresh EMQX Neuron 3.x instance configured from zero into a running south driver → north app → eKuiper rule pipeline, using only the REST API. Tested against emqx/neuronex:latest (3.8.1).

Pattern: each call returns {"error": 0} on success. API surfaces: — /api/... is EMQX Neuron system configuration (login, license, system),

  • /api/neuron/... is the embedded Neuron (nodes, groups, tags, subscribe)
  • /api/ekuiper/... is the embedded eKuiper (streams, rules).
# 0. Authenticate. Default credentials are admin / 0000 — change before exposing the dashboard.
TOKEN=$(curl -sS -X POST http://localhost:8085/api/login \
  -H 'Content-Type: application/json' \
  -d '{"name":"admin","pass":"0000"}' | jq -r .token)

# 1. South: add a Modbus TCP driver node and configure it.
curl -sS -X POST http://localhost:8085/api/neuron/node \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"name":"demo-modbus","plugin":"Modbus TCP"}'

curl -sS -X POST http://localhost:8085/api/neuron/node/setting \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{
    "node": "demo-modbus",
    "params": {
      "host": "192.0.2.10", "port": 502,
      "timeout": 3000, "interval": 20,
      "connection_mode": 0, "transport_mode": 0
    }
  }'

# 2. Tags. Posting tags auto-creates the group at the default 100 ms poll interval; a follow-up PUT changes it.
curl -sS -X POST http://localhost:8085/api/neuron/tags \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{
    "node": "demo-modbus", "group": "demo-group",
    "tags": [
      {"name":"holding-1","address":"1!400001","attribute":1,"type":3}
    ]
  }'

curl -sS -X PUT http://localhost:8085/api/neuron/group \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"node":"demo-modbus","group":"demo-group","interval":1000}'

# 3. North: add an MQTT app node and configure it to point at the broker.
curl -sS -X POST http://localhost:8085/api/neuron/node \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"name":"demo-mqtt","plugin":"MQTT"}'

curl -sS -X POST http://localhost:8085/api/neuron/node/setting \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{
    "node": "demo-mqtt",
    "params": {
      "client-id": "demo-neuron",
      "host": "emqx", "port": 1883,
      "username": "", "password": "",
      "ssl": false, "qos": 1, "version": 5, "format": 0,
      "cache": false, "cache-mem-size": 0, "cache-disk-size": 0,
      "cache-sync-interval": 100,
      "write-req-topic":  "/demo/write/req",
      "write-resp-topic": "/demo/write/resp"
    }
  }'

# 4. Wire the app to the driver/group with a publish topic.
curl -sS -X POST http://localhost:8085/api/neuron/subscribe \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{
    "app": "demo-mqtt",
    "driver": "demo-modbus",
    "group":  "demo-group",
    "params": { "topic": "/demo/data" }
  }'

# Nodes auto-start after configuration. To explicitly start/stop:
#   POST /api/neuron/node/ctl  body: {"node":"demo-modbus","cmd":0}   # 0=start, 1=stop

# 5. eKuiper rule. EMQX Neuron ships a built-in stream `neuronStream` whose
#    rows are every Neuron group read. Filter to this driver and forward
#    to a different MQTT topic.
curl -sS -X POST http://localhost:8085/api/ekuiper/rules \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "demo_rule",
    "sql": "SELECT node_name, group_name, values FROM neuronStream WHERE node_name = \"demo-modbus\"",
    "actions": [{
      "mqtt": {
        "server": "tcp://emqx:1883",
        "topic":  "/demo/ekuiper/out",
        "qos":    1,
        "sendSingle": true
      }
    }]
  }'

# 6. Verify.
curl -sS -H "Authorization: Bearer $TOKEN" \
  "http://localhost:8085/api/neuron/node/state?node=demo-modbus"   # running:3, link:0/1
curl -sS -H "Authorization: Bearer $TOKEN" \
  "http://localhost:8085/api/neuron/node/state?node=demo-mqtt"     # link:1 = MQTT connected
curl -sS -H "Authorization: Bearer $TOKEN" \
  http://localhost:8085/api/ekuiper/rules/demo_rule/status         # status:"running"

To tear it all back down:

curl -sS -X DELETE http://localhost:8085/api/ekuiper/rules/demo_rule \
  -H "Authorization: Bearer $TOKEN"
curl -sS -X DELETE http://localhost:8085/api/neuron/node \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"name":"demo-mqtt"}'
curl -sS -X DELETE http://localhost:8085/api/neuron/node \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"name":"demo-modbus"}'

Full API reference is served by each instance at http://<host>:<port>/api-docs/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment