|
|
|
@ -1908,7 +1908,7 @@ const stat_stop_intervals = {};
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
const motorIntervals = {};
|
|
|
|
|
exports.motorAction = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
@ -2040,7 +2040,12 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
if (motorIntervals[motorId]) {
|
|
|
|
|
clearInterval(motorIntervals[motorId]); // Clear the interval
|
|
|
|
|
delete motorIntervals[motorId]; // Remove the interval from the object
|
|
|
|
|
}
|
|
|
|
|
this.publishMotorStopStatus(motorId, motorStopStatus);
|
|
|
|
|
|
|
|
|
|
// Send immediate response to the client
|
|
|
|
|
reply.code(200).send({ message: "Motor stopped successfully." });
|
|
|
|
|
|
|
|
|
@ -2120,8 +2125,8 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate();
|
|
|
|
|
const intervalId = setInterval(async () => {
|
|
|
|
|
const thresholdTime = new Date(new Date().getTime() + req.body.manual_threshold_time * 60000);
|
|
|
|
|
motorIntervals[motorId] = setInterval(async () => {
|
|
|
|
|
const supplierTank = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() });
|
|
|
|
|
const currentWaterLevel = parseInt(supplierTank.waterlevel, 10);
|
|
|
|
|
const currentWaterPercentage = (currentWaterLevel / parseInt(supplierTank.capacity.replace(/,/g, ''), 10)) * 100;
|
|
|
|
@ -2141,8 +2146,9 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
emitWithTimestamp('lowWaterLevel', fcmToken); // Emit low water level notification
|
|
|
|
|
clearInterval(motorIntervals[motorId]); // Clear the interval when stopping
|
|
|
|
|
delete motorIntervals[motorId];
|
|
|
|
|
|
|
|
|
|
clearInterval(intervalId);
|
|
|
|
|
this.publishMotorStopStatus(motorId, "1");
|
|
|
|
|
await delay(300000);
|
|
|
|
|
const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id });
|
|
|
|
@ -2232,7 +2238,7 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start monitoring water level based on threshold percentage
|
|
|
|
|
const intervalId = setInterval(async () => {
|
|
|
|
|
motorIntervals[motorId] = setInterval(async () => {
|
|
|
|
|
// Check if water level has reached the threshold percentage
|
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() });
|
|
|
|
|
const current_water_level = parseInt(supplier_tank_info1.waterlevel, 10);
|
|
|
|
@ -2250,7 +2256,8 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
clearInterval(intervalId); // Stop monitoring water level
|
|
|
|
|
clearInterval(motorIntervals[motorId]); // Clear the interval when stopping
|
|
|
|
|
delete motorIntervals[motorId];// Stop monitoring water level
|
|
|
|
|
await delay(300000);
|
|
|
|
|
|
|
|
|
|
const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id });
|
|
|
|
|