Skip to content

RFID Device Socket.IO Protocol

This reference describes the Socket.IO connection used by networked RFID devices, including SmartBoards, fridges, and storage cabinets. It is intended for device-software developers implementing the backend client. The cabinet application can use this same protocol; it does not require a cabinet-specific Socket.IO server.

The backend currently authenticates device connections against Products.Units. Device software connects as the registered unit and reports stock/process state. DiamondTracker and DM-front initiate user actions through authenticated HTTP endpoints; the backend forwards the resulting commands to the connected device.

1. Register the unit

Create the device record in the Products database's Units collection before connecting. First authenticate a DiamondTracker user who belongs to the company that will own the unit. Send the user's username and password to POST /v2/auth/login:

curl --request POST "$BASE_URL/v2/auth/login" \
  --header 'Content-Type: application/json' \
  --data '{"username":"<operator-username>","password":"<operator-password>"}'

On success, the response contains a JWT in its token property. Use that token as a bearer token for registration. The owning company must have the Products_Endpoints license; this is checked against the company, not granted by the user token itself. The authenticated user's company is used as the unit's company when payload.company is omitted or empty.

Then create the unit with POST /v2/products/:

{
  "collection": "Units",
  "payload": {
    "serial_number": "CABINET-SERIAL",
    "company": "",
    "name": "",
    "location": "",
    "created": "2026-09-29T10:00:00Z",
    "password": "device-secret",
    "hardware": {
      "cameras_sn": [],
      "serials_sn": ["RFID-READER-SERIAL"]
    }
  }
}

Send the registration request with Authorization: Bearer <token> and Content-Type: application/json:

curl --request POST "$BASE_URL/v2/products/" \
  --header "Authorization: Bearer <token>" \
  --header 'Content-Type: application/json' \
  --data @unit-registration.json

The login endpoint returns 401 for invalid credentials. Registration returns 201 on creation; the backend hashes a supplied device password, and duplicate unit serials return 409. Store the generated device password securely; it is the device's credential for obtaining a Socket.IO token. The unit's serial_number is also its device login/Socket.IO identity. Do not reuse the operator's bearer token as the device credential.

Cabinet inventory/listing and connectivity routes already read from Products.Units; there is no separate cabinet registration collection in the current backend path. For cabinets already present only in a legacy collection, migrate or recreate each unit in Products.Units with a unique serial_number, correct company, working device credentials, and hardware metadata. Preserve any relevant name, location, capacity, and intake settings. The backend classifies device type from the serial prefix: known prefixes identify SmartBoard, SmartBox, SmartPad, and Drawer; other prefixes default to SmartCabinet. Avoid assigning a reserved prefix to a cabinet.

2. Authenticate and connect

Request a short-lived JWT using HTTP Basic authentication, with the unit serial as username and its registered password:

GET /socket/token
Authorization: Basic base64(serial-number:device-password)

The response contains a token string. Connect to the backend Socket.IO endpoint using Engine.IO v4 WebSocket transport and pass the token as a query parameter:

wss://<backend-host>/socket.io/?EIO=4&transport=websocket&token=<url-encoded-token>

Use https:// for the token request and wss:// for the WebSocket on production deployments. The standard Socket.IO/Engine.IO handshake must be completed; a raw WebSocket connection alone is not sufficient. The JavaRFID implementation uses Engine.IO open/connect packets and responds to server heartbeat pings. A C# client should use a Socket.IO-compatible client library where possible and enable reconnection with fresh token acquisition after authentication expiry.

After connection, the backend registers the device by the unit serial, emits Welcome, and marks it connected for the Devices page. Emit metadata on connect:

{
  "serial_number": "CABINET-SERIAL",
  "app_version": "1.2.3"
}

Event: device:metadata. The backend uses app_version for device status display. Keep the connection alive with the Engine.IO heartbeat mechanism. On disconnect, reconnect and authenticate again. The backend cancels pending scan requests when the device disconnects before completing them.

3. Stock scans

The primary flow is server-commanded scanning:

  1. A user requests a scan from DM-front or an API client. The backend verifies the device belongs to the company and is connected, then creates an action history record.
  2. The backend emits stock:get to the device with the action ID and timestamps, for example { "id": "<history-id>", "created_at": "...", "updated_at": "..." }.
  3. The device scans and emits one stock:put event per drawer/snapshot. Copy the command's id into each report's parent_id so the backend associates the result with the scan action.
  4. After all stock:put events, emit stock:scan_complete with the same parent_id. This signals that ingestion is complete and allows the backend to finalize the action/result.

stock:put payload fields used by the current JavaRFID client:

