Smart Site
Home Docs Smart Data Device Management

Device Management

The Device module is the operational hub of Smart SCADA. It manages device records, device groups, device-to-tag bindings, online status, and bulk import/export. All endpoints are scoped by project: /api/v1/projects/:projectId/devices.

Interface Screenshot

Device Management (English UI)

Captured from the live Smart Site system with the English UI. See the zh-CN counterpart for the Chinese-UI screenshot.

1. Core Concepts

  • Device — A physical or virtual unit (PLC, RTU, gateway, sensor) that exposes one or more data tags
  • Device Group — A tree node used to organize devices; supports drag-and-drop sorting
  • Data Tag — A single readable/writable point on a device (e.g. temperature, status bit)
  • Online Status — Derived from collector heartbeat and last successful read

2. Functional Areas

2.1 Device CRUD

Operation Endpoint
List GET /api/v1/projects/:projectId/devices
Detail GET /api/v1/projects/:projectId/devices/:id
Create POST /api/v1/projects/:projectId/devices
Update PUT /api/v1/projects/:projectId/devices/:id
Delete DELETE /api/v1/projects/:projectId/devices/:id
Move POST /api/v1/projects/:projectId/devices/:id/move
Stats GET /api/v1/projects/:projectId/devices/stats

The DeviceController enforces permission codes such as device:read, device:write, and device:delete.

2.2 Device Groups (Drag-and-Drop Sorting)

Groups form a tree stored in the device_groups table. Each group has a parentId and a sortOrder column.

  • GET /devices/groups/tree returns the full tree
  • GET /devices/groups/:groupId/path returns the ancestor path (breadcrumbs)
  • POST /devices/:id/move re-parents a device or reorders it within a group

The frontend renders the tree with drag-and-drop; on drop, the new parentId and sortOrder are sent to the move endpoint.

2.3 Online Status Monitoring

Online status is computed by the DeviceStateManagerService:

  1. Each collector reports a heartbeat after every scan cycle
  2. If no heartbeat arrives within 2 × scanRate (default), the device is marked offline
  3. Status changes are emitted on the device.status.changed EventBus topic and pushed to the frontend via WebSocket

The /devices/stats endpoint returns counts of online/offline/total devices for dashboard widgets.

2.4 Device-Tag Binding

A device owns a list of data tags. Tag endpoints are nested under the device:

Operation Endpoint
Add tag POST /devices/:deviceId/tags
Batch add POST /devices/:deviceId/tags/batch
Remove tag DELETE /devices/:deviceId/tags/:tagId

Tags define the address (Modbus register, OPC UA node ID, MQTT topic, S7 DB offset), data type, scaling, and deadband.

2.5 Device Template Import

Templates (see the Template module) can be applied to a device to bulk-create tags:

  1. Open the device detail page
  2. Click Apply Template
  3. Select a template — its tag definitions are merged into the device
  4. Review and adjust per-device addresses (e.g. change Modbus slave ID)

Bulk JSON/CSV import is also available:

  • POST /devices/import/json — import devices from a JSON file
  • POST /devices/import/csv — import devices from CSV
  • GET /devices/export/json / GET /devices/export/csv — export current devices

3. Operational Guidance

3.1 Diagnosing a Device

  • POST /devices/:id/ping — triggers an immediate connectivity check
  • POST /devices/:id/diagnostic — runs a full diagnostic (connection, tag read, latency)

3.2 Reading Live and Historical Data

  • GET /devices/:id/data/latest — latest cached values for all tags
  • GET /devices/:id/data/history?start=...&end=... — historical series from InfluxDB
  • POST /devices/:id/data/write — write a value to a writable tag

4. FAQ

Q: A device shows "offline" but the collector is running. A: Check the collector's scan rate and the device's network address. Use POST /devices/:id/ping to force a fresh check. If the ping succeeds, the heartbeat interval may be too aggressive relative to the scan rate.

Q: Drag-and-drop reordering does not persist. A: Ensure the user has the device:write permission. The move endpoint returns 403 without it, and the frontend reverts the tree.

Q: Importing a CSV fails silently. A: The CSV must match the export column order exactly. Open the exported file as a template, fill in rows, and re-import. Common issues: wrong data type codes, missing group ID.

Q: How many tags can one device hold? A: There is no hard limit, but for performance keep a single device below ~500 tags. Use multiple devices or groups to scale further.