Architecting Hardware-Controlled IoT Billing with Laravel and ESP8266
The Real-World Problem
In a busy PlayStation or gaming rental center, software-only timers still leave a major gap: if a cashier forgets to turn off a screen or someone starts a session off the books, revenue leaks immediately. While building the IoT Gaming Rental System, the goal was simple—software billing had to physically control the TV relay on every table.
System Architecture Overview
Instead of pushing fragile peer-to-peer commands from browsers to local hardware, the architecture uses the Laravel backend as the single source of truth:
- Admin & Cashier UI (Laravel + Livewire Volt): Handles prepaid timer packages, open-ended postpaid sessions, pause/resume states, and table service alerts.
- Relational State (MySQL): Stores active session timestamps, remaining seconds, and device assignment so server restarts never lose billing state.
- Hardware Nodes (Arduino / ESP8266 + Relay): Each station connects over Wi-Fi, sends a lightweight heartbeat to the server, and receives an authoritative
relay_onboolean along with device health metadata.
Why a Heartbeat Protocol Works Best
In real rental environments, local Wi-Fi routers reboot and power fluctuates. A one-second authenticated heartbeat from the ESP8266 node solves two problems at once:
- Self-healing state sync: Even if a relay misses a single packet, the very next heartbeat aligns physical TV power with the billing database within one second.
- Live hardware health monitoring: If a node stops checking in for more than a few seconds, the admin dashboard flags the station as offline immediately.
// Simplified Laravel heartbeat endpoint response
$session = $device->activeSession();
$shouldPowerOn = $session !== null
&& $session->status === 'active'
&& ($session->isPostpaid() || $session->ends_at->isFuture());
$device->update(['last_seen_at' => now()]);
return response()->json([
'power' => $shouldPowerOn,
'remaining_seconds' => $session?->remainingSeconds() ?? 0,
]);Lessons Learned Deploying Software + Hardware
- Design for idempotency: Treat every device poll as a pure state query, never as a toggle command—toggles drift out of sync as soon as a packet is dropped.
- Hardware failsafes matter: Wire relays cleanly and ensure default boot states keep screens off until the node authenticates and receives
power: true. - Keep cashier UX instant: Reactive dashboards with Livewire Volt let staff start, pause, or extend sessions in one click without page reloads.
Interested in building custom backend systems or hardware-integrated web platforms? Explore more of my case studies or get in touch to discuss your project.