From c217a807a7ddab04ee3b68c1695f9277fbfa5b3a Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 28 Sep 2023 06:32:48 -0500 Subject: [PATCH] Updates --- src/index.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1303424..0c76f49 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,7 @@ const RAIN_GAUGE_ENDPOINT = process.env.RAIN_GAUGE_ENDPOINT; const SOIL_SENSOR_ENDPOINT = process.env.SOIL_SENSOR_ENDPOINT; const TEASENSE_ENDPOINT = process.env.TEASENSE_ENDPOINT; const PORT = process.env.PORT || 3000; -const DATA_COLLECT_SLEEP = 1000; +const DATA_COLLECT_SLEEP = 2000; const PURGE_SLEEP = 60000; const PURGE_TEASENSE_SLEEP = 1000; @@ -75,10 +75,10 @@ const collectData = async () => { }); const data: any = await response.json(); if (data.rainfall > 0) { - saveDataPoint('rainfall', data.rainfall); + await saveDataPoint('rainfall', data.rainfall); } } catch (e) { - console.log(e); + console.error(e); } } @@ -88,22 +88,26 @@ const collectData = async () => { signal: AbortSignal.timeout(5000), }); const data: any = await response.json(); - saveDataPoint('soil_voltage', data.moisture); + await saveDataPoint('soil_voltage', data.moisture); } catch (e) { - console.log(e); + console.error(e); } } if (TEASENSE_ENDPOINT && TEASENSE_ENDPOINT.trim() !== '') { try { - const response = await fetch(TEASENSE_ENDPOINT); + const response = await fetch(TEASENSE_ENDPOINT, { + signal: AbortSignal.timeout(10000), + }); const data: any = await response.json(); - saveDataPoint('teasense', data.temperature); + await saveDataPoint('teasense', data.temperature); } catch (e) { - console.log(e); + console.error(e); } } + purger5Sec(); + setTimeout(() => collectData(), DATA_COLLECT_SLEEP); }; @@ -135,4 +139,4 @@ const purger5Sec = async () => { setTimeout(() => collectData(), DATA_COLLECT_SLEEP); setInterval(() => purger(), PURGE_SLEEP); -setInterval(() => purger5Sec(), PURGE_TEASENSE_SLEEP); \ No newline at end of file +// setInterval(() => purger5Sec(), PURGE_TEASENSE_SLEEP); \ No newline at end of file