Skip to content

MQTT Integration ​

The server connects to an MQTT broker to receive real-time beacon and gateway data. MQTT handling is split between lib/src/mqtt.ts (client connection) and server/src/mqtt.ts (message dispatching).

Message Types ​

Beacon Messages ​

Beacons broadcast three types of advertisement packets:

TypeSchemaDataPurpose
adv1MqttButtonAdv1SchemaBattery, temperature, humidity, button stateSensor data and panic button events
adv4MqttButtonAdv4SchemaRSSI, gateway MACSignal strength for location tracking
adv8MqttButtonAdv8SchemaExtended sensor dataAdditional sensor readings

Beacons are identified by MAC address with prefixes BC5729 or BBCBBC.

Gateway Messages ​

TypeSchemaDataPurpose
aliveMqttGatewayAliveSchemaIP, uptime, firmwareGateway health monitoring
advDataMqttGatewayAdvDataSchemaBeacon advertisementsForwarded beacon data

Direct Sensor Messages ​

Legacy (non-BLE) MQTT-enabled sensors publish directly to the broker, without a gateway:

TypeSchemaDataPurpose
sDataMqttSensorDataSchemaTemperature, humidityEnvironmental readings from legacy sensors

These messages carry no RSSI, so the devices are discovered and fed into sensor storage/alerting but never participate in RTLS tracking. See the Legacy Sensor MQTT Spec for the full device-facing specification.

Message Flow ​

MQTT Broker
    │
    ▼
lib/src/mqtt.ts
    │  mqtt_start() → subscribes to all topics (#)
    │  Parses gateway messages (MqttGatewayMessageSchema)
    │  Extracts beacon adv1/adv4/adv8 and gateway alive
    │
    ▼
server/src/mqtt.ts
    │  mqtt_message_process(source, type, message)
    │
    ├── bridge_process_mqtt_message()  [if bridge enabled]
    │   → Forwards to Zabbix
    │
    ├── devices_mqtt_process()
    │   → Updates in-memory device caches (used immediately by Import Gateways / Import Beacons, alongside periodic sync to `device_gateways` / `device_beacons`)
    │
    └── events_process_mqtt_message()
        ├── Panic/SOS handling
        ├── Sensor data storage
        └── tracking_process_mqtt_message()
            → RSSI data for zone prediction

Configuration ​

MQTT connection is configured in config/main.config.json (legacy fallback: root main.config.json):

KeyDescription
server_mqtt_urlBroker URL (e.g. mqtt://localhost:1883)
server_mqtt_userBroker username
server_mqtt_passBroker password

Status ​

The MQTT connection status can be checked via:

  • HTTP endpoint: GET /api/v1/status/mqtt (cached snapshot wrapper; the dashboard uses GET /api/v1/status/dashboard)
  • Function: mqtt_status_get() returns connection state