Updates
This commit is contained in:
parent
d1549bf553
commit
c217a807a7
22
src/index.ts
22
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 SOIL_SENSOR_ENDPOINT = process.env.SOIL_SENSOR_ENDPOINT;
|
||||||
const TEASENSE_ENDPOINT = process.env.TEASENSE_ENDPOINT;
|
const TEASENSE_ENDPOINT = process.env.TEASENSE_ENDPOINT;
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
const DATA_COLLECT_SLEEP = 1000;
|
const DATA_COLLECT_SLEEP = 2000;
|
||||||
const PURGE_SLEEP = 60000;
|
const PURGE_SLEEP = 60000;
|
||||||
const PURGE_TEASENSE_SLEEP = 1000;
|
const PURGE_TEASENSE_SLEEP = 1000;
|
||||||
|
|
||||||
@ -75,10 +75,10 @@ const collectData = async () => {
|
|||||||
});
|
});
|
||||||
const data: any = await response.json();
|
const data: any = await response.json();
|
||||||
if (data.rainfall > 0) {
|
if (data.rainfall > 0) {
|
||||||
saveDataPoint('rainfall', data.rainfall);
|
await saveDataPoint('rainfall', data.rainfall);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,22 +88,26 @@ const collectData = async () => {
|
|||||||
signal: AbortSignal.timeout(5000),
|
signal: AbortSignal.timeout(5000),
|
||||||
});
|
});
|
||||||
const data: any = await response.json();
|
const data: any = await response.json();
|
||||||
saveDataPoint('soil_voltage', data.moisture);
|
await saveDataPoint('soil_voltage', data.moisture);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TEASENSE_ENDPOINT && TEASENSE_ENDPOINT.trim() !== '') {
|
if (TEASENSE_ENDPOINT && TEASENSE_ENDPOINT.trim() !== '') {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(TEASENSE_ENDPOINT);
|
const response = await fetch(TEASENSE_ENDPOINT, {
|
||||||
|
signal: AbortSignal.timeout(10000),
|
||||||
|
});
|
||||||
const data: any = await response.json();
|
const data: any = await response.json();
|
||||||
saveDataPoint('teasense', data.temperature);
|
await saveDataPoint('teasense', data.temperature);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
purger5Sec();
|
||||||
|
|
||||||
setTimeout(() => collectData(), DATA_COLLECT_SLEEP);
|
setTimeout(() => collectData(), DATA_COLLECT_SLEEP);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -135,4 +139,4 @@ const purger5Sec = async () => {
|
|||||||
setTimeout(() => collectData(), DATA_COLLECT_SLEEP);
|
setTimeout(() => collectData(), DATA_COLLECT_SLEEP);
|
||||||
|
|
||||||
setInterval(() => purger(), PURGE_SLEEP);
|
setInterval(() => purger(), PURGE_SLEEP);
|
||||||
setInterval(() => purger5Sec(), PURGE_TEASENSE_SLEEP);
|
// setInterval(() => purger5Sec(), PURGE_TEASENSE_SLEEP);
|
Loading…
Reference in New Issue
Block a user