write motor status for sensor

master
varun 2 years ago
parent 8c7a430ac1
commit 910ff604df

@ -1004,8 +1004,6 @@ exports.consumption = async (req, reply) => {
// } // }
// }; // };
exports.calculateCapacity = async (req, reply) => { exports.calculateCapacity = async (req, reply) => {
try { try {
const shape = req.body.shape; const shape = req.body.shape;
@ -1076,8 +1074,6 @@ exports.calculateCapacity = async (req, reply) => {
} }
}; };
// exports.IotDevice = async (req, reply) => { // exports.IotDevice = async (req, reply) => {
// try { // try {
// const { hardwareId, mode, tanks } = req.body; // const { hardwareId, mode, tanks } = req.body;
@ -1169,7 +1165,6 @@ exports.IotDevice = async (req, reply) => {
const existingTank = await Tank.findOne({ hardwareId, tankhardwareId }); const existingTank = await Tank.findOne({ hardwareId, tankhardwareId });
if (existingTank) { if (existingTank) {
// Update the waterlevel using the tankHeight value // Update the waterlevel using the tankHeight value
@ -1289,8 +1284,6 @@ exports.getLatestData = async (req, reply) => {
}; };
exports.checkStatusofIot = async (req, reply) => { exports.checkStatusofIot = async (req, reply) => {
try { try {
// get a list of unique hardware IDs in the collection // get a list of unique hardware IDs in the collection
@ -1352,8 +1345,6 @@ exports.totalwaterLevelSum = async (request, reply) => {
} }
exports.startUpdateLoop = async (request, reply) => { exports.startUpdateLoop = async (request, reply) => {
const updateInterval = 5000; const updateInterval = 5000;
@ -1420,7 +1411,6 @@ exports.updatewaterlevelsatmidnight = async (req, reply) => {
}; };
exports.deletemotordatarecordsbefore7days = async (req, reply) => { exports.deletemotordatarecordsbefore7days = async (req, reply) => {
try { try {
// Schedule the task to run every day at 10 seconds past the minute // Schedule the task to run every day at 10 seconds past the minute
@ -1443,16 +1433,6 @@ exports.deletemotordatarecordsbefore7days = async (req, reply) => {
}; };
exports.motorstatus = async (req, reply) => { exports.motorstatus = async (req, reply) => {
try { try {
@ -1507,7 +1487,6 @@ exports.readMotorStatus = async (req, reply) => {
exports.writeMotorStatus = async (req, reply) => { exports.writeMotorStatus = async (req, reply) => {
try { try {
const motor_id = req.body.motor_id; const motor_id = req.body.motor_id;
const status = req.body.status;
// Perform any necessary logic to handle motor status update from the device // Perform any necessary logic to handle motor status update from the device
@ -1515,20 +1494,18 @@ exports.writeMotorStatus = async (req, reply) => {
const existingRecord = await Tank.findOne({ motor_id: motor_id }); const existingRecord = await Tank.findOne({ motor_id: motor_id });
if (existingRecord && (existingRecord.motor_stop_status === '1' || existingRecord.motor_stop_status === '2')) { if (existingRecord && (existingRecord.motor_stop_status === '1' || existingRecord.motor_stop_status === '2')) {
if (existingRecord.motor_stop_status === status) { const newMotorStatus = existingRecord.motor_stop_status;
if (existingRecord.motor_status !== status) {
if (existingRecord.motor_status !== newMotorStatus) {
const result = await Tank.findOneAndUpdate( const result = await Tank.findOneAndUpdate(
{ motor_id: motor_id }, { motor_id: motor_id },
{ $set: { motor_status: status } }, { $set: { motor_status: newMotorStatus } },
{ new: true } // To return the updated document { new: true } // To return the updated document
); );
reply.send({ status_code: 200, motor_status: result.motor_status }); reply.send({ status_code: 200, motor_status: result.motor_status });
} else { } else {
reply.send({ status_code: 200, motor_status: status }); reply.send({ status_code: 200, motor_status: newMotorStatus });
}
} else {
reply.send({ status_code: 200, message: 'Status and motor_stop_status are not the same.' });
} }
} else { } else {
reply.send({ status_code: 200, message: 'Motor stop status is not "on" or "off".' }); reply.send({ status_code: 200, message: 'Motor stop status is not "on" or "off".' });
@ -1563,6 +1540,7 @@ exports.changeMotorStatus = async (req, reply) => {
} }
}; };
exports.motortemperature = async (req, reply) => { exports.motortemperature = async (req, reply) => {
try { try {
@ -1585,3 +1563,5 @@ exports.motortemperature = async (req, reply) => {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };

Loading…
Cancel
Save