master
Varun 10 months ago
parent 1ed3061dfa
commit 40481f7591

@ -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(intervalId);
clearInterval(motorIntervals[motorId]); // Clear the interval when stopping
delete motorIntervals[motorId];
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 });

@ -70,7 +70,7 @@ const tanksSchema = new mongoose.Schema({
water_level: { type: String, default: null },
manual_threshold_percentage: { type: String, default: "90" },
manual_threshold_time: { type: String, default: null },
manual_stop_threshold_time: { type: String, default: null },
stop_threshold_time: { type: String, default: null },
threshold_type: { type: String, default: "percentage" },
startTime: { type: String, default: null },

Loading…
Cancel
Save