|
|
|
@ -1502,10 +1502,11 @@ exports.readMotorStatusFromIot = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const motor_status = motorInfo.motor_status;
|
|
|
|
|
const motor_stop_status = motorInfo.motor_stop_status;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, motor_status:motor_status });
|
|
|
|
|
reply.send({ status_code: 200, motor_status:motor_status ,motor_stop_status:motor_stop_status});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
@ -1573,6 +1574,7 @@ exports.writeMotorStatus = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.changeMotorStatus = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const motor_id = req.body.motor_id;
|
|
|
|
@ -1595,12 +1597,33 @@ exports.changeMotorStatus = async (req, reply) => {
|
|
|
|
|
motor_stop_status: action,
|
|
|
|
|
motor_status: updatedMotor.motor_status // Assuming motor_status is a field in your Tank model
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Schedule a check for motor_status after 2 minutes
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
try {
|
|
|
|
|
// Fetch the motor_status again
|
|
|
|
|
const finalMotor = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
|
|
|
|
|
|
// Check if motor_status is different from motor_stop_status
|
|
|
|
|
if (finalMotor && finalMotor.motor_status !== finalMotor.motor_stop_status) {
|
|
|
|
|
// If they are different, update motor_stop_status to motor_status
|
|
|
|
|
await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_stop_status: finalMotor.motor_status } }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error in setTimeout:", error);
|
|
|
|
|
}
|
|
|
|
|
}, 2 * 60 * 1000); // 2 minutes in milliseconds
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.motortemperature = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|