automation of motor switch test2

master
varun 1 year ago
parent 276725ca11
commit 804f3a134c

@ -1043,7 +1043,7 @@ const motorActionAuto = async (req, reply) => {
$set: { $set: {
"connections.inputConnections.$.motor_stop_status": "2", "connections.inputConnections.$.motor_stop_status": "2",
"connections.inputConnections.$.startTime": req.body.startTime, "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) { for (const inputConnection of tank.connections.inputConnections) {
if (inputConnection.auto_mode === "active") { if (inputConnection.auto_mode === "active") {
console.log("This is automation for tank: " + tank.tankName); console.log("This is automation for tank: " + tank.tankName);
const waterLevel = parseInt(tank.waterlevel, 10); const waterLevel = parseFloat(tank.waterlevel.replace(/,/g, ''));
const capacity = parseInt(tank.capacity, 10); const capacity = parseFloat(tank.capacity.replace(/,/g, ''));
const autoMinPercentage = parseInt(inputConnection.auto_min_percentage, 10); const autoMinPercentage = parseFloat(tank.auto_min_percentage);
const autoMaxPercentage = parseInt(inputConnection.auto_max_percentage, 10); 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; 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'); const now = moment().format('DD-MMM-YYYY - HH:mm');
console.log(now)
if (capacity > 0) { if (currentPercentage <= autoMinPercentage) {
if (currentPercentage <= autoMinPercentage) { await motorActionAuto({
await motorActionAuto({ params: { customerId: tank.customerId },
params: { customerId: tank.customerId }, body: {
body: { action: "start",
action: "start", motor_id: inputConnection.motor_id,
motor_id: inputConnection.motor_id, motor_on_type: "auto",
motor_on_type: "auto", startTime: now
startTime: now }
} }, {
}, { code: (statusCode) => ({ send: (response) => console.log(response) })
code: (statusCode) => ({ send: (response) => console.log(response) }) });
}); } else if (currentPercentage >= autoMaxPercentage && inputConnection.motor_on_type === "auto") {
} else if (currentPercentage >= autoMaxPercentage && inputConnection.motor_on_type === "auto") { await motorActionAuto({
await motorActionAuto({ params: { customerId: tank.customerId },
params: { customerId: tank.customerId }, body: {
body: { action: "stop",
action: "stop", motor_id: inputConnection.motor_id,
motor_id: inputConnection.motor_id, motor_on_type: "auto",
motor_on_type: "auto", stopTime: now
stopTime: now }
} }, {
}, { code: (statusCode) => ({ send: (response) => console.log(response) })
code: (statusCode) => ({ send: (response) => console.log(response) }) });
});
}
} }
} }
} }
@ -1134,6 +1139,7 @@ setInterval(checkAutoMode, 15000);
// exports.calculateCapacity = async (req, reply) => { // exports.calculateCapacity = async (req, reply) => {
// try { // try {
// const shape = req.body.shape // const shape = req.body.shape

Loading…
Cancel
Save