|
|
|
@ -1481,14 +1481,21 @@ exports.motorstatus = async (req, reply) => {
|
|
|
|
|
exports.readMotorStatus = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
const motor_id = req.query.motor_id;
|
|
|
|
|
const motor_id = req.body.motor_id;
|
|
|
|
|
console.log(motor_id)
|
|
|
|
|
|
|
|
|
|
// Perform any necessary logic based on action (1: Start, 2: Stop)
|
|
|
|
|
|
|
|
|
|
// For example, you can update a database or trigger an action
|
|
|
|
|
|
|
|
|
|
const motorInfo = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
|
const motor_status = motorInfo.motor_status
|
|
|
|
|
const motorInfo = await Tank.findOne({motor_id : motor_id });
|
|
|
|
|
|
|
|
|
|
if (!motorInfo) {
|
|
|
|
|
return reply.status(404).send({ status_code: 404, message: 'Tank not found for the specified motor_id' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const motor_status = motorInfo.motor_status;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, motor_status:motor_status });
|
|
|
|
@ -1508,17 +1515,10 @@ exports.writeMotorStatus = async (req, reply) => {
|
|
|
|
|
// For example, update a database with the new status, current, and temp values
|
|
|
|
|
let result;
|
|
|
|
|
|
|
|
|
|
if (status === 'on') {
|
|
|
|
|
result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_status: "2" } }
|
|
|
|
|
);
|
|
|
|
|
} else if (status === 'off') {
|
|
|
|
|
result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_stop_status: "1" } }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_stop_status: "1" } }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` });
|
|
|
|
|
} catch (err) {
|
|
|
|
|