|
|
@ -1,5 +1,5 @@
|
|
|
|
//const Tank = require("../models/tanks");
|
|
|
|
//const Tank = require("../models/tanks");
|
|
|
|
const { Tank, MotorData } = require('../models/tanks')
|
|
|
|
const { Tank, MotorData, IotData } = require('../models/tanks')
|
|
|
|
|
|
|
|
|
|
|
|
const User = require("../models/User");
|
|
|
|
const User = require("../models/User");
|
|
|
|
const boom = require("boom");
|
|
|
|
const boom = require("boom");
|
|
|
@ -510,4 +510,42 @@ exports.consumption = async (req, reply) => {
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.IotDevice = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { hardwareId, tankHeight, maxLevel, minLevel, mode } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create a new tank document
|
|
|
|
|
|
|
|
const tank = new IotData({ hardwareId, tankHeight, maxLevel, minLevel, mode });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// save the document to MongoDB
|
|
|
|
|
|
|
|
await tank.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// send a success response
|
|
|
|
|
|
|
|
reply.code(200).send({ message: 'Data saved successfully' });
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
// send an error response
|
|
|
|
|
|
|
|
reply.code(500).send({ error: err.message });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getIotD = async(req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await IotData.find({hardwareId: req.query.hardwareId})
|
|
|
|
|
|
|
|
.exec()
|
|
|
|
|
|
|
|
.then((docs) => {
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
|
|
reply.send({ error: err });
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|