made changes in motoraction

master
Varun 1 year ago
parent aa03b20985
commit a2bab73b64

@ -1359,6 +1359,8 @@ const sendNotification = async (fcmTokens, title, body) => {
// };
const stat_stop_intervals = {};
exports.motorAction = async (req, reply) => {
try {
const customerId = req.params.customerId;
@ -1395,6 +1397,11 @@ exports.motorAction = async (req, reply) => {
}
}
);
if (intervals[motorId]) {
clearInterval(stat_stop_intervals[motorId]);
delete stat_stop_intervals[motorId];
console.log("interval cleared")
}
reply.code(200).send({ message: "Motor stopped successfully." });
@ -1480,7 +1487,8 @@ exports.motorAction = async (req, reply) => {
// Start monitoring water level based on threshold time
const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate();
const intervalId = setInterval(async () => {
stat_stop_intervals[motorId] = setInterval(async () => {
console.log(stat_stop_intervals)
const splr_tank_info3 = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() });
const splr_tank_info3_waterlevel = parseInt(splr_tank_info3.waterlevel, 10);
const splr_tank_info3_capacity = parseInt(splr_tank_info3.capacity.replace(/,/g, ''), 10);
@ -1498,7 +1506,9 @@ exports.motorAction = async (req, reply) => {
}
}
);
clearInterval(intervalId);
console.log(stat_stop_intervals[motorId])
clearInterval(stat_stop_intervals[motorId]);
delete stat_stop_intervals[motorId];
// Send notification after motor stops due to time threshold
if (fcmToken) {
@ -1589,7 +1599,7 @@ exports.motorAction = async (req, reply) => {
}
// Start monitoring water level based on litres
const intervalId = setInterval(async () => {
stat_stop_intervals[motorId] = setInterval(async () => {
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);
if (current_water_level <= supplier_threshold) {
@ -1604,7 +1614,8 @@ exports.motorAction = async (req, reply) => {
}
}
);
clearInterval(intervalId);
clearInterval(stat_stop_intervals[motorId]);
delete stat_stop_intervals[motorId];
await delay(300000);

Loading…
Cancel
Save