ashok 2 years ago
commit b990578d87

@ -1482,13 +1482,20 @@ exports.readMotorStatus = async (req, reply) => {
try {
const motor_id = req.query.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_status: status } }
);
reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` });
} catch (err) {

@ -583,7 +583,7 @@ module.exports = function (fastify, opts, next) {
required: ['motor_id', 'status'],
properties: {
motor_id: { type: 'string' },
status: { type: 'string', enum: ['on', 'off'] },
status: { type: 'string'},
current: { type: 'string' },
temp: { type: 'string' },
},
@ -610,6 +610,8 @@ module.exports = function (fastify, opts, next) {
},
// required: ['motor_id'],
},
},
handler: tanksController.readMotorStatus

Loading…
Cancel
Save