master^2
Bhaskar 6 months ago
parent c1e7f54d5d
commit c1a971879b

@ -1952,7 +1952,6 @@ exports.getIotDataByCustomer = async (req, reply) => {
const masterHardwareIds = [
...new Set(sensors.map(s => s.connected_to?.trim()).filter(Boolean))
];
const enrichedMasters = await Promise.all(masterHardwareIds.map(async (hardwareId) => {
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);
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 loraDiff = now.diff(tankTime, "minutes");
loraConnected = loraDiff <= 1;
loraMessage = loraConnected ? "LORA is connected" : "LORA is not connected";
}
return {
@ -1993,7 +1996,7 @@ exports.getIotDataByCustomer = async (req, reply) => {
tankLocation: slave.tankLocation ?? null,
masterName: slave.masterName ?? null,
location: slave.location ?? null,
loraMessage: loraConnected ? "LORA is connected" : "LORA is not connected",
loraMessage, // Updated LoRa message
latestTankData: matchedTank ?? null
};
});
@ -2010,6 +2013,7 @@ exports.getIotDataByCustomer = async (req, reply) => {
};
}));
return reply.send({
status_code: 200,
message: "Success",

Loading…
Cancel
Save