|
|
|
@ -2837,6 +2837,7 @@ async function calculateTotalPumpedWater(customerId, motorId, start_instance_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stoppedMotors = new Set(); // To track motors that have already been stopped
|
|
|
|
|
|
|
|
|
|
exports.motorAction = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
@ -2936,23 +2937,31 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
console.log("New Threshold Time:", thresholdTime);
|
|
|
|
|
console.log("Current Time:", new Date());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
motorIntervals[motorId] = setInterval(async () => {
|
|
|
|
|
const currentTime = new Date();
|
|
|
|
|
console.log(`🚀 Checking Motor ${motorId} | Threshold Time: ${thresholdTime} | Current Time: ${currentTime}`);
|
|
|
|
|
|
|
|
|
|
// If threshold time has passed, force stop the motor
|
|
|
|
|
// If threshold time has passed, stop the motor
|
|
|
|
|
if (currentTime >= thresholdTime) {
|
|
|
|
|
console.log(`🛑 Motor ${motorId} threshold time exceeded. Stopping motor.`);
|
|
|
|
|
|
|
|
|
|
// Stop the interval before proceeding
|
|
|
|
|
// Check if motor has already been stopped
|
|
|
|
|
if (stoppedMotors.has(motorId)) {
|
|
|
|
|
console.log(`⚠️ Motor ${motorId} already stopped. Skipping duplicate stop.`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mark motor as stopped to prevent duplicate execution
|
|
|
|
|
stoppedMotors.add(motorId);
|
|
|
|
|
|
|
|
|
|
// Ensure the interval is cleared before proceeding
|
|
|
|
|
if (motorIntervals[motorId]) {
|
|
|
|
|
clearInterval(motorIntervals[motorId]);
|
|
|
|
|
delete motorIntervals[motorId];
|
|
|
|
|
console.log(`✅ Interval for motorId: ${motorId} successfully deleted.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the tank data and publish stop status
|
|
|
|
|
// Update tank data
|
|
|
|
|
const formattedTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
|
await Tank.updateOne(
|
|
|
|
|
{ customerId, "connections.inputConnections.motor_id": motorId },
|
|
|
|
@ -2967,13 +2976,14 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`🚨 Motor ${motorId} stop condition met. Sending stop command.`);
|
|
|
|
|
this.publishMotorStopStatus(motorId, "1");
|
|
|
|
|
|
|
|
|
|
return; // Ensure the function exits
|
|
|
|
|
return; // Ensure function exits after stopping
|
|
|
|
|
}
|
|
|
|
|
}, 10000); // Check every 10 seconds instead of 30
|
|
|
|
|
}, 10000); // Check every 10 seconds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|