master^2
Bhaskar 6 months ago
parent b576a853df
commit a0c6014a79

@ -1007,10 +1007,16 @@ exports.getMasterSlaveSummary = async (req, reply) => {
// Update connection status and timestamps // Update connection status and timestamps
const updateStatusPromises = allDevices.map(async device => { const updateStatusPromises = allDevices.map(async device => {
const hwId = device.connected_to; let checkHardwareId = device.hardwareId?.trim();
if (!hwId) return; if (!checkHardwareId) return;
const latestData = await IotData.findOne({ hardwareId: hwId }) // For slave, check connection via master's hardwareId (i.e., connected_to)
if (device.type === 'slave') {
checkHardwareId = device.connected_to?.trim();
if (!checkHardwareId) return;
}
const latestData = await IotData.findOne({ hardwareId: checkHardwareId })
.sort({ date: -1 }) .sort({ date: -1 })
.lean(); .lean();
@ -1043,7 +1049,6 @@ exports.getMasterSlaveSummary = async (req, reply) => {
device.connected_lora_time = time; device.connected_lora_time = time;
} }
} }
} }
updateFields.connected_status = status; updateFields.connected_status = status;

Loading…
Cancel
Save