ashok 2 years ago
commit b990578d87

@ -1482,13 +1482,20 @@ exports.readMotorStatus = async (req, reply) => {
try { try {
const motor_id = req.query.motor_id; const motor_id = req.query.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_status: status } }
{ $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) {

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

Loading…
Cancel
Save