Skip to main content

WebSocket API reference

Third-party applications (SCADA, dashboards, MES, historians, scripts) read live tag values from WiConnector, and optionally write them, over a WebSocket. The service runs on its own port, separate from the web UI. Turn it on and configure it on the Services page.

Settings​

SettingDefaultMeaning
EnabledoffNothing is exposed until this is on.
ProtocolHTTP (ws://)HTTPS gives wss://. Without a certificate file, a self-signed certificate is created in data/gateway/.
Listen on0.0.0.0All network cards; 127.0.0.1 for this computer only; or one IP address.
Port5090Must differ from the web UI port.
Path/dataClients connect to ws://host:5090/data.
Publish interval250 msHow often changes are pushed. Only each tag's latest value is sent.
Max clients50Further connections get HTTP 503.
Access without a keyoffWhen on, clients without a key may read the public tag patterns.
Allowed browser originsanyRestricts which web pages may connect from a browser.
API keysnoneOne per application: name, tag patterns it can read, and whether it can write.

Settings live in data/gateway/websocket.json. Only a SHA-256 hash of each API key is stored: the key is shown once, when it is created.

Tag patterns​

One pattern per line, case-insensitive, / between levels:

  • Plant/Line1/Pump1/Speed: one tag
  • Plant/Line1/*/Speed: * matches any text inside one level
  • Plant/**: ** matches any number of levels (everything under Plant)
  • !**/Setpoint: a leading ! excludes; excludes win

A key sees the tags its patterns match. Writes also need the key's Can write option and the tag's Client access set to Read and write.

Connecting​

Send the API key in one of:

  • Authorization: Bearer wic_…
  • X-Api-Key: wic_…
  • ?key=wic_… in the URL (browsers cannot set WebSocket headers)

A refused client still connects, then receives one message saying why and is closed with a matching code:

{ "type": "error", "code": 4401, "error": "An API key is required. Add ?key=wic_... to the URL, or send an Authorization: Bearer header." }
Close codeMeaning
4401Missing, unknown or disabled API key
4403Browser origin not allowed
1013Too many clients, try again later

The close frame carries the same reason text, so WebSocket test tools show it instead of a bare "1006".

Messages​

Every message is one JSON object in a text frame, with a type. Requests may carry an id (any JSON value); the reply echoes it.

From the server​

{ "type": "welcome", "client": "scada", "allowWrite": false, "tags": 120, "publishIntervalMs": 250 }

Sent once on connect. tags is how many tags this client can see.

{ "type": "data", "values": [
{ "path": "Plant/Line1/Pump1/Speed", "value": 1184.2, "quality": "good", "timestamp": "2026-11-24T10:15:02.120+05:30", "units": "rpm" },
{ "path": "Plant/Line1/Tank1/Level", "value": null, "quality": "bad", "reason": "CommFailure", "timestamp": "…" }
] }

Current values right after subscribe, then changes every publish interval. quality is good, uncertain or bad; reason is set when it is not good.

{ "type": "tagsChanged", "subscribed": 42 }

Tags were added, removed or renamed. Subscriptions are re-applied automatically; send browse to refresh your list.

From the client​

RequestReply
{ "type": "browse", "id": 1, "tags": ["Plant/**"] } (tags optional){ "type": "browse", "id": 1, "tags": [ { "path", "dataType", "units", "description", "writable" } ] }
{ "type": "subscribe", "id": 2, "tags": ["Plant/Line1/**"] }{ "type": "subscribed", "id": 2, "count": 8 }, then data
{ "type": "unsubscribe", "id": 3, "tags": ["Plant/Line1/**"] } (no tags: all){ "type": "unsubscribed", "id": 3, "count": 0 }
{ "type": "read", "id": 4, "tags": ["Plant/**/Speed"] }{ "type": "read", "id": 4, "values": [ … ] } (one-off, no subscription)
{ "type": "write", "id": 5, "path": "Plant/Line1/Pump1/Setpoint", "value": 1500 }{ "type": "write", "id": 5, "ok": true } or { …, "ok": false, "error": "Tag is read-only." }
{ "type": "ping", "id": 6 }{ "type": "pong", "id": 6, "time": "…" }

Anything else gets { "type": "error", "id": …, "error": "…" }. Messages over 64 KB close the connection.

Values are in engineering units (after scaling). Writes take engineering units too and are scaled back to raw.

Example (browser or Node.js 22+)​

const ws = new WebSocket("ws://wiconnector-pc:5090/data?key=wic_...");
ws.onopen = () => ws.send(JSON.stringify({ type: "subscribe", id: 1, tags: ["Plant/**"] }));
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.type === "data") for (const v of msg.values) console.log(v.path, v.value, v.quality);
};

Example (Python, websockets package)​

import asyncio, json, websockets

async def main():
async with websockets.connect("ws://wiconnector-pc:5090/data",
additional_headers={"Authorization": "Bearer wic_..."}) as ws:
await ws.send(json.dumps({"type": "subscribe", "id": 1, "tags": ["Plant/**"]}))
async for raw in ws:
msg = json.loads(raw)
if msg["type"] == "data":
for v in msg["values"]:
print(v["path"], v["value"], v["quality"])

asyncio.run(main())

Connections, refusals and writes are logged under Logs → Communication, source WebSocket.