Device Registration and Connection Management
Device registration
Device registration starts with POST /devices.
- The Device sends its device name, secret key, Track information, and action information to the server.
- The server validates that the request value matches the runtime server setting
device.secretKey. - If validation succeeds, the server generates a device token and stores the Device in the DB.
- The server publishes a
DEVICE_REGISTEREDevent, and the client receives it to refresh the list. - After that, the device connects to the Moth device-connection-management channel and goes through the health-check process.
Meaning of the device token
The token is used for the following purposes afterward.
- device authentication
- Moth Track identification
- Task executor identification
In production, the registration request should travel through a protected channel, and the registration secret should be managed as an operational secret separate from ordinary user settings.
Device connection and state monitoring
The server periodically publishes HEALTHCHECK on Moth's device-connection-management channel.
- When a new interval begins, the Server broadcasts a
HEALTHCHECKmessage on the device-management channel. - The Device responds with
HEARTBEATincluding its token. - The Server records the tokens of the devices that responded within the interval.
- If the heartbeat is the first or a recovered heartbeat, the Device is transitioned to connected and a
DEVICE_CONNECTEDevent is published.
Health-check policy
The server uses the following policies from /server-settings.
device.healthcheckIntervalSeconds: the interval at whichHEALTHCHECKmessages are broadcastdevice.healthcheckMaxConsecutiveMisses: the maximum number of consecutive missed health checks
If the missed-heartbeat count exceeds the threshold, the device is transitioned to disconnected.
Device disconnection
- publish
DEVICE_DISCONNECTED - abort the latest in-progress or pending Task
- stop TGDM automatic recording when required
- stop active Mantis streams