master^2
Varun 5 months ago
parent b386899f6a
commit c337761d0b

@ -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) {

@ -64,6 +64,8 @@ const tanksSchema = new mongoose.Schema({
notificationSentHigh: { type: Boolean }, notificationSentHigh: { type: Boolean },
all_motor_status: { type: Boolean }, all_motor_status: { type: Boolean },
status:{ type: String, default: "active" }, status:{ type: String, default: "active" },
slave_status:{ type: String, default: "working" },
slave_disconnected_time :{ type: String, default: null },
connections: { connections: {
source: { type: String }, source: { type: String },

Loading…
Cancel
Save