MQTT¶
Developer reference for Meshtastic/MeshCore MQTT ingest, channel key mapping, or the sticky BLE suppress. Repo-wide rules live in AGENTS.md.
Meshtastic: mqtt-manager.ts (AES-128/256-CTR, Meshtastic nonce layout, channel keys, protobuf, dedup); inbound TEXT_MESSAGE ingest prefers topic channel name → channelNameToIndex (receiver-local slot); MeshPacket.channel is fallback when topic absent — sampled log when they disagree (mqtt-channel-topic-mismatch:*); outbound (publishEncryptedData and its JSON mirror, publishDecodedJsonMirror) stamps channel with computeMeshtasticChannelHash(channelName, psk) from src/shared/meshtasticChannelHash.ts (XOR-fold of name bytes ^ XOR-fold of key bytes, mirroring firmware Channels::generateHash) — not the local slot index, which is "meaningless to send between nodes" per the field's own protobuf doc and is silently dropped by real radios/gateways that rely on it (there's no MQTT topic on RF to fall back to, unlike inbound). This hashes whatever key resolvePskForChannel resolves (including its DEFAULT_PSK fallback). PSK shorthand aliases (a single decoded byte, e.g. AQ== = 0x01) are firmware-defined channel-key presets, not raw key material — parsePsk() and normalizeMeshtasticPskTo16Bytes() expand them via expandMeshtasticPskAlias() in src/shared/meshtasticDefaultPublicPsk.ts (alias 1 → firmware defaultpsk d4f1bb3a20290759f0bcffabcf4e6901; 2-10 → that key's last byte + (index - 1); 0 / undefined aliases zero-pad, matching "no encryption"/unknown). Zero-padding the raw alias byte instead (the pre-fix behavior) silently produces the wrong AES key and the wrong channel hash for every default/simple-preset-PSK channel — always fix both MESHTASTIC_DEFAULT_PUBLIC_PSK_BYTES and main-process DEFAULT_PSK together (doc-commented as required to match) if this ever needs to change again; Connection panel Channel PSKs ChannelName@index= for MQTT-only slot mapping; meshtasticMqttPublish.ts; meshtasticChannelPskInput.ts + src/shared/meshtasticChannelPskLine.ts; meshtasticMqttSettingsStorage.ts; meshtasticMqttIdentity.ts (MQTT-only from); mqtt-broker-client-id.ts. After RF configure, useMeshtasticRuntime must re-push resolvedChannelConfigs via mqtt.updateChannelKeys (not only on MQTT status change) so cold-start MQTT before deviceStore channels still gets correct topic→slot maps ([Meshtastic MQTT] channelNameToIndex updated). updateChannelKeys topic→index and radio PSKs are merge-safe across incremental RF channel packets (partial OnTrail-only push must not wipe LongFast@1 or private-channel decrypt keys); slot takeover evicts another name on the same index; complete-cover pushes drop absent radio names. Pass radioSessionId (rf:<myNodeNum> / rf:none) so a new RF identity clears the prior radio's maps before merging. Runtime also debounces channel-key pushes (MESHTASTIC_MQTT_CHANNEL_KEYS_DEBOUNCE_MS via createDebouncedMqttChannelKeysPush) while configs stream. TELEMETRY_APP decode: protobuf-es v2 oneofs arrive as telemetry.variant = { case, value }. deviceMetrics is read from variant.value (legacy variant.deviceMetrics kept as fallback); environmentMetrics / airQualityMetrics go through sanitizeEnvironmentReading (src/shared/environmentTelemetry.ts) and emit nodeUpdate with env_* fields plus the env_recorded_at marker; JSON mirror posts (handleJsonTelemetry) do the same via environmentReadingFromSnakeCase. useMeshtasticRuntime strips the marker and records the reading into environmentTelemetryStore (source mqtt; RF/MQTT copies dedup in the store) → SQLite node_environment_telemetry (7-day / 500-per-node prune at startup) → map Sensors layer and NodeInfo sparklines. JSON sensor chat posts (e.g. {"xiaomi1":{"temp":…}}) are only matched by the Chat weather filter, not parsed into readings. Saved MQTT profiles (Meshtastic): src/renderer/lib/mqttProfiles.ts (mesh-client:mqttProfiles:meshtastic, same localStorage trust level as MQTTSettings, password included; no built-in regional brokers). Listed after the built-in presets in the network preset select (profile:<id> values) with inline save/rename/delete (MqttProfileControls.tsx); a Saved profile picker also appears on the connected card. Applying merges broker/topic/TLS/WebSocket fields only (auto-launch, PSKs, retries kept) and never connects; on a live session a topic-only change calls mqtt.updateTopicPrefix, while broker/credential/transport changes show a reconnect prompt. Subscribing to more than one root topic at once is deferred (single wildcard subscription unchanged). MeshCore: meshcore-mqtt-adapter.ts (JSON v1); LetsMesh JWT letsMeshJwt.ts. Multi-broker analyzer feeds (MeshCore only): MeshcoreMqttPool (src/main/meshcore-mqtt-pool.ts) owns one bidirectional chat session (connectionId: 'chat') plus up to three publish-only packet-analyzer feeds (MAX_MESHCORE_MQTT_CONNECTIONS = 4, MAX_MESHCORE_MQTT_PUBLISH_FEEDS = 8 saved). Feed adapters pass publishOnly so they never subscribe or emit chatMessage; publishChat routes to the chat adapter only and publishPacketLog serializes one payload per v1_ pubkey and fans it out. Feed metadata lives in mesh-client:mqttFeeds:meshcore (meshcoreMqttFeeds.ts) with passwords in mqtt:meshcore:feeds; the chat broker keeps the existing mesh-client:mqttSettings:meshcore key and presets/migrations unchanged. The Connection panel renders the chat entry and every saved feed as one MQTT connections list: each row has Connect/Cancel/Disconnect (plus Reconnect when edited), Edit, Auto-connect and Delete (feeds), and Add opens the shared preset-backed editor. MeshMapper's preset enables packet logging automatically because that broker only ingests packets/status. IPC payloads carry connectionId/role, and token refresh/update are keyed by connection id. This is a deliberate protocol-parity exception: Meshtastic/MeshCom MQTT remain single-session because their encrypted channel ingest would duplicate across brokers. Sticky MeshCore BLE “Blue” suppress: connectedMeshcoreBleMac.ts persists a valid MeshCore BLE MAC and pre-arms Meshtastic NodeDB ghost suppression across cold start, failed reconnect, and user disconnect; clear only on Forget or switching MeshCore to a non-BLE transport.