From 114463618ee0b68e838425d8403f3f9600c6309c Mon Sep 17 00:00:00 2001 From: Dawid Kubicki Date: Sun, 20 Jan 2019 21:24:41 +0100 Subject: [PATCH 1/2] save only 1 status --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fd52d22..5e2c029 100644 --- a/index.js +++ b/index.js @@ -20,10 +20,10 @@ const save_data = async time => { try { const devices = await deviceSchema.find({}); //console.log("DEVICES => " + devices); - for (const { ip, _id, lastStatus } of devices) { + for (const { _id } of devices) { const value_data = await getScript(ip); const data = JSON.parse(value_data); - + const { ip, lastStatus } = await deviceSchema.findById(_id); //console.log(lastStatus, data.Sensors[0].Switch); if (lastStatus != data.Sensors[0].Switch) { From 2924473ec03c6ae8d0086654c0ae0bf3222a2201 Mon Sep 17 00:00:00 2001 From: Dawid Kubicki Date: Sun, 20 Jan 2019 23:43:02 +0100 Subject: [PATCH 2/2] server bug fixed --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5e2c029..05dcaaf 100644 --- a/index.js +++ b/index.js @@ -20,11 +20,10 @@ const save_data = async time => { try { const devices = await deviceSchema.find({}); //console.log("DEVICES => " + devices); - for (const { _id } of devices) { + for (const { _id, ip } of devices) { const value_data = await getScript(ip); const data = JSON.parse(value_data); - const { ip, lastStatus } = await deviceSchema.findById(_id); - //console.log(lastStatus, data.Sensors[0].Switch); + const { lastStatus } = await deviceSchema.findById(_id); if (lastStatus != data.Sensors[0].Switch) { await statusSchema.findOneAndUpdate(