<ahref="https://ko-fi.com/liamcottle"><imgsrc="https://img.shields.io/badge/Donate%20a%20Coffee-liamcottle-yellow?style=flat&logo=buy-me-a-coffee"alt="donate on ko-fi"/></a>
- An [mqtt client](./src/mqtt.js) is persistently connected to `mqtt.meshtastic.org` and subscribed to the `#` topic.
- All messages received are attempted to be decoded as [ServiceEnvelope](https://buf.build/meshtastic/protobufs/docs/main:meshtastic#meshtastic.ServiceEnvelope) packets.
- If a packet is encrypted, it attempts to decrypt it with the default `AQ==` key.
- If a packet can't be decoded as a `ServiceEnvelope`, it is ignored.
-`NODEINFO_APP` packets add a node to the database.
-`POSITION_APP` packets update the position of a node in the database.
-`NEIGHBORINFO_APP` packets log neighbours heard by a node to the database.
-`TELEMETRY_APP` packets update battery and voltage metrics for a node in the database.
-`TRACEROUTE_APP` packets log all trace routes performed by a node to the database.
-`MAP_REPORT_APP` packets are stored in the database, but are not widely adopted, so are not used yet.
Add a database [connection string for prisma](https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/connect-your-database-typescript-postgresql) to `.env` file.
By default, the [MQTT Collector](./src/mqtt.js) connects to the public Meshtastic MQTT server.
Alternatively, you may provide the relevant options shown in the help section below to connect to your own MQTT server along with your own decryption keys.
```
node src/mqtt.js --help
```
```
Meshtastic MQTT Collector
Collects and processes service envelopes from a Meshtastic MQTT server.
The map shows a different coloured icon for nodes based on their connection state to MQTT.
-`Green`: Online (connected to MQTT)
-`Blue`: Offline (disconnected from MQTT)
This works by listening to `/stat/!ID` topics on the MQTT server.
When a node connects to MQTT it publishes `online` to the topic, and when the MQTT server detects the client has disconnected (via an [LWT](https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/)) it publishes `offline` to the topic.
The Meshtastic [firmware configures](https://github.com/meshtastic/firmware/blob/279464f96d5139920b017d437501233737daf407/src/mqtt/MQTT.cpp#L330) an [LWT](https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/) (Last Will and Testament), which the MQTT server publishes upon client disconnect.
After a node boots up, there is a ~30 second delay before the `online` state is published.
After a node disconnects from MQTT, there is a ~30 second delay before the `offline` state is published.
This works well when your node connects to MQTT over WiFi, however, when using the `MQTT Client Proxy` feature, your node sends/receives packets to/from your Android/iOS device, and then your device connects to MQTT and proxies the messages.
Unfortunately, when using that feature your `online` / `offline` states will not work as expected.
As of the time of writing these docs, the mobile devices do not correctly configure the LWT for the node being proxied, and thus do not publish the `offline` state for the node, so you can't detect if your node disconnected from MQTT.