automation of motor switch test2

master
varun 1 year ago
parent e5e691c37b
commit 276725ca11

@ -1075,20 +1075,20 @@ const motorActionAuto = async (req, reply) => {
};
const checkAutoMode = async () => {
try {
const tanks = await Tank.find();
for (const tank of tanks) {
if (tank.auto_mode === "active") {
console.log("this is automation " + tank.tankName)
for (const inputConnection of tank.connections.inputConnections) {
if (inputConnection.auto_mode === "active") {
console.log("This is automation for tank: " + tank.tankName);
const waterLevel = parseInt(tank.waterlevel, 10);
const capacity = parseInt(tank.capacity, 10);
const autoMinPercentage = parseInt(tank.auto_min_percentage, 10);
const autoMaxPercentage = parseInt(tank.auto_max_percentage, 10);
const autoMinPercentage = parseInt(inputConnection.auto_min_percentage, 10);
const autoMaxPercentage = parseInt(inputConnection.auto_max_percentage, 10);
const currentPercentage = (waterLevel / capacity) * 100;
console.log("this is automation percentage " + currentPercentage)
console.log("This is automation percentage: " + currentPercentage);
const now = moment().format('DD-MMM-YYYY-HH-mm');
if (capacity > 0) {
@ -1097,19 +1097,19 @@ const checkAutoMode = async () => {
params: { customerId: tank.customerId },
body: {
action: "start",
motor_id: tank.connections.inputConnections[0].motor_id,
motor_id: inputConnection.motor_id,
motor_on_type: "auto",
startTime: now
}
}, {
code: (statusCode) => ({ send: (response) => console.log(response) })
});
} else if (currentPercentage >= autoMaxPercentage && tank.connections.inputConnections[0].motor_on_type === "auto") {
} else if (currentPercentage >= autoMaxPercentage && inputConnection.motor_on_type === "auto") {
await motorActionAuto({
params: { customerId: tank.customerId },
body: {
action: "stop",
motor_id: tank.connections.inputConnections[0].motor_id,
motor_id: inputConnection.motor_id,
motor_on_type: "auto",
stopTime: now
}
@ -1120,6 +1120,7 @@ const checkAutoMode = async () => {
}
}
}
}
} catch (err) {
console.error("Error checking auto mode:", err);
}

Loading…
Cancel
Save