Skip to main content
The event stream is a WebSocket your own service can open to follow the progress of a device’s firmware updates as it happens, for example in your own support tool or companion app. For device connections, disconnections and the other fleet events, use webhooks instead.

Requirements

  • A credential: a user access token or a product API key. See API authentication.
  • The credential’s role must be able to view the device. Every built-in role can.
  • A Phoenix Channels client. The stream uses the Phoenix Channels protocol, and client libraries exist for most languages.
Authenticating with a product API key is on the NervesHub main branch but in no tagged release as of NervesHub 2.5.4. On 2.5.4 and earlier, use a user access token.

Connect

Open a WebSocket to /events-socket/websocket on the web host, the same host that serves the HTTP API. Pass the credential as the token query parameter.
A connection with a missing or invalid token is refused.

Subscribe to a device

Join the topic device:<identifier>. Join one topic for each device you want to follow.
A successful join is answered with status ok. A refused join is answered with status error and this response:
A join is refused when:
  • The device does not exist, or the credential cannot see it. A product API key only sees devices in its own product. A member with a tag-scoped role only sees devices with matching tags.
  • The device’s organization requires two-factor authentication and the token’s user has not set it up.

The firmware_update event

The server pushes firmware_update on the device’s topic each time the device reports on an update.

Example

This example uses the phoenix JavaScript client.

Check that it works

  1. Connect and join the topic for a device that is online.
  2. Send firmware to the device, for example with nh device upgrade <identifier> <firmware-uuid>.
  3. Watch for firmware_update events as the device downloads and applies it.

When access changes

The socket authenticates once, when it connects. NervesHub closes what you no longer have access to:
  • NervesHub checks your access to the device again when your role changes, when you are removed from the organization, when the organization starts requiring two-factor authentication, and when the device’s tags change. If you can no longer view the device, the subscription is closed.
  • A socket opened with a product API key is disconnected when the key is deactivated, or when the custom role it holds is edited. Reconnect to pick up the edited role.

Limits

  • The stream is live only. Events sent while you are not subscribed are not replayed.
  • It covers firmware update progress for one device per topic. There is no topic for a whole product or organization.