added delay push data to mongo

This commit is contained in:
Dawid Kubicki 2019-01-12 11:36:07 +01:00
parent da5ef52bcd
commit 3a82387578

View File

@ -12,16 +12,18 @@ app.use(cors());
app.options("*", cors());
const port = 3000;
const save_data = async url => {
const value_data = await getScript(url);
const data = JSON.parse(value_data);
const item = new dbSchema({
name: data.Sensors[0].TaskName,
status: data.Sensors[0].Switch
});
await item.save();
};
let interval = setInterval(() => {
(async url => {
const value_data = await getScript(url);
console.log(value_data);
const item = new dbSchema({
name: value_data.Sensors[0].TaskName,
status: value_data.Sensors[0].Switch
});
await item.save();
})("http://localhost:3000/chillroom-server?ip=192.168.8.107");
save_data("192.168.8.107");
}, 5000);
const getScript = url => {
@ -32,6 +34,8 @@ const getScript = url => {
url = "http://" + url + "/json";
console.log("DATA URL => " + url);
client
.get(url, resp => {
let data = "";
@ -68,15 +72,7 @@ app.get("/stop", (req, res) => {
app.get("/start", (req, res) => {
if (interval === null) {
interval = setInterval(() => {
(async url => {
const value_data = await getScript(url);
console.log(value);
const item = new dbSchema({
name: value_data.split(",")[0],
value: value_data.split(",")[1]
});
await item.save();
})("http://localhost:3000/chillroom-server?ip=192.168.8.107");
save_data("192.168.8.107");
}, 5000);
res.json({ message: "Zaczalem dzialac :>" });