Fix: Save relay status dari ESP32 ke control_commands table
This commit is contained in:
parent
ce1b178ae5
commit
63ffe9c8ed
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue