ashok 8 months ago
commit 008b8a8805

@ -3254,6 +3254,33 @@ exports.motorAction = async (req, reply) => {
} else if (action === "stop") {
await stopMotor(motorId, customerId, start_instance_id);
this.publishMotorStopStatus(motorId, motorStopStatus);
// Fetch motor data to check its threshold time
const motorData = await Tank.findOne(
{ customerId, "connections.inputConnections.motor_id": motorId },
{ "connections.inputConnections.$": 1 }
);
if (motorData) {
const motor = motorData.connections.inputConnections[0];
const thresholdTime = motor.manual_threshold_time; // Get threshold time
const hw_Id = motor.hw_Id; // Get hardware ID
// Check if motor was running for at least the threshold time
if (motor.runTime >= thresholdTime) {
console.log(`Sending threshold time notification for motor ${motorId}`);
eventEmitter.emit(
"sendThresholdTimeNotification",
customerId,
fcmToken, // Use correct FCM token list
thresholdTime,
hw_Id,
tankName,
blockName
);
}
}
reply.code(200).send({ message: "Motor stopped successfully." });
}
} catch (err) {

Loading…
Cancel
Save