MQTT subscription channel for ESP RainMaker Neo.

This channel is a thin adapter over NodeMQTTOrchestrator, which owns the single MQTT connection, the AWS IoT shadow topic subscriptions, and the deduplication of nodes that share a group/subgroup shadow. The channel's job is only to:

  • map a node to its shadow and register it with the orchestrator,
  • normalize each shadow message into the canonical ESPNodeUpdateData envelope (so the app sees the same shape from every channel), and
  • fan that envelope out to the app callbacks subscribed for the node.

It deliberately does not open/close the MQTT connection — that lifecycle is owned by ESPRMNeoBase.init() / the orchestrator, so disposing one channel never tears down a connection other channels (or the node) still use.

const mqttChannel = new MQTTSubscriptionChannel();
await ESPRMNeoBase.subscriptionManager.registerChannel(mqttChannel);
await ESPRMNeoBase.subscriptionManager.subscribeToNode(node, (update) => {
console.log(`Node ${update.nodeId} updated:`, update.payload);
});

Implements

Constructors

Properties

channelId: "mqtt" = SubscriptionChannelIds.MQTT

Unique identifier for this channel (e.g., "mqtt", "matter", "ble")

Methods

  • Subscribe to parameter updates for a node.

    Constructs the node's shadow name from its group/subgroup context, registers it with the orchestrator (deduped by shadow), and installs a single orchestrator listener per node that normalizes shadow messages and fans them out to all subscriber callbacks.

    Parameters

    • callback: (update: ESPNodeUpdateData) => void

      Invoked with a normalized ESPNodeUpdateData on each update.

    • node: NodeLike

      The node to subscribe to. Must carry nodeId (or id) and groupId; subgroupIds optional. Group context is used to build the shadow name directly — no reverse lookup from persisted state.

    Returns Promise<void>

    Error if the node has no id or the orchestrator subscription fails.

  • Unsubscribe from a node.

    • No nodeId: detach every node.
    • nodeId only: detach the node and all its subscribers.
    • nodeId + callback: remove just that subscriber; the node stays subscribed (and the shared orchestrator listener stays attached) until its last subscriber is removed, so sibling subscribers are not affected.

    Parameters

    • OptionalnodeId: string

      Node id to detach; omit to detach all nodes.

    • Optionalcallback: (update: ESPNodeUpdateData) => void

      Optional specific subscriber to remove.

    Returns Promise<void>