From 63ffe9c8eda6426181ccc212b7660727eee22c38 Mon Sep 17 00:00:00 2001 From: flems Date: Fri, 29 May 2026 05:44:23 +0700 Subject: [PATCH] Fix: Save relay status dari ESP32 ke control_commands table --- backend/server.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/server.js b/backend/server.js index e6d4c93..7ec092f 100644 --- a/backend/server.js +++ b/backend/server.js @@ -250,15 +250,23 @@ mqttClient.on('message', async (topic, message) => { // Save status update to status_history try { await db.insertStatusHistory(`RELAY: ${statusMsg}`); - console.log('✅ Relay status saved to MySQL database'); + console.log('✅ Relay status saved to status_history'); } catch (dbError) { console.error('❌ Failed to save relay status:', dbError.message); } + + // Save juga ke control_commands dengan source ESP32 + try { + await db.insertControlCommand(statusMsg, 'ESP32'); + console.log('✅ Relay status saved to control_commands'); + } catch (dbError) { + console.error('❌ Failed to save to control_commands:', dbError.message); + } } else { // Ini adalah command dari API/Flutter, simpan ke control_commands try { await db.insertControlCommand(msg, 'MQTT'); - console.log('✅ Control command saved to MySQL database'); + console.log('✅ Control command saved to control_commands'); } catch (dbError) { console.error('❌ Failed to save control command:', dbError.message); }