automation of motor switch test2

master
varun 1 year ago
parent e5e691c37b
commit 276725ca11

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

Loading…
Cancel
Save