# Devices

A device is anything that connects to Qualithm: a gateway, an edge computer, a prototype on your
desk. Each device belongs to one [scope](https://docs.qualithm.com/scopes.md), holds its own credential, and speaks
[MQTT](https://docs.qualithm.com/mqtt.md) or [HTTP](https://docs.qualithm.com/http.md) to the gateway for its scope's [zone](https://docs.qualithm.com/zones.md).

What a device reports and accepts shows up across the app. Its readings feed
[dashboards](https://docs.qualithm.com/dashboards.md), and [automations](https://docs.qualithm.com/automations.md) watch those readings and set its
controls.

## Add a device

Create a claim code in the scope the device should join, then let the device claim its credential
with it. In the app, open **Scopes**, choose the scope, and open **Claim codes**. The steps over
HTTP are in [Claim a device](https://docs.qualithm.com/http.md#claim-a-device).

A claim code is shown once, when you create it. After creation the app shows the gateway and API the
device connects to for its zone. A code is **Pending** until a device uses it, then **Claimed**.
Revoke a pending code you no longer need.

The device takes its scope's zone when it claims. That zone never changes.

A claimed device keeps its receipt: what the claim decided, such as its zone, gateway and
credential. `GET /v1/teams/{teamId}/devices/{deviceId}`, the device's **Overview** in the app and
`qualithm device get` all show it.

## Connect it with a credential

A credential lets the device connect. It is either a token, used as the device's MQTT password, or a
certificate. Claiming gives the device its first credential.

The device's **Credentials** tab lists every credential with its status, expiry and when it was last
used:

- **Create token** adds a token. Copy it when it appears: it is shown once.
- **Rotate** replaces a token. The current token stops working, so the device can't connect until it
  uses the new one.
- **Revoke** stops the device connecting with that credential. This cannot be undone.

To connect with a certificate instead, see
[Move a device to a certificate](https://docs.qualithm.com/http.md#move-a-device-to-a-certificate).

## Declare what the device does

A device declares its readings and controls in the connect call of the Qualithm Device SDK. See
[Declare capabilities](https://docs.qualithm.com/mqtt.md#declare-capabilities). Dashboards and automations offer only what the
device declared. Until it declares something, the device's **Overview** shows **No capabilities
declared**.

## Reach production

The device's **Checks** tab shows its level. A device starts at **Development** and reaches
**Production** when every check passes:

- **Certificate credential**: connect the device with a certificate, then revoke its tokens.
- **Protected key**: generate the device's key in protected hardware.
- **Signed firmware**: run signed firmware on the device.
- **Expiring credential**: revoke each credential that never expires.

Each failing check names its fix.

## Move a device

On the device's **Settings** tab, choose another scope under **Scope**. A device moves only between
scopes in the zone it was claimed in. To run it in another zone, delete it and claim it again from a
scope in that zone.

## Park a device

Parking a device keeps its registration, credentials and history but stops it connecting or writing.
Park and unpark from the **Devices** table on the **Scopes** page. A device a member parks stays
parked until a member unparks it. A parked device that stays online keeps renewing its credentials,
so unparking brings it straight back.

Qualithm also parks a device that hasn't connected, published or been changed by a member for
30 days. That park lifts itself: the device unparks the next time it
connects to the gateway for its zone with a valid credential. On the free plan, the connection must
also fit under the team's [connected-device limit](https://docs.qualithm.com/billing-and-usage.md#connect-more-devices). A
connection the limit refuses leaves the device parked.

A device idle that long has usually outlived its credential. Before it can connect and unpark, give
it a new one on its **Credentials** tab. Don't claim it again: a new claim makes a new device,
without the parked one's history.

`GET /v1/teams/{teamId}/devices/{deviceId}` returns why a device is parked as `parkedReason`:
`member` or `idle`. It is `null` while the device isn't parked.

## Stay under the event limit

A single event a device publishes can be at most **128 KiB** (131072 bytes), flat across every plan.
The gateway tells the device the limit when it connects (the MQTT 5 Maximum Packet Size property)
and rejects an oversize publish instead of dropping it. The device SDK reads that limit and raises
`PayloadTooLargeError` before the bytes are sent, so an oversize event fails at the call site with
the limit and the actual size named.

A reading holds at most **64 metrics**, since each metric is stored as its own reading. The gateway
refuses a reading with more (PUBACK `0x99`), and the Python device SDK raises `TooManyMetricsError`
before sending it. Split a wider reading into several.

Larger payloads belong in object storage with a reference in the event, not in the event itself.

## Delete a device

Deleting a device revokes its credentials, so it can no longer connect, and removes its readings.
Confirm by entering `DELETE`. This cannot be undone.

## See also

- [Scopes](https://docs.qualithm.com/scopes.md)
- [MQTT](https://docs.qualithm.com/mqtt.md)
- [HTTP](https://docs.qualithm.com/http.md)
- [Dashboards](https://docs.qualithm.com/dashboards.md)
- [Automations](https://docs.qualithm.com/automations.md)
