From d721b4d37c5de579884cc9531243a9f7aa043def Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 11 Mar 2025 17:00:50 +0530 Subject: [PATCH 1/4] changes --- src/controllers/tanksController.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 9ea2c3bb..4fdcb7d3 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2344,6 +2344,7 @@ cron.schedule("* * * * *", async () => { // }; exports.publishMotorStopStatus = async (motor_id, motor_stop_status) => { + console.log("entered publish",motor_id,motor_stop_status) const deviceTopic = `water/operation/${motor_id}`; // Target specific IoT const payload = { topic: 'operation', From a6b73f611c58736319963ba9a2c546924daac38e Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 11 Mar 2025 17:02:26 +0530 Subject: [PATCH 2/4] changes --- src/controllers/tanksController.js | 71 ++++++++++++++++-------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index b18ced49..3b9406c5 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1572,18 +1572,18 @@ eventEmitter.on('sendCriticalHighWaterNotification', async (fcmTokens, tankInfo, // }); -// eventEmitter.on('sendThresholdTimeNotification', async (customerId, fcmTokens, thresholdTime, hw_Id, tankName, blockName) => { -// try { -// const message = -// `🛢️ Tank Name: '${tankName}'\n` + -// `🏢 Block Name: '${blockName}'\n` + -// `Motor Stopped as it completed ${thresholdTime} minutes.`; -// await sendNotification(hw_Id, customerId, fcmTokens, 'Motor Alert', message); -// console.log("Threshold time notification sent successfully."); -// } catch (error) { -// console.error("Error sending threshold time notification:", error); -// } -// }); +eventEmitter.on('sendThresholdTimeNotification', async (customerId, fcmTokens, thresholdTime, hw_Id, tankName, blockName) => { + try { + const message = + `🛢️ Tank Name: '${tankName}'\n` + + `🏢 Block Name: '${blockName}'\n` + + `Motor Stopped as it completed ${thresholdTime} minutes.`; + await sendNotification(hw_Id, customerId, fcmTokens, 'Motor Alert', message); + console.log("Threshold time notification sent successfully."); + } catch (error) { + console.error("Error sending threshold time notification:", error); + } +}); // eventEmitter.on( // 'sendMotorStartNotification', @@ -2343,6 +2343,9 @@ cron.schedule("* * * * *", async () => { // } // }; + + + exports.publishMotorStopStatus = async (motor_id, motor_stop_status) => { console.log("entered publish",motor_id,motor_stop_status) const deviceTopic = `water/operation/${motor_id}`; // Target specific IoT @@ -3105,29 +3108,29 @@ exports.motorAction = async (req, reply) => { const notificationKey = `${customerId}_${motorId}_threshold`; // Check if the notification has already been sent - // if (!notificationTracker.get(notificationKey)) { - // console.log("Sending threshold time notification..."); + if (!notificationTracker.get(notificationKey)) { + console.log("Sending threshold time notification..."); - // eventEmitter.emit( - // "sendThresholdTimeNotification", - // customerId, - // fcmToken, - // manual_threshold_time, - // motorId, - // tankName, - // blockName - // ); - - // // Mark notification as sent - // notificationTracker.set(notificationKey, true); - - // // Optionally, reset the flag after some time (e.g., 24 hours) - // setTimeout(() => { - // notificationTracker.delete(notificationKey); - // }, 24 * 60 * 60 * 1000); // Reset after 24 hours - // } else { - // console.log("Notification already sent, skipping..."); - // } + eventEmitter.emit( + "sendThresholdTimeNotification", + customerId, + fcmToken, + manual_threshold_time, + motorId, + tankName, + blockName + ); + + // Mark notification as sent + notificationTracker.set(notificationKey, true); + + // Optionally, reset the flag after some time (e.g., 24 hours) + setTimeout(() => { + notificationTracker.delete(notificationKey); + }, 24 * 60 * 60 * 1000); // Reset after 24 hours + } else { + console.log("Notification already sent, skipping..."); + } const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); await Tank.updateOne( From aba4cc9330c52f8df10c075f140b79cddf0e7315 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 11 Mar 2025 17:05:37 +0530 Subject: [PATCH 3/4] changes --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 3b9406c5..86d59e51 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3061,7 +3061,7 @@ exports.motorAction = async (req, reply) => { receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10) }); await newMotorData.save(); - + console.log("entered time",motorId,motorStopStatus) // Update the tank connections with start time and threshold time for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { this.publishMotorStopStatus(motorId, motorStopStatus); From ea28c0067c7273a9fdf0e6bcb2604079d7458bb5 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 11 Mar 2025 17:08:28 +0530 Subject: [PATCH 4/4] changes --- src/controllers/tanksController.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 86d59e51..d118c8d4 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2349,6 +2349,7 @@ cron.schedule("* * * * *", async () => { exports.publishMotorStopStatus = async (motor_id, motor_stop_status) => { console.log("entered publish",motor_id,motor_stop_status) const deviceTopic = `water/operation/${motor_id}`; // Target specific IoT + console.log(deviceTopic,"deviceTopic") const payload = { topic: 'operation', object: {