|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
//const Tank = require("../models/tanks");
|
|
|
|
|
const { Tank, MotorData, IotData,MotorIot } = require('../models/tanks')
|
|
|
|
|
const { Tank, MotorData, IotData,MotorIot,TankWaterLevel } = require('../models/tanks')
|
|
|
|
|
|
|
|
|
|
const User = require("../models/User");
|
|
|
|
|
const boom = require("boom");
|
|
|
|
@ -2373,3 +2373,28 @@ exports.update_auto_percentage = async (req, reply) => {
|
|
|
|
|
throw boom.boomify(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//storing water level for every 15 minutes
|
|
|
|
|
|
|
|
|
|
const storeWaterLevels = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const tanks = await Tank.find({});
|
|
|
|
|
const currentTime = new Date().toISOString();
|
|
|
|
|
|
|
|
|
|
const waterLevelRecords = tanks.map(tank => ({
|
|
|
|
|
customerId: tank.customerId,
|
|
|
|
|
tankName: tank.tankName,
|
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
|
waterlevel: tank.waterlevel,
|
|
|
|
|
time: currentTime
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
await TankWaterLevel.insertMany(waterLevelRecords);
|
|
|
|
|
console.log('Water levels stored successfully');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error storing water levels:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
setInterval(storeWaterLevels, 15 * 60 * 1000); // Run every 15 minutes
|
|
|
|
|