Bhaskar 7 months ago
commit 5bb68828cb

@ -1572,18 +1572,18 @@ eventEmitter.on('sendCriticalHighWaterNotification', async (fcmTokens, tankInfo,
// }); // });
// eventEmitter.on('sendThresholdTimeNotification', async (customerId, fcmTokens, thresholdTime, hw_Id, tankName, blockName) => { eventEmitter.on('sendThresholdTimeNotification', async (customerId, fcmTokens, thresholdTime, hw_Id, tankName, blockName) => {
// try { try {
// const message = const message =
// `🛢️ Tank Name: '${tankName}'\n` + `🛢️ Tank Name: '${tankName}'\n` +
// `🏢 Block Name: '${blockName}'\n` + `🏢 Block Name: '${blockName}'\n` +
// `Motor Stopped as it completed ${thresholdTime} minutes.`; `Motor Stopped as it completed ${thresholdTime} minutes.`;
// await sendNotification(hw_Id, customerId, fcmTokens, 'Motor Alert', message); await sendNotification(hw_Id, customerId, fcmTokens, 'Motor Alert', message);
// console.log("Threshold time notification sent successfully."); console.log("Threshold time notification sent successfully.");
// } catch (error) { } catch (error) {
// console.error("Error sending threshold time notification:", error); console.error("Error sending threshold time notification:", error);
// } }
// }); });
// eventEmitter.on( // eventEmitter.on(
// 'sendMotorStartNotification', // 'sendMotorStartNotification',
@ -2343,8 +2343,13 @@ cron.schedule("* * * * *", async () => {
// } // }
// }; // };
exports.publishMotorStopStatus = async (motor_id, motor_stop_status) => { 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 deviceTopic = `water/operation/${motor_id}`; // Target specific IoT
console.log(deviceTopic,"deviceTopic")
const payload = { const payload = {
topic: 'operation', topic: 'operation',
object: { object: {
@ -3057,7 +3062,7 @@ exports.motorAction = async (req, reply) => {
receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10) receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10)
}); });
await newMotorData.save(); await newMotorData.save();
console.log("entered time",motorId,motorStopStatus)
// Update the tank connections with start time and threshold time // Update the tank connections with start time and threshold time
for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) {
this.publishMotorStopStatus(motorId, motorStopStatus); this.publishMotorStopStatus(motorId, motorStopStatus);
@ -3104,29 +3109,29 @@ exports.motorAction = async (req, reply) => {
const notificationKey = `${customerId}_${motorId}_threshold`; const notificationKey = `${customerId}_${motorId}_threshold`;
// Check if the notification has already been sent // Check if the notification has already been sent
// if (!notificationTracker.get(notificationKey)) { if (!notificationTracker.get(notificationKey)) {
// console.log("Sending threshold time notification..."); console.log("Sending threshold time notification...");
// eventEmitter.emit( eventEmitter.emit(
// "sendThresholdTimeNotification", "sendThresholdTimeNotification",
// customerId, customerId,
// fcmToken, fcmToken,
// manual_threshold_time, manual_threshold_time,
// motorId, motorId,
// tankName, tankName,
// blockName blockName
// ); );
// // Mark notification as sent // Mark notification as sent
// notificationTracker.set(notificationKey, true); notificationTracker.set(notificationKey, true);
// // Optionally, reset the flag after some time (e.g., 24 hours) // Optionally, reset the flag after some time (e.g., 24 hours)
// setTimeout(() => { setTimeout(() => {
// notificationTracker.delete(notificationKey); notificationTracker.delete(notificationKey);
// }, 24 * 60 * 60 * 1000); // Reset after 24 hours }, 24 * 60 * 60 * 1000); // Reset after 24 hours
// } else { } else {
// console.log("Notification already sent, skipping..."); console.log("Notification already sent, skipping...");
// } }
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
await Tank.updateOne( await Tank.updateOne(

Loading…
Cancel
Save