Skip to main content
Version: 3.4.x

Device Registration and Connection Management

Device registration

Device registration starts with POST /devices.

  1. The Device sends its device name, secret key, Track information, and action information to the server.
  2. The server validates that the request value matches the runtime server setting device.secretKey.
  3. If validation succeeds, the server generates a device token and stores the Device in the DB.
  4. The server publishes a DEVICE_REGISTERED event, and the client receives it to refresh the list.
  5. 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.

  1. When a new interval begins, the Server broadcasts a HEALTHCHECK message on the device-management channel.
  2. The Device responds with HEARTBEAT including its token.
  3. The Server records the tokens of the devices that responded within the interval.
  4. If the heartbeat is the first or a recovered heartbeat, the Device is transitioned to connected and a DEVICE_CONNECTED event is published.

Health-check policy

The server uses the following policies from /server-settings.

  • device.healthcheckIntervalSeconds: the interval at which HEALTHCHECK messages are broadcast
  • device.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