Skip to main content

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.

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.

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 as null. 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).
{
  "machine_id": "cnc",
  "temperature": 29.4,
  "humidity": 61.0,
  "vibration": 0.0314,
  "timestamp": "2026-05-05T10:30:00Z"
}
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 is factory/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.
SegmentExample valuePurpose
factoryfactoryFixed namespace
machinemachineFixed segment
+cnc, plc, melfaMachine identifier
telemetrytelemetryFixed segment
A device publishing to factory/machine/cnc/telemetry will have its data stored against machine ID cnc.

Enabling the worker

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
# Install on Ubuntu/Debian
sudo apt install mosquitto mosquitto-clients

# Test publish from a device
mosquitto_pub -h localhost -t factory/machine/cnc/telemetry \
  -m '{"machine_id":"cnc","temperature":29.4,"humidity":61.0,"vibration":0.0314}'

TLS configuration

Set MQTT_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
MQTT_USE_TLS=true
MQTT_BROKER_HOST=your-broker.example.com
MQTT_BROKER_PORT=8883
MQTT_USERNAME=your-username
MQTT_PASSWORD=your-password
When MQTT_USE_TLS=true, ECE-BOT calls tls_set() on the paho client with system CA certificates. If your broker uses a self-signed certificate, you will need to modify services/mqtt_service.py to pass the CA certificate path explicitly.

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 by MACHINE_OFFLINE_AFTER_SECONDS (default: 15), the machine is shown as offline.
.env
# Mark machine offline after 30 seconds without a telemetry message
MACHINE_OFFLINE_AFTER_SECONDS=30
Match MACHINE_OFFLINE_AFTER_SECONDS to your device’s publish interval. If a device publishes every 10 seconds, a threshold of 15–30 seconds gives one or two missed messages before the machine is marked offline.

Build docs developers (and LLMs) love