automation of motor switch test2

master
varun 1 year ago
parent 0062f2fdd1
commit 60036e9836

@ -932,13 +932,7 @@ exports.motorAction = async (req, reply) => {
const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate();
const intervalId = setInterval(async () => {
// Check if threshold time has been reached
const splr_tank_info3 = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() });
const splr_tank_info3_waterlevel = parseInt(splr_tank_info3.waterlevel, 10);
const splr_tank_info3_capacity = parseInt(splr_tank_info3.capacity, 10);
const splr_tank_info3_percentage = (splr_tank_info3_waterlevel / splr_tank_info3_capacity) * 100;
console.log(splr_tank_info3_percentage,"percentage for less than 20")
if (new Date() >= thresholdTime || splr_tank_info3_percentage<=20) {
if (new Date() >= thresholdTime) {
// Stop the motor pump
await Tank.updateOne(
{ customerId, "connections.inputConnections.motor_id": motorId },
@ -1494,26 +1488,23 @@ exports.IotDevice = async (req, reply) => {
const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10);
const water_level = water_level_height * waterCapacityPerCm;
if (water_level >= 0) {
existingTank.waterlevel = water_level;
// Save the updated tank document
await existingTank.save();
// Update linked tanks
for (const outputConnection of existingTank.connections.outputConnections) {
const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type });
if (linkedTank) {
for (const inputConnection of linkedTank.connections.inputConnections) {
if (inputConnection.inputConnections === tank_name) {
inputConnection.water_level = water_level;
await linkedTank.save();
}
existingTank.waterlevel = water_level;
// Save the updated tank document
await existingTank.save();
// Update linked tanks
for (const outputConnection of existingTank.connections.outputConnections) {
const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type });
if (linkedTank) {
for (const inputConnection of linkedTank.connections.inputConnections) {
if (inputConnection.inputConnections === tank_name) {
inputConnection.water_level = water_level;
await linkedTank.save();
}
}
}
}
}
// Send the latest three documents

Loading…
Cancel
Save