Fix: Save relay status dari ESP32 ke control_commands table

This commit is contained in:
flems 2026-05-29 05:44:23 +07:00
parent ce1b178ae5
commit 63ffe9c8ed
1 changed files with 10 additions and 2 deletions

View File

@ -250,15 +250,23 @@ mqttClient.on('message', async (topic, message) => {
// Save status update to status_history // Save status update to status_history
try { try {
await db.insertStatusHistory(`RELAY: ${statusMsg}`); await db.insertStatusHistory(`RELAY: ${statusMsg}`);
console.log('✅ Relay status saved to MySQL database'); console.log('✅ Relay status saved to status_history');
} catch (dbError) { } catch (dbError) {
console.error('❌ Failed to save relay status:', dbError.message); 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 { } else {
// Ini adalah command dari API/Flutter, simpan ke control_commands // Ini adalah command dari API/Flutter, simpan ke control_commands
try { try {
await db.insertControlCommand(msg, 'MQTT'); await db.insertControlCommand(msg, 'MQTT');
console.log('✅ Control command saved to MySQL database'); console.log('✅ Control command saved to control_commands');
} catch (dbError) { } catch (dbError) {
console.error('❌ Failed to save control command:', dbError.message); console.error('❌ Failed to save control command:', dbError.message);
} }