|
|
|
@ -1504,29 +1504,37 @@ exports.readMotorStatus = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.writeMotorStatus = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const { motor_id, status, current, temp } = req.body;
|
|
|
|
|
const motor_id = req.body.motor_id;
|
|
|
|
|
const status = req.body.status;
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
let result;
|
|
|
|
|
const existingRecord = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
|
|
|
|
|
|
if (existingRecord && (existingRecord.motor_stop_status === '1' || existingRecord.motor_stop_status === '2')) {
|
|
|
|
|
if (existingRecord.motor_status !== status) {
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_status: status } },
|
|
|
|
|
{ new: true } // To return the updated document
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_status: status } }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` });
|
|
|
|
|
reply.send({ status_code: 200, motor_status: result.motor_status });
|
|
|
|
|
} else {
|
|
|
|
|
reply.send({ status_code: 200, motor_status: status });
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
reply.send({ status_code: 200, message: 'Motor stop status is not "on" or "off".' });
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.changeMotorStatus = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const motor_id = req.body.motor_id;
|
|
|
|
@ -1540,11 +1548,11 @@ exports.changeMotorStatus = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_status: action } });
|
|
|
|
|
{ $set: { motor_stop_status: action } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200,motor_status: action });
|
|
|
|
|
reply.send({ status_code: 200,motor_stop_status: action });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|