diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 0110fa94..c122ddfb 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1175,6 +1175,10 @@ exports.calculateCapacity = async (req, reply) => { // reply.code(500).send({ error: err.message }); // } // }; + + + + exports.IotDevice = async (req, reply) => { try { const { hardwareId, mode, tanks } = req.body; @@ -1222,7 +1226,8 @@ exports.IotDevice = async (req, reply) => { const tank_height = parseInt(existingTank.height.replace(/,/g, ''), 10) * 30.48; const water_level_height = tank_height - tankHeight; const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10); - const water_level = water_level_height * waterCapacityPerCm; + let water_level = water_level_height * waterCapacityPerCm; + water_level = Math.round(water_level); // Round to nearest whole number existingTank.waterlevel = water_level.toString(); // Convert to string as per schema definition // Save the updated tank document @@ -1259,6 +1264,8 @@ exports.IotDevice = async (req, reply) => { } }; + + // exports.getIotD = async(req, reply) => { // try { // await IotData.find({hardwareId: req.query.hardwareId})