|
|
|
@ -1972,9 +1972,12 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
}
|
|
|
|
|
// Determine the motor stop status based on the action
|
|
|
|
|
let motorStopStatus;
|
|
|
|
|
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 || new Date().toISOString();
|
|
|
|
|
const motorOnType = req.body.motor_on_type || "manual";
|
|
|
|
|
if (action === "start") {
|
|
|
|
|
const startTime = req.body.startTime;
|
|
|
|
|
const motorOnType = req.body.motor_on_type || "manual";
|
|
|
|
|
const stopCriteria =
|
|
|
|
|
motorOnType === "time"
|
|
|
|
|
? `${req.body.manual_threshold_time} minutes`
|
|
|
|
@ -1986,14 +1989,13 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
new Date().toISOString(),
|
|
|
|
|
motorId,
|
|
|
|
|
currentWaterLevel,
|
|
|
|
|
req.body.from, // Block Name
|
|
|
|
|
req.body.to, // Tank Name
|
|
|
|
|
blockName, // Block Name
|
|
|
|
|
tankName, // Tank Name
|
|
|
|
|
startTime,
|
|
|
|
|
motorOnType,
|
|
|
|
|
stopCriteria
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Add any additional logic for starting the motor here
|
|
|
|
|
await Tank.updateOne(
|
|
|
|
|
{ customerId, "connections.inputConnections.motor_id": motorId },
|
|
|
|
|
{ $set: { "connections.inputConnections.$.motor_stop_status": "2" } }
|
|
|
|
@ -2002,7 +2004,16 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
|
reply.code(200).send({ message: "Motor started successfully." });
|
|
|
|
|
} else if (action === "stop") {
|
|
|
|
|
motorStopStatus = "1"; // If action is stop, set stop status to "1"
|
|
|
|
|
// eventEmitter.emit('motorStop', fcmToken, motorId, currentWaterLevel,blockName, tankName,stopTime,motorOnType);
|
|
|
|
|
eventEmitter.emit(
|
|
|
|
|
"motorStop",
|
|
|
|
|
fcmToken,
|
|
|
|
|
motorId,
|
|
|
|
|
currentWaterLevel,
|
|
|
|
|
blockName,
|
|
|
|
|
tankName,
|
|
|
|
|
stopTime,
|
|
|
|
|
motorOnType
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error("Invalid action provided.");
|
|
|
|
|
}
|
|
|
|
|