The problem
IoT devices only send running totals, which are hard to use; the business needs per-interval logs that follow the factory working day.
What I built
A Python service in Docker that listens to MQTT and works out, from how the counts move, when each product starts, reaches its plan or stops. Each event goes through n8n into the dashboard’s notification feed, and while a line runs its running totals become 10-minute output that feeds the per-hour charts.
Key features
- Starts logging only when output actually moves
- Detects machine counter resets and starts a new lot
- Stops when the ERP plan is reached or after 60 idle minutes
- Reloads the latest state from the database after a restart
- Publishes the active line list back to MQTT for other systems
- Sends start, plan-reached and stop events with factory, line, product and output against plan through n8n to the dashboard’s notification feed
- Notices when a stopped product resumes and starts recording again
Under the hood
- Tells a real first reading from noise: the first delta must equal the running total, and a falling counter means a reset
- paho-mqtt runs in a background thread with a lock-guarded buffer flushed into 10-minute windows
- 08:00 working-day cutoff, and a solved TLS issue when reaching SQL Server from inside the container