fix: Turn OFF pot and pumps atomically together to prevent pressure issues in hose

This commit is contained in:
Wizznu 2026-06-02 08:40:16 +07:00
parent 206117d26a
commit b8cb7a3ba6
1 changed files with 11 additions and 21 deletions

View File

@ -365,40 +365,30 @@ const wateringWorker = new Worker(
totalWateringTime += duration; totalWateringTime += duration;
} }
// Turn OFF current pot valve (keep pumps ON for next pot if exists) // Turn OFF current pot valve AND pumps TOGETHER (atomic operation)
// This prevents pressure issues in the hose
const offUpdates = {}; const offUpdates = {};
if (pot >= 1 && pot <= 5) { if (pot >= 1 && pot <= 5) {
offUpdates[`mosvet_${pot + 2}`] = false; // pot 1 → mosvet_3, etc. offUpdates[`mosvet_${pot + 2}`] = false; // pot 1 → mosvet_3, etc.
} }
console.log(` 🔴 Turn OFF POT ${pot} valve: ${Object.keys(offUpdates).join(', ')}`); // Always turn OFF pumps with the pot (atomic OFF)
if (pompaAir) offUpdates['mosvet_1'] = false;
if (pompaPupuk) offUpdates['mosvet_2'] = false;
console.log(` 🔴 Turn OFF POT + PUMPS TOGETHER (atomic): ${Object.keys(offUpdates).join(', ')}`);
try { try {
await updateFirebaseSmart('aktuator', offUpdates, 2); await updateFirebaseSmart('aktuator', offUpdates, 2);
console.log(` ✅ POT ${pot} valve OFF confirmed`); console.log(` ✅ POT and pumps OFF confirmed (atomic)`);
} catch (offError) { } catch (offError) {
console.error(` ❌ FAILED to turn OFF POT ${pot}: ${offError.message}`); console.error(` ❌ FAILED to turn OFF: ${offError.message}`);
throw offError; throw offError;
} }
// Break 30 detik sebelum pot berikutnya (jika ada) // Break 30 detik sebelum pot berikutnya (jika ada)
if (potIndex < potCount - 1) { if (potIndex < potCount - 1) {
console.log(` ⏳ Waiting 2 seconds to stabilize...`); console.log(` ⏳ Waiting 2 seconds to stabilize (everything OFF)...`);
await sleep(2000); // 2 second stabilization after pot OFF await sleep(2000); // 2 second stabilization after everything OFF
// IMPORTANT: Turn OFF pumps during break (no pot is ON, so no need for pumps)
const breakPumpStop = {};
if (pompaAir) breakPumpStop['mosvet_1'] = false;
if (pompaPupuk) breakPumpStop['mosvet_2'] = false;
if (Object.keys(breakPumpStop).length > 0) {
console.log(` 🔴 Turn OFF pumps during BREAK: ${Object.keys(breakPumpStop).join(', ')}`);
try {
await updateFirebaseSmart('aktuator', breakPumpStop, 2);
console.log(` ✅ Pumps OFF confirmed`);
} catch (pumpError) {
console.warn(` ⚠️ Failed to turn OFF pumps during break: ${pumpError.message}`);
}
}
console.log(`\n ⏸️ BREAK 30 DETIK sebelum POT ${potNumbers[potIndex + 1]}...`); console.log(`\n ⏸️ BREAK 30 DETIK sebelum POT ${potNumbers[potIndex + 1]}...`);
for (let breakTime = 30; breakTime > 0; breakTime--) { for (let breakTime = 30; breakTime > 0; breakTime--) {