ECE-BOT includes an MQTT worker that subscribes to a broker and stores machine telemetry — temperature, humidity, and vibration — into the database as it arrives. The worker runs independently from the Flask web app, which means you can enable or disable telemetry ingestion without touching the web server configuration.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Kr-Yogsa/ECE-BOT/llms.txt
Use this file to discover all available pages before exploring further.
How the worker fits into the architecture
mqtt_worker.py is a standalone Python process. It connects to the MQTT broker, subscribes to the configured topic filter, and writes each valid message to the database via the same database layer used by the web app.
In Docker deployments, setting RUN_MQTT_WORKER=true starts the worker alongside gunicorn in the same container using a process supervisor. Outside Docker, you run mqtt_worker.py directly as a separate process.
Expected telemetry payload
The worker expects each MQTT message to be a JSON object. All numeric fields are optional — missing fields are stored asnull. The machine_id field is the preferred source of the machine identifier; if it is absent, the worker falls back to extracting the second-to-last segment of the topic path (the + wildcard position in factory/machine/+/telemetry).
Timestamps that pre-date 2025 (such as ESP32 uptime-based placeholders that start from
1970-01-01) are discarded and replaced with the server’s current time when storing the record.Topic structure
The default topic filter isfactory/machine/+/telemetry. The + wildcard matches exactly one topic level and is treated as the machine ID when machine_id is not present in the payload.
| Segment | Example value | Purpose |
|---|---|---|
factory | factory | Fixed namespace |
machine | machine | Fixed segment |
+ | cnc, plc, melfa | Machine identifier |
telemetry | telemetry | Fixed segment |
factory/machine/cnc/telemetry will have its data stored against machine ID cnc.
Enabling the worker
- Docker (recommended)
- Separate process
Set
RUN_MQTT_WORKER=true in your .env file and redeploy. The container entrypoint starts the worker alongside gunicorn automatically..env
Broker options
ECE-BOT is broker-agnostic and works with any MQTT v3/v5 broker. Common choices:- Eclipse Mosquitto — lightweight, easy to self-host on the same machine or a local network device
- EMQX — full-featured broker with a web dashboard, suitable for larger deployments
- HiveMQ Cloud — managed cloud broker with a free tier
- AWS IoT Core / Azure IoT Hub — cloud-managed options that require TLS and certificate-based auth
TLS configuration
SetMQTT_USE_TLS=true to enable TLS for the broker connection. The broker must be listening on a TLS port (typically 8883) and have a valid certificate installed.
.env
Machine online/offline status
The dashboard shows each machine as online or offline based on how recently a telemetry message was received. If no message arrives within the number of seconds defined byMACHINE_OFFLINE_AFTER_SECONDS (default: 15), the machine is shown as offline.
.env