Skip to Content
GuidesRaspberry Pi fleet observer

Raspberry Pi Fleet Observer

A Raspberry Pi as a local MQTT gateway for a fleet of ESP32s: a Mosquitto broker on the Pi, plus a small Python bridge that forwards each MQTT message to Plexus with the source_id parsed from the topic.

Prerequisites

  • A Raspberry Pi 3B+ or newer running Raspberry Pi OS Lite (64-bit).
  • Mosquitto: sudo apt install -y mosquitto mosquitto-clients.
  • An API key from your /dev/keys page.
  • The ESP32 → alerts hardware (you’ll re-flash it once).

The bridge

Subscribes to plexus/+/+ and forwards each message to Plexus, one client per source so every device keeps its own identity:

import json, os import paho.mqtt.client as mqtt from plexus import Plexus MQTT_HOST = os.environ.get("MQTT_HOST", "localhost") TOPIC = os.environ.get("MQTT_TOPIC", "plexus/+/+") clients = {} def get_client(source_id): if source_id not in clients: clients[source_id] = Plexus(source_id=source_id) return clients[source_id] def on_message(_c, _u, msg): parts = msg.topic.split("/") # plexus/<source_id>/<metric> if len(parts) != 3 or parts[0] != "plexus": return _, source_id, metric = parts payload = msg.payload.decode("utf-8", errors="replace") try: value = float(payload) except ValueError: try: value = json.loads(payload) except ValueError: value = payload get_client(source_id).send(metric, value) def main(): client = mqtt.Client() client.on_message = on_message client.connect(MQTT_HOST) client.subscribe(TOPIC) client.loop_forever() if __name__ == "__main__": main()

Install (run on boot)

python3 -m venv ~/plexus-bridge && source ~/plexus-bridge/bin/activate pip install plexus-python paho-mqtt cp bridge.py ~/bridge.py sudo cp plexus-bridge.service /etc/systemd/system/ # systemd unit, restart-on-failure sudo systemctl daemon-reload sudo systemctl enable --now plexus-bridge

Verify with sudo systemctl status plexus-bridge and journalctl -u plexus-bridge -f.

Point the ESP32s at the Pi

Re-flash each ESP32 with the BME280_Dashboard sketch:

  • Uncomment #define PLEXUS_TRANSPORT_MQTT at the top.
  • Set MQTT_HOST to the Pi’s LAN IP (e.g., 192.168.1.42).
  • Give each ESP32 a unique SOURCE_ID (esp32-greenhouse, esp32-fridge).
  • Install one extra Arduino library: PubSubClient by Nick O’Leary.

Each ESP32 publishes plexus/<SOURCE_ID>/<metric> to Mosquitto; the Pi forwards each to Plexus with the right source_id attached.

Tuning knobs

Set in the systemd unit’s environment:

Env varDefaultWhat it does
PLEXUS_API_KEY(required)your Plexus key
MQTT_HOSTlocalhostbroker host
MQTT_TOPICplexus/+/+topic filter (devices/metrics)
Last updated on