|
|
|
@ -2238,6 +2238,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 () => {
|
|
|
|
@ -2288,6 +2325,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.");
|
|
|
|
|
}
|
|
|
|
|