changes in read and write motor

master
varun 2 years ago
parent 60c109710d
commit 5ad517d682

@ -1481,14 +1481,21 @@ exports.motorstatus = async (req, reply) => {
exports.readMotorStatus = async (req, reply) => { exports.readMotorStatus = async (req, reply) => {
try { 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) // Perform any necessary logic based on action (1: Start, 2: Stop)
// For example, you can update a database or trigger an action // For example, you can update a database or trigger an action
const motorInfo = await Tank.findOne({ motor_id: motor_id }); const motorInfo = await Tank.findOne({motor_id : motor_id });
const motor_status = motorInfo.motor_status
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 }); 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 // For example, update a database with the new status, current, and temp values
let result; let result;
if (status === 'on') { result = await Tank.findOneAndUpdate(
result = await Tank.findOneAndUpdate( { motor_id: motor_id },
{ motor_id: motor_id }, { $set: { motor_stop_status: "1" } }
{ $set: { motor_status: "2" } } );
);
} else if (status === 'off') {
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}` }); reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` });
} catch (err) { } catch (err) {

Loading…
Cancel
Save