automation of motor switch test2

master
varun 1 year ago
parent 380627bf7f
commit cc3fa2531a

@ -1494,23 +1494,26 @@ exports.IotDevice = async (req, reply) => {
const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10); const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10);
const water_level = water_level_height * waterCapacityPerCm; const water_level = water_level_height * waterCapacityPerCm;
existingTank.waterlevel = water_level; if (water_level >= 0) {
existingTank.waterlevel = water_level;
// Save the updated tank document
await existingTank.save(); // Save the updated tank document
await existingTank.save();
// Update linked tanks
for (const outputConnection of existingTank.connections.outputConnections) { // Update linked tanks
const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type }); for (const outputConnection of existingTank.connections.outputConnections) {
if (linkedTank) { const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type });
for (const inputConnection of linkedTank.connections.inputConnections) { if (linkedTank) {
if (inputConnection.inputConnections === tank_name) { for (const inputConnection of linkedTank.connections.inputConnections) {
inputConnection.water_level = water_level; if (inputConnection.inputConnections === tank_name) {
await linkedTank.save(); inputConnection.water_level = water_level;
await linkedTank.save();
}
} }
} }
} }
} }
} }
// Send the latest three documents // Send the latest three documents

Loading…
Cancel
Save