{
  "device_type": "SmartCabinet",
  "serial_num": "CABINET-SERIAL",
  "parent_id": "<history-id-or-empty-string>",
  "userid": "operator-name",
  "type": "BADGE",
  "authentication_type": "BADGE",
  "badge_number": "12345",
  "user_id": "user-id-or-null",
  "drawer": 0,
  "created_at": "2026-09-29T10:00:00Z",
  "added_tags": ["EPC-1"],
  "present_tags": ["EPC-1", "EPC-2"],
  "removed_tags": []
}

device_type should match the product (SmartCabinet for cabinets); serial_num must match the registered serial_number. Tags are RFID values. present_tags describes the complete current contents for the reported drawer, while added_tags and removed_tags describe the change. Use the actual authentication type and user/badge values when available; nullable identity fields may be null. parent_id is empty for unsolicited snapshots.

Completion payload:

{
  "parent_id": "<history-id>",
  "serial_num": "CABINET-SERIAL",
  "drawers": [0],
  "stock_put_count": 1,
  "created_at": "2026-09-29T10:00:00Z"
}

drawers lists the drawers included in the completed snapshot; stock_put_count is the number of stock:put events emitted for this scan. Wait for any local scan work and emit all snapshots before completion. The backend processes stock events asynchronously and serializes ingestion by scan/device; completion is the explicit end-of-scan marker.

Backend responses include stock:put_result with a status/message for each stock update. The backend also emits client:stock:get_accepted, client:stock:get_result, or client:stock:get_error when a client uses the Socket.IO client scan event client:stock:get; these are for the requesting app/client, not the RFID device.

4. Processes and pick-to-light

HTTP process creation/cancellation and device UI actions are mediated by the backend. A process targeting a device is delivered as processes:created; cancellation/deletion is delivered as processes:deleted. Apply these events to the device's local process/lighting state and stop any active guidance when the process is removed. Process events are company-wide broadcasts, so a device should act only on processes whose device or devices includes its own serial.

The device can request process synchronization after connecting or reconnecting. The processes:created event is also used to deliver an active process to a device. Backend process-update notifications use processes:updated; cabinet selection changes can emit processes:refresh with an empty object, meaning clients should fetch the current process snapshot again. Process event payloads may wrap their data in { "status": 200, "message": "", "result": [...] }; processes:get_result may instead be the process array directly. Parse according to the event and handle both successful and error-shaped responses.

Device emits Backend replies Purpose
processes:get processes:get_result Fetch current process state
processes:get_by_id with { "id": "..." } processes:get_result Fetch one process
processes:get_by_user with { "userId": "..." } processes:get_by_user_result Fetch processes for a user
processes:update with { "id": "...", "listOfTagPulled": [...] } processes:update_result Report process progress
processes:delete with { "id": "..." } processes:delete_result and broadcast processes:deleted Delete a process

The backend also accepts users:get, users:get_by_username with { "username": "..." }, and users:put for RFID device user/badge synchronization. users:get_by_username also responds on users:get_result. The users:put payload supports username, badge_num, finger_index, and ftemplate; its result is emitted as users:put_result. Company-wide user changes arrive as users:create, users:update, and users:delete. Devices that do not use backend-synchronized users need not implement this optional flow.

Compatibility note: the checked-out JavaRFID source currently emits process progress as { "id": "...", "status": "...", "current_tags": [...] }, but this backend's processes:update handler reads listOfTagPulled. A new client should follow the backend payload in the event table rather than infer the contract from that Java emitter. JavaRFID's legacy users:put emitter can also send permission and active, but the backend handler currently consumes only username, badge_num, finger_index, and ftemplate.

For the SmartBoard-style pick-to-light workflow, backend process records carry process id, status, type, tags, current_tags, and device target information. The device uses the active process and its current tags to illuminate/guide retrieval, then reports progress through processes:update. Stop guidance when a processes:deleted event arrives or the process becomes inactive. Cabinets should implement this behavior according to their physical indicator/door model; the backend protocol does not prescribe the cabinet's lighting hardware behavior.

5. Devices page and HTTP interface

DM-front's Devices page uses authenticated REST endpoints for listing devices, connection status, settings, and actions. The backend's /v2/devices list is backed by Products.Units; its connected and app_version values come from the Socket.IO registry. Scan actions are requested over HTTP and then delivered to the device as stock:get. Therefore the cabinet does not need a direct browser-to-device connection, and no cabinet-specific frontend registration workflow is required for the existing Devices page.

The cabinet add-on also retains authenticated /v2/cabinet/inventory/devices, history, and selection routes. Its inventory device list likewise reads Products.Units; these routes are compatibility/add-on endpoints rather than a separate device store.

6. Complete Socket.IO event reference

The server registers the device-side events below. Emit JSON as the Socket.IO event argument (not a JSON string nested inside another JSON string). Events marked optional support user synchronization or generic client utilities; they are not prerequisites for a cabinet to report stock and receive scans/processes.

Device to backend

Event Payload Backend response/effect
device:metadata { "serial_number": "...", "app_version": "..." } Updates the connected-device version metadata.
stock:put Stock snapshot described above. stock:put_result with { "message": "...", "status": 200 } on success; status 400 for rejected stock and 500 for internal failure.
stock:scan_complete Completion payload described above. Finalizes the matching scan action after queued stock ingestion completes. No separate acknowledgement event is emitted.
processes:get No payload. processes:get_result with the company's current process list.
processes:get_by_id { "id": "<process-id>" } processes:get_result with process data or an error object.
processes:get_by_user { "userId": "<user-id>" } processes:get_by_user_result with process data or an error object.
processes:update { "id": "<process-id>", "listOfTagPulled": ["<RFID>"] } processes:update_result with the update result. The backend removes these pulled RFID values from the process's current tags.
processes:delete { "id": "<process-id>" } processes:delete_result to the requester and processes:deleted broadcast to the company.
users:get (optional) No payload. users:get_result with users.
users:get_by_username (optional) { "username": "..." } users:get_result with the matching user.
users:put (optional) { "username": "...", "badge_num": "...", "finger_index": [...], "ftemplate": [...] } users:put_result with the update result.
messages:send (generic utility) { "text": "..." } Echo response on messages:send_result with { "from": "<username>", "text": "..." }. Not needed for device operation.

Backend to device

Event Payload Device behavior
Welcome Greeting string. Confirms the socket handler registered the connection.
stock:get { "id": "<history-id>", "created_at": "...", "updated_at": "..." } Scan and report snapshots with this id as parent_id, then emit stock:scan_complete.
stock:put_result { "message": "...", "status": 200\|400\|500 } Handle/report stock persistence result; correlate with emitted stock update if needed.
processes:get_result Current process array, or an error object for invalid/error cases. Replace or reconcile cached process state.
processes:get_by_user_result User process data or error object. Handle response to processes:get_by_user.
processes:update_result Process update result or error object. Handle progress update result.
processes:delete_result Process deletion result or error object. Handle request result; this is separate from the company-wide deletion event.
processes:created Process event object, typically wrapped in result: [...]. Add/update the process and apply device-specific guidance when targeted to this unit.
processes:deleted { "status": 200, "message": "deleted", "result": { "id": "..." } }. Remove the process and stop its guidance.
processes:updated { "status": 200, "message": "", "result": [{ "id": "...", "description": "..." }] }. Refresh or update the matching process.
processes:refresh Usually {}. Fetch/reconcile the process list; emitted by cabinet selection workflows after a selection changes.
pick_to_light:stop Action/history object containing id, created_at, and updated_at. Stop the active pick-to-light guidance for the unit.
config { "config": { ... } }; keys depend on the requested device configuration operation. Apply supported configuration updates.
users:get_result User list or user lookup result; malformed requests may return { "message": "...", "users": [], "status": 400 }. Replace or reconcile optional user cache.
users:put_result User update result or error object. Handle optional user update response.
users:create User change notification, commonly { "status": 200, "message": "User created", "result": [...] }. Add/update optional local user data.
users:update User change notification, commonly { "status": 200, "message": "User updated", "result": [...] }. Update optional local user data.
users:delete { "userIds": ["..."] }. Remove optional local user data by ID.
errors:authentication_invalid Authentication error object/message. Stop using the socket and obtain a fresh device token/verify unit credentials.
errors:authentication_no_token Authentication error object/message. Fix missing/invalid device token configuration before reconnecting.
errors:unknown_event Diagnostic string. Development-only response for an unrecognized event; do not rely on it in production.

Socket.IO lifecycle also includes Engine.IO open/connect, heartbeat ping/pong, disconnect, and reconnect handling. These are transport control packets, not application events. The server's authentication middleware can reject a connection as a Socket.IO connect_error; the named authentication error events above are emitted by applicable middleware paths when possible.

Client-only events

These events belong to authenticated web/app Socket.IO clients. They are not part of the RFID device's required contract, but are included here to make the shared Socket.IO namespace complete:

Direction Event Payload/result
Client to backend client:stock:get { "serialNumber": "<unit-serial>", "requestId": "<optional-correlation-id>" }; asks the backend to command the device to scan.
Backend to client client:stock:get_accepted Includes requestId, actionHistoryId, and serial_number once the request is accepted.
Backend to client client:stock:get_result Includes action ID, device, changed flag, stock history IDs, drawer-level tag changes, and matched inventory items after scan completion.
Backend to client client:stock:get_error Includes request/action IDs when known, device serial, and an error message; can result from invalid ownership, disconnected device, another pending scan, timeout, or disconnect.
Client to backend messages:send { "text": "..." }.
Backend to client messages:send_result { "from": "<username>", "text": "..." }.

errors:unknown_event is emitted only outside production when the server receives an event with no handler or audit configuration. Unknown events should be logged and ignored by device clients; the server does not provide a production acknowledgement for arbitrary event names.