|
|
|
@ -6225,23 +6225,23 @@ async function processIotData(hw_Id, data) {
|
|
|
|
|
// First time signal is lost
|
|
|
|
|
existingTank.slave_status = "signal_lost1";
|
|
|
|
|
|
|
|
|
|
// Only set signal lost time if it doesn't exist
|
|
|
|
|
if (!existingTank.slave_signal_lost_time) {
|
|
|
|
|
existingTank.slave_signal_lost_time = now.format('DD-MMM-YYYY - HH:mm:ss');
|
|
|
|
|
console.log(`⚠️ Signal lost for tank [${tankhardwareId}] at ${existingTank.slave_signal_lost_time}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await existingTank.save();
|
|
|
|
|
|
|
|
|
|
} else if (existingTank.slave_status === "signal_lost1") {
|
|
|
|
|
const lostTime = moment(existingTank.slave_signal_lost_time, 'DD-MMM-YYYY - HH:mm:ss');
|
|
|
|
|
const minutesElapsed = now.diff(lostTime, 'minutes');
|
|
|
|
|
console.log(`⏳ ${minutesElapsed} min since signal lost for tank [${tankhardwareId}]`);
|
|
|
|
|
|
|
|
|
|
if (minutesElapsed >= 15) {
|
|
|
|
|
existingTank.slave_status = "not_working";
|
|
|
|
|
existingTank.slave_disconnected_time = now.format('DD-MMM-YYYY - HH:mm:ss');
|
|
|
|
|
await existingTank.save();
|
|
|
|
|
|
|
|
|
|
// Propagate status to output connections
|
|
|
|
|
for (const outputConnection of existingTank.connections.outputConnections) {
|
|
|
|
|
const linkedTank = await Tank.findOne({
|
|
|
|
|
customerId,
|
|
|
|
@ -6260,14 +6260,17 @@ async function processIotData(hw_Id, data) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(`❌ Slave marked as not_working for tank [${tankhardwareId}] at ${existingTank.slave_disconnected_time}`);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`⏳ Still waiting... only ${minutesElapsed} minutes passed for tank [${tankhardwareId}]`);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`⏩ Slave already marked as ${existingTank.slave_status} for tank [${tankhardwareId}], skipping update.`);
|
|
|
|
|
console.log(`⏩ Already in ${existingTank.slave_status}, no update.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tankHeight > 0 && waterLevel >= 0) {
|
|
|
|
|
existingTank.waterlevel = waterLevel;
|
|
|
|
|