|
|
@ -1952,7 +1952,6 @@ exports.getIotDataByCustomer = async (req, reply) => {
|
|
|
|
const masterHardwareIds = [
|
|
|
|
const masterHardwareIds = [
|
|
|
|
...new Set(sensors.map(s => s.connected_to?.trim()).filter(Boolean))
|
|
|
|
...new Set(sensors.map(s => s.connected_to?.trim()).filter(Boolean))
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const enrichedMasters = await Promise.all(masterHardwareIds.map(async (hardwareId) => {
|
|
|
|
const enrichedMasters = await Promise.all(masterHardwareIds.map(async (hardwareId) => {
|
|
|
|
const latestRecord = await IotData.findOne({ hardwareId }).sort({ date: -1 }).lean();
|
|
|
|
const latestRecord = await IotData.findOne({ hardwareId }).sort({ date: -1 }).lean();
|
|
|
|
|
|
|
|
|
|
|
@ -1981,10 +1980,14 @@ exports.getIotDataByCustomer = async (req, reply) => {
|
|
|
|
const matchedTank = latestRecord.tanks.find(tank => tank.tankhardwareId === slaveId);
|
|
|
|
const matchedTank = latestRecord.tanks.find(tank => tank.tankhardwareId === slaveId);
|
|
|
|
|
|
|
|
|
|
|
|
let loraConnected = false;
|
|
|
|
let loraConnected = false;
|
|
|
|
if (matchedTank?.date) {
|
|
|
|
let loraMessage = "LORA is not connected"; // Default message for LoRa not connected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If matchedTank exists and tankHeight is not zero, check LoRa connection
|
|
|
|
|
|
|
|
if (matchedTank?.date && matchedTank.tankHeight !== "0") {
|
|
|
|
const tankTime = moment.tz(matchedTank.date, "Asia/Kolkata");
|
|
|
|
const tankTime = moment.tz(matchedTank.date, "Asia/Kolkata");
|
|
|
|
const loraDiff = now.diff(tankTime, "minutes");
|
|
|
|
const loraDiff = now.diff(tankTime, "minutes");
|
|
|
|
loraConnected = loraDiff <= 1;
|
|
|
|
loraConnected = loraDiff <= 1;
|
|
|
|
|
|
|
|
loraMessage = loraConnected ? "LORA is connected" : "LORA is not connected";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
@ -1993,7 +1996,7 @@ exports.getIotDataByCustomer = async (req, reply) => {
|
|
|
|
tankLocation: slave.tankLocation ?? null,
|
|
|
|
tankLocation: slave.tankLocation ?? null,
|
|
|
|
masterName: slave.masterName ?? null,
|
|
|
|
masterName: slave.masterName ?? null,
|
|
|
|
location: slave.location ?? null,
|
|
|
|
location: slave.location ?? null,
|
|
|
|
loraMessage: loraConnected ? "LORA is connected" : "LORA is not connected",
|
|
|
|
loraMessage, // Updated LoRa message
|
|
|
|
latestTankData: matchedTank ?? null
|
|
|
|
latestTankData: matchedTank ?? null
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -2010,6 +2013,7 @@ exports.getIotDataByCustomer = async (req, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
return reply.send({
|
|
|
|
status_code: 200,
|
|
|
|
status_code: 200,
|
|
|
|
message: "Success",
|
|
|
|
message: "Success",
|
|
|
|