for null received from iot device

master
varun 1 year ago
parent 38d6d699a7
commit e961f3e1e4

@ -1157,14 +1157,10 @@ exports.IotDevice = async (req, reply) => {
for (const tank of tanks) {
const { tankhardwareId, tankHeight } = tank;
// Skip if tankHeight is null or undefined
if (tankHeight === null || tankHeight === undefined) {
continue; // Skip this iteration and move to the next tank
}
// Find the corresponding tank in tanksSchema
const existingTank = await Tank.findOne({ hardwareId, tankhardwareId });
if (existingTank) {
// Update the waterlevel using the tankHeight value
@ -1203,12 +1199,13 @@ for (const tank of tanks) {
existingTank.waterlevel = parseInt(formatted_water_level.replace(/,/g, ''), 10);
console.log(existingTank.waterlevel);
// Save the updated tank document
await existingTank.save();
}
}
// Send the latest three documents
const latestOttanks = await IotData.find({ hardwareId })
.sort({ date: -1, time: -1 });
@ -1220,7 +1217,6 @@ for (const tank of tanks) {
}
};
// exports.getIotD = async(req, reply) => {
// try {
// await IotData.find({hardwareId: req.query.hardwareId})

Loading…
Cancel
Save