read motor_status changed to motor_stop_status

master
varun 2 years ago
parent 910ff604df
commit c85c87ca72

@ -1474,11 +1474,11 @@ exports.readMotorStatus = async (req, reply) => {
return reply.status(404).send({ status_code: 404, message: 'Tank not found for the specified motor_id' });
}
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_stop_status:motor_stop_status });
} catch (err) {
throw boom.boomify(err);
}
@ -1520,21 +1520,25 @@ exports.writeMotorStatus = async (req, reply) => {
exports.changeMotorStatus = async (req, reply) => {
try {
const motor_id = req.body.motor_id;
const action =req.body.action
const action = req.body.action;
// Perform any necessary logic to handle motor status update from the device
// For example, update a database with the new status, current, and temp values
const result = await Tank.findOneAndUpdate(
{ motor_id: motor_id },
{ $set: { motor_stop_status: action }
});
const result = await Tank.findOneAndUpdate(
{ motor_id: motor_id },
{ $set: { motor_stop_status: action } });
// Fetch the motor_status for the given motor_id
const updatedMotor = await Tank.findOne({ motor_id: motor_id });
reply.send({ status_code: 200,motor_stop_status: action });
// Send the response with motor_stop_status and motor_status
reply.send({
status_code: 200,
motor_stop_status: action,
motor_status: updatedMotor.motor_status // Assuming motor_status is a field in your Tank model
});
} catch (err) {
throw boom.boomify(err);
}

Loading…
Cancel
Save