Sanyakorn Chaiphiphatworakul
All work

In production

MQTT production collector

Collects live output from factory IoT counters, checks it against the ERP plan, starts and stops itself, and recovers state after restarts.

Period
2026
Role
Sole developer
Used by
Production

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, turns running totals into 10-minute output, checks the ERP plan and alerts through n8n. Its data feeds the dashboard’s output-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
  • Alerts through n8n

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