|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
//const Tank = require("../models/tanks");
|
|
|
|
|
const { Tank, MotorData, IotData } = require('../models/tanks')
|
|
|
|
|
const { Tank, MotorData, IotData,MotorIot } = require('../models/tanks')
|
|
|
|
|
|
|
|
|
|
const User = require("../models/User");
|
|
|
|
|
const boom = require("boom");
|
|
|
|
@ -1387,6 +1387,7 @@ exports.startUpdateLoop = async (request, reply) => {
|
|
|
|
|
}, updateInterval);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updatewaterlevelsatmidnight = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
// Schedule the task to run every day at 10 seconds past the minute
|
|
|
|
@ -1441,3 +1442,129 @@ 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) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var motor_id = req.body.motor_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_status: "1" } }
|
|
|
|
|
);
|
|
|
|
|
//return update;
|
|
|
|
|
console.log(result)
|
|
|
|
|
reply.send({ status_code: 200});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.motorstatus = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const motor_id = req.params.motor_id;
|
|
|
|
|
console.log(motor_id)
|
|
|
|
|
|
|
|
|
|
const motorInfo = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
|
|
|
|
|
|
console.log(motorInfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//return update;
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200,status:motorInfo.motor_status});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.motorspeed = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const motor_id = req.body.motor_id;
|
|
|
|
|
const speed = req.body.speed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ motor_id: motor_id },
|
|
|
|
|
{ $set: { motor_speed: speed } }
|
|
|
|
|
);
|
|
|
|
|
//return update;
|
|
|
|
|
console.log(result)
|
|
|
|
|
reply.send({ status_code: 200});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.motortemperature = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const motor_id = req.params.motor_id;
|
|
|
|
|
console.log(motor_id)
|
|
|
|
|
|
|
|
|
|
const motorInfo = await Tank.findOne({ motor_id: motor_id });
|
|
|
|
|
|
|
|
|
|
console.log(motorInfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//return update;
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200,temperature:motorInfo.motor_temperfature});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|