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