made changes in tankscontroller

master
varun 1 year ago
parent 40a07d9ba6
commit 17a2dab2a2

@ -895,9 +895,6 @@ exports.motorAction = async (req, reply) => {
); );
} else { } else {
// Update the motor stop status to "2" for start action // Update the motor stop status to "2" for start action
@ -967,16 +964,13 @@ exports.motorAction = async (req, reply) => {
const supplier_capacity = parseInt(supplier_tank_info.capacity, 10); const supplier_capacity = parseInt(supplier_tank_info.capacity, 10);
const supplier_waterLevel = parseInt(supplier_tank_info.waterlevel, 10); const supplier_waterLevel = parseInt(supplier_tank_info.waterlevel, 10);
const capacity = parseInt(receiver_tank_info.capacity, 10); const capacity = parseInt(receiver_tank_info.capacity, 10);
const waterLevel = parseInt(receiver_tank_info.waterlevel, 10); const waterLevel = parseInt(receiver_tank_info.waterlevel, 10);
const desired_percentage = parseInt(req.body.manual_threshold_litres, 10); const desired_percentage = parseInt(req.body.manual_threshold_litres, 10);
const threshold_water_level = waterLevel+desired_percentage; const threshold_water_level = waterLevel+desired_percentage;
const supplier_threshold = supplier_waterLevel-desired_percentage const supplier_threshold = supplier_waterLevel-desired_percentage
console.log(supplier_threshold,"supplier_threshold")
for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) {
const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId); const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId);
@ -2237,8 +2231,7 @@ exports.writeMotorStatus = async (req, reply) => {
} }
}; };
// exports.writeMotorStatus = async (req, reply) => {
// try {
// const motor_id = req.body.motor_id; // const motor_id = req.body.motor_id;
// const status = req.body.status; // const status = req.body.status;
@ -2402,3 +2395,20 @@ const storeWaterLevels = async () => {
}; };
setInterval(storeWaterLevels, 15 * 60 * 1000); setInterval(storeWaterLevels, 15 * 60 * 1000);
const updateWaterLevelAtMidnight = async () => {
try {
await Tank.updateMany({}, { $set: { waterlevel_at_midnight: '$waterlevel' } });
console.log('Water levels updated at midnight');
} catch (error) {
console.error('Error updating water levels:', error);
}
};
// Schedule the job to run at midnight every day
cron.schedule('0 0 * * *', async () => {
await updateWaterLevelAtMidnight();
});
console.log('Cron job scheduled to update water levels at midnight');
Loading…
Cancel
Save