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
| Setting | Default | Meaning |
|---|---|---|
| Enabled | off | Nothing is exposed until this is on. |
| Protocol | HTTP (ws://) | HTTPS gives wss://. Without a certificate file, a self-signed certificate is created in data/gateway/. |
| Listen on | 0.0.0.0 | All network cards; 127.0.0.1 for this computer only; or one IP address. |
| Port | 5090 | Must differ from the web UI port. |
| Path | /data | Clients connect to ws://host:5090/data. |
| Publish interval | 250 ms | How often changes are pushed. Only each tag's latest value is sent. |
| Max clients | 50 | Further connections get HTTP 503. |
| Access without a key | off | When on, clients without a key may read the public tag patterns. |
| Allowed browser origins | any | Restricts which web pages may connect from a browser. |
| API keys | none | One 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 tagPlant/Line1/*/Speed:*matches any text inside one levelPlant/**:**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 code | Meaning |
|---|---|
4401 | Missing, unknown or disabled API key |
4403 | Browser origin not allowed |
1013 | Too 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
| Request | Reply |
|---|---|
{ "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.