Update to add teasense
This commit is contained in:
parent
8e27964021
commit
67ba524b2d
21
src/index.ts
21
src/index.ts
@ -13,6 +13,7 @@ const { formatInTimeZone } = dateFnsTz;
|
|||||||
|
|
||||||
const RAIN_GAUGE_ENDPOINT = process.env.RAIN_GAUGE_ENDPOINT;
|
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 PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
const RAIN_GAUGE_SLEEP = 100;
|
const RAIN_GAUGE_SLEEP = 100;
|
||||||
|
|
||||||
@ -75,7 +76,9 @@ const saveDataPoint = async (name: string, value: number) => {
|
|||||||
const collectData = async () => {
|
const collectData = async () => {
|
||||||
if (RAIN_GAUGE_ENDPOINT && RAIN_GAUGE_ENDPOINT.trim() !== '') {
|
if (RAIN_GAUGE_ENDPOINT && RAIN_GAUGE_ENDPOINT.trim() !== '') {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(RAIN_GAUGE_ENDPOINT);
|
const response = await fetch(RAIN_GAUGE_ENDPOINT, {
|
||||||
|
signal: AbortSignal.timeout(5000),
|
||||||
|
});
|
||||||
const data: any = await response.json();
|
const data: any = await response.json();
|
||||||
if (data.rainfall > 0) {
|
if (data.rainfall > 0) {
|
||||||
saveDataPoint('rainfall', data.rainfall);
|
saveDataPoint('rainfall', data.rainfall);
|
||||||
@ -87,7 +90,9 @@ const collectData = async () => {
|
|||||||
|
|
||||||
if (SOIL_SENSOR_ENDPOINT && SOIL_SENSOR_ENDPOINT.trim() !== '') {
|
if (SOIL_SENSOR_ENDPOINT && SOIL_SENSOR_ENDPOINT.trim() !== '') {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(SOIL_SENSOR_ENDPOINT);
|
const response = await fetch(SOIL_SENSOR_ENDPOINT, {
|
||||||
|
signal: AbortSignal.timeout(5000),
|
||||||
|
});
|
||||||
const data: any = await response.json();
|
const data: any = await response.json();
|
||||||
saveDataPoint('soil_temperature', data.temperature);
|
saveDataPoint('soil_temperature', data.temperature);
|
||||||
saveDataPoint('soil_capacitence', data.capacitive);
|
saveDataPoint('soil_capacitence', data.capacitive);
|
||||||
@ -95,6 +100,18 @@ const collectData = async () => {
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TEASENSE_ENDPOINT && TEASENSE_ENDPOINT.trim() !== '') {
|
||||||
|
try {
|
||||||
|
const response = await fetch(TEASENSE_ENDPOINT, {
|
||||||
|
signal: AbortSignal.timeout(5000),
|
||||||
|
});
|
||||||
|
const data: any = await response.json();
|
||||||
|
saveDataPoint('teasense', data.temperature);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
setTimeout(() => collectData(), RAIN_GAUGE_SLEEP);
|
setTimeout(() => collectData(), RAIN_GAUGE_SLEEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user