@qualithm/device - v0.12.2
    Preparing search index...

    Class Device

    A connected Qualithm device.

    const device = new Device({
    provisioningUrl: "https://api.qualithm.com",
    claimCode: process.env.QUALITHM_CLAIM_CODE
    })
    await device.connect()
    await device.publish(
    "telemetry",
    JSON.stringify({ ts: Date.now(), metrics: { temperature: 21.4 } })
    )
    Index

    Constructors

    Accessors

    Methods

    • Provision (claim once, or load the stored credential) and open the auto-reconnecting MQTT-over-TLS session. Resolves once connected.

      Returns Promise<void>

    • Declare (or re-declare) the device's capability set. The manifest is validated locally, published on the current session, and re-published on every subsequent connect. Throws a CapabilityError on an invalid declaration.

      Parameters

      Returns Promise<void>

    • Gracefully close the session. The state becomes closed (terminal).

      Returns Promise<void>

    • Register a handler for commands addressed to one capability key.

      The SDK subscribes command/# once and dispatches by key, decoding the payload first: a settable capability's handler receives the decoded value; a trigger capability's handler is invoked with no value. A malformed payload or a throwing handler is reported through onError without interrupting dispatch. Returns an unregister function.

      Type Parameters

      • V

      Parameters

      Returns () => void

    • Subscribe to connection-state transitions. Returns an unsubscribe function.

      Parameters

      Returns () => void

    • Publish a payload to a (device-relative) topic.

      A QoS 1 publish carries a msg-id user property. When the gateway answers it with a failed PUBACK (reason code 0x80 or above), it is published again with the same msg-id, after a capped, jittered backoff, so the gateway stores it once.

      Parameters

      • topic: string
      • payload: string | Uint8Array<ArrayBufferLike>
      • Optionaloptions: IClientPublishOptions

      Returns Promise<void>

      PayloadTooLargeError when the payload exceeds the ceiling the gateway advertised in CONNACK (qualithm/pm#126) — caught before the bytes go on the wire, so the device is told rather than silently dropped.

      the last failed PUBACK's error once every attempt has failed.

    • Start soft-AP provisioning mode: serve the claim exchange on the device's setup network until the companion app claims the device.

      Only available before a gateway session exists — never alongside one. A successful claim persists the credential, stops the server and the setup access point, and invokes onProvisioned; connect() then proceeds with the stored credential. While the server is serving, the device's state is provisioning.

      Parameters

      Returns Promise<ProvisioningServer>

      ConnectionError when a gateway session is active or the device is closed.

      ProvisioningError when the device is already provisioned or the server fails to start.

    • Subscribe to one or more (device-relative) topic filters.

      Parameters

      • topic: string | string[]
      • Optionaloptions: IClientSubscribeOptions

      Returns Promise<void>