|
|
@ -6147,9 +6147,23 @@ async function processIotData(hw_Id, data) {
|
|
|
|
const waterLevel = parseInt(waterLevelHeight * waterCapacityPerCm, 10);
|
|
|
|
const waterLevel = parseInt(waterLevelHeight * waterCapacityPerCm, 10);
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`🚰 Tank [${tankhardwareId}] - Level: ${tankHeight}, Calculated Water Level: ${waterLevel}`);
|
|
|
|
console.log(`🚰 Tank [${tankhardwareId}] - Level: ${tankHeight}, Calculated Water Level: ${waterLevel}`);
|
|
|
|
|
|
|
|
if (tankHeight <= 0) {
|
|
|
|
|
|
|
|
if (existingTank.slave_status !== "not_working") {
|
|
|
|
|
|
|
|
const disconnectedTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm:ss');
|
|
|
|
|
|
|
|
existingTank.slave_status = "not_working";
|
|
|
|
|
|
|
|
existingTank.slave_disconnected_time = disconnectedTime;
|
|
|
|
|
|
|
|
await existingTank.save();
|
|
|
|
|
|
|
|
console.log(`⚠️ Slave disconnected for tank [${tankhardwareId}] at ${disconnectedTime}`);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.log(`⏩ Slave already marked as not_working for tank [${tankhardwareId}], skipping update.`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tankHeight > 0 && waterLevel >= 0) {
|
|
|
|
if (tankHeight > 0 && waterLevel >= 0) {
|
|
|
|
existingTank.waterlevel = waterLevel;
|
|
|
|
existingTank.waterlevel = waterLevel;
|
|
|
|
|
|
|
|
existingTank.slave_status = "working";
|
|
|
|
|
|
|
|
existingTank.slave_disconnected_time = null;
|
|
|
|
await existingTank.save();
|
|
|
|
await existingTank.save();
|
|
|
|
|
|
|
|
|
|
|
|
for (const outputConnection of existingTank.connections.outputConnections) {
|
|
|
|
for (const outputConnection of existingTank.connections.outputConnections) {
|
|
|
|