constmessage=`Attention: Water level in '${tankInfo.tankName}' located at '${tankInfo.tankLocation}' is critically high at ${tankInfo.waterLevel}% (${tankInfo.volumeInLitres} L). Water may overflow. Please stop the motor. Motor running from ${startTime} to ${stopTime}.`;
constmessage=`Attention: Water level in '${tankInfo.tankName}' located at '${tankInfo.tankLocation}' is critically high at ${tankInfo.waterLevel}% (${tankInfo.volumeInLitres} L). Water may overflow. Please stop the motor. Motor running from ${startTime} to ${stopTime}.`;
awaitsendNotification(fcmTokens,'Critical High Water Level',message,'Stop Motor');
awaitsendNotification(fcmTokens,'Critical High Water Level',message,'Stop Motor');
// await sendNotification(fcmTokens, 'High Water Level', `Motor ID: ${motorId}, water level reached above 90% at ${timestamp}. Current Water Level: ${waterLevel} Ltrs`);
// await sendNotification(fcmTokens, 'High Water Level', `Motor ID: ${motorId}, water level reached above 90% at ${timestamp}. Current Water Level: ${waterLevel} Ltrs`);
@ -2152,7 +2185,51 @@ console.log(fcmToken)
if(action==="start"){
if(action==="start"){
motorStopStatus="2";
motorStopStatus="2";
conststartTime=req.body.startTime;
conststartMessage=`The motor supplying water to '${tankName}' in block '${blockName}' has started manually at ${newDate().toISOString()}.`;
constthresholdTimeMs=req.body.manual_threshold_time*60*1000;// Convert minutes to milliseconds
//const startTime = new Date(); // Record the start time
conststartTime=req.body.startTime;
// Schedule a task to send a notification when the threshold time is reached
motorIntervals[motorId]=setTimeout(async()=>{
try{
// Fetch the latest tank and motor data
constreceiverTank=awaitTank.findOne({
customerId,
tankName:req.body.to,
tankLocation:req.body.to_type.toLowerCase(),
});
// Send a notification for threshold time reached
constmessage=`Threshold time of ${req.body.manual_threshold_time} minutes has been reached for the motor supplying '${receiverTank.tankName}' located at '${receiverTank.tankLocation}'. Please review the motor operation.`;