automation of motor switch test2

master
varun 1 year ago
parent 276725ca11
commit 804f3a134c

@ -1043,7 +1043,7 @@ const motorActionAuto = async (req, reply) => {
$set: {
"connections.inputConnections.$.motor_stop_status": "2",
"connections.inputConnections.$.startTime": req.body.startTime,
"connections.inputConnections.$.motor)on_type": "auto",
"connections.inputConnections.$.motor_on_type": "auto",
}
}
@ -1083,40 +1083,45 @@ const checkAutoMode = async () => {
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(inputConnection.auto_min_percentage, 10);
const autoMaxPercentage = parseInt(inputConnection.auto_max_percentage, 10);
const waterLevel = parseFloat(tank.waterlevel.replace(/,/g, ''));
const capacity = parseFloat(tank.capacity.replace(/,/g, ''));
const autoMinPercentage = parseFloat(tank.auto_min_percentage);
const autoMaxPercentage = parseFloat(tank.auto_max_percentage);
console.log(waterLevel,capacity,autoMinPercentage,autoMaxPercentage)
if (isNaN(waterLevel) || isNaN(capacity) || capacity === 0) {
console.error(`Invalid water level or capacity for tank: ${tank.tankName}`);
continue; // Skip this tank if the values are not valid
}
const currentPercentage = (waterLevel / capacity) * 100;
console.log("This is automation percentage: " + currentPercentage);
const now = moment().format('DD-MMM-YYYY-HH-mm');
if (capacity > 0) {
if (currentPercentage <= autoMinPercentage) {
await motorActionAuto({
params: { customerId: tank.customerId },
body: {
action: "start",
motor_id: inputConnection.motor_id,
motor_on_type: "auto",
startTime: now
}
}, {
code: (statusCode) => ({ send: (response) => console.log(response) })
});
} else if (currentPercentage >= autoMaxPercentage && inputConnection.motor_on_type === "auto") {
await motorActionAuto({
params: { customerId: tank.customerId },
body: {
action: "stop",
motor_id: inputConnection.motor_id,
motor_on_type: "auto",
stopTime: now
}
}, {
code: (statusCode) => ({ send: (response) => console.log(response) })
});
}
const now = moment().format('DD-MMM-YYYY - HH:mm');
console.log(now)
if (currentPercentage <= autoMinPercentage) {
await motorActionAuto({
params: { customerId: tank.customerId },
body: {
action: "start",
motor_id: inputConnection.motor_id,
motor_on_type: "auto",
startTime: now
}
}, {
code: (statusCode) => ({ send: (response) => console.log(response) })
});
} else if (currentPercentage >= autoMaxPercentage && inputConnection.motor_on_type === "auto") {
await motorActionAuto({
params: { customerId: tank.customerId },
body: {
action: "stop",
motor_id: inputConnection.motor_id,
motor_on_type: "auto",
stopTime: now
}
}, {
code: (statusCode) => ({ send: (response) => console.log(response) })
});
}
}
}
@ -1134,6 +1139,7 @@ setInterval(checkAutoMode, 15000);
// exports.calculateCapacity = async (req, reply) => {
// try {
// const shape = req.body.shape

Loading…
Cancel
Save