|
|
@ -1346,7 +1346,7 @@ exports.totalwaterLevelSum = async (request, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
const result = waterlevelSum[0]?.totalWaterlevel ?? 0;
|
|
|
|
const result = waterlevelSum[0]?totalWaterlevel : 0;
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ waterlevelSum: result });
|
|
|
|
reply.send({ waterlevelSum: result });
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1445,48 +1445,28 @@ exports.deletemotordatarecordsbefore7days = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.startmotoriot = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
var motor_id = req.body.motor_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
|
|
|
{ $set: { motor_status: "2" } }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
//return update;
|
|
|
|
|
|
|
|
console.log(result)
|
|
|
|
|
|
|
|
reply.send({ status_code: 200});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.stopmotoriot = async (req, reply) => {
|
|
|
|
exports.motorstatus = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
var motor_id = req.body.motor_id;
|
|
|
|
const motor_id = req.params.motor_id;
|
|
|
|
|
|
|
|
console.log(motor_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const motorInfo = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(motorInfo)
|
|
|
|
|
|
|
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
|
|
|
{ $set: { motor_status: "1" } }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
//return update;
|
|
|
|
//return update;
|
|
|
|
console.log(result)
|
|
|
|
|
|
|
|
reply.send({ status_code: 200});
|
|
|
|
reply.send({ status_code: 200,status:motorInfo.motor_status});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1497,51 +1477,70 @@ exports.stopmotoriot = async (req, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.readMotorStatus = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const motor_id = req.query.motor_id;
|
|
|
|
|
|
|
|
|
|
|
|
exports.motorstatus = async (req, reply) => {
|
|
|
|
// Perform any necessary logic based on action (1: Start, 2: Stop)
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
// For example, you can update a database or trigger an action
|
|
|
|
const motor_id = req.params.motor_id;
|
|
|
|
|
|
|
|
console.log(motor_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const motorInfo = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
const motorInfo = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
|
|
|
|
const motor_status = motorInfo.motor_status
|
|
|
|
|
|
|
|
|
|
|
|
console.log(motorInfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//return update;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200,status:motorInfo.motor_status});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, motor_status:motor_status });
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.writeMotorStatus = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { motor_id, status, current, temp } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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" } }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` });
|
|
|
|
catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.motorspeed = async (req, reply) => {
|
|
|
|
exports.changeMotorStatus = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const motor_id = req.body.motor_id;
|
|
|
|
const motor_id = req.body.motor_id;
|
|
|
|
const speed = req.body.speed;
|
|
|
|
const action =req.body.action
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
|
|
|
{ $set: { motor_speed: speed } }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
//return update;
|
|
|
|
|
|
|
|
console.log(result)
|
|
|
|
|
|
|
|
reply.send({ status_code: 200});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
|
|
|
{ $set: { motor_status: action } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200});
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -1567,57 +1566,4 @@ exports.motortemperature = async (req, reply) => {
|
|
|
|
catch (err) {
|
|
|
|
catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.readMotorStatus = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { motor_id, action } = request.query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tank = await Tank.findOne({ motor_id });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tank) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ error: 'Tank not found' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (action === '1') {
|
|
|
|
|
|
|
|
tank.motor_status = '1';
|
|
|
|
|
|
|
|
} else if (action === '2') {
|
|
|
|
|
|
|
|
tank.motor_status = '0';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return reply.code(400).send({ error: 'Invalid action' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await tank.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tank;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
request.log.error(error);
|
|
|
|
|
|
|
|
return reply.code(500).send({ error: 'Internal Server Error' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.writeMotorStatus = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { motor_id, status, current, temp } = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tank = await Tank.findOne({ motor_id });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tank) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ error: 'Tank not found' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tank.motor_status = status;
|
|
|
|
|
|
|
|
tank.motor_temperature = temp || tank.motor_temperature;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await tank.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tank;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
request.log.error(error);
|
|
|
|
|
|
|
|
return reply.code(500).send({ error: 'Internal Server Error' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|