@ -1583,7 +1583,7 @@ eventEmitter.on(
const message =
` Tank Name: ' ${ tankName } ' \n ` +
` Pump started at: ' ${ startTime } ' \n ` +
` Initiated by user(s) : ${ userNames } \n ` +
` Initiated by : ${ userNames } \n ` +
` Pump started by: ' ${ motorOnType . toUpperCase ( ) } ' \n ` +
` Will stop at after: ' ${ manual _threshold _time } ' mins ` ;
@ -1609,7 +1609,7 @@ eventEmitter.on('motorStop', async (fcmTokens, tankName,stopTime, motorOnType)
const message =
` Tank Name: ' ${ tankName } ' \n ` +
` Pump stopped at: ' ${ stopTime } ' \n ` +
` Initiated by user(s) : ${ userNames } \n ` +
` Initiated by : ${ userNames } \n ` +
` Motor On Type: ' ${ motorOnType } ' ` ;
// Send the notification
@ -2183,7 +2183,7 @@ console.log(fcmToken)
const blockName = req . body . from || "Unknown Block" ; // Provide a fallback if `from` is missing
const tankName = req . body . to || "Unknown Tank" ; // Provide a fallback if `to` is missing
const stopTime = req . body . stopTime
const motorOnType = req . body . motor _on _type || "A pp ";
const motorOnType = req . body . motor _on _type || "A PP ";
const manual _threshold _time = req . body . manual _threshold _time ;
if ( action === "start" ) {
@ -2206,7 +2206,7 @@ console.log(fcmToken)
motorIntervals [ motorId ] = setTimeout ( async ( ) => {
try {
// Perform threshold time logic (e.g., notification, motor stop)
console . log ( ` Threshold time of ${ manual ThresholdT ime} minutes reached for motor ${ motorId } ` ) ;
console . log ( ` Threshold time of ${ manual _threshold _t ime} minutes reached for motor ${ motorId } ` ) ;
await Tank . updateOne (
{ customerId , "connections.inputConnections.motor_id" : motorId } ,
{ $set : { "connections.inputConnections.$.motor_stop_status" : "1" } }
@ -2243,6 +2243,43 @@ console.log(fcmToken)
"connections.inputConnections.$.threshold_type" : "time" } }
) ;
await Tank . updateOne (
{ customerId , "connections.inputConnections.motor_id" : motorId } ,
{
$set : {
"connections.inputConnections.$.motor_stop_status" : "2" ,
"connections.inputConnections.$.motor_on_type" : "manual" ,
}
}
) ;
// const startMessage = `Motor supplying water to '${tankName}' in block '${blockName}' started manually at ${startTime}.`;
// eventEmitter.emit('sendMotorStartNotification', fcmToken, startMessage);
// Schedule threshold check
// const thresholdTimeMs = manual_threshold_time * 60 * 1000;
motorIntervals [ motorId ] = setTimeout ( async ( ) => {
try {
// const stopMessage = `Threshold time of ${manual_threshold_time} minutes reached for motor supplying water to '${tankName}' in block '${blockName}'.`;
// eventEmitter.emit('sendThresholdTimeNotification', fcmToken, stopMessage);
await Tank . updateOne (
{ customerId , "connections.inputConnections.motor_id" : motorId } ,
{
$set : {
"connections.inputConnections.$.motor_stop_status" : "1" ,
"connections.inputConnections.$.manual_threshold_time" : null ,
"connections.inputConnections.$.threshold_type" : null ,
}
}
) ;
delete motorIntervals [ motorId ] ;
} catch ( error ) {
console . error ( "Error during threshold handling:" , error ) ;
}
} , thresholdTimeMs ) ;
reply . code ( 200 ) . send ( { message : "Motor started successfully." } ) ;
// Schedule water level checks after motor start
motorIntervals [ motorId ] = setInterval ( async ( ) => {
@ -2279,6 +2316,25 @@ console.log(fcmToken)
stopTime ,
motorOnType
) ;
await Tank . updateOne (
{ customerId , "connections.inputConnections.motor_id" : motorId } ,
{
$set : {
"connections.inputConnections.$.motor_stop_status" : "1" ,
"connections.inputConnections.$.motor_on_type" : "manual" ,
}
}
) ;
// const stopMessage = `Motor supplying water to '${tankName}' in block '${blockName}' stopped manually at ${stopTime}.`;
// eventEmitter.emit('sendMotorStopNotification', fcmToken, stopMessage);
if ( motorIntervals [ motorId ] ) {
clearTimeout ( motorIntervals [ motorId ] ) ;
delete motorIntervals [ motorId ] ;
}
} else {
throw new Error ( "Invalid action provided." ) ;
}