This commit is contained in:
William Moore 2023-06-15 15:02:51 -05:00
parent ea269c6459
commit 795a887678
2 changed files with 26 additions and 22 deletions

View File

@ -1,4 +1,4 @@
FROM node:18-alpine3.14 FROM node:18-alpine3.18
RUN apk update && apk upgrade && sync RUN apk update && apk upgrade && sync
EXPOSE 3000 EXPOSE 3000
WORKDIR /usr/app WORKDIR /usr/app

View File

@ -33,15 +33,12 @@ export type DataPoint = {
value: number; value: number;
}; };
let tempValue = 0.;
async function pullTempFromBackend() { async function pullTempFromBackend() {
try { try {
const response = await axios.get( const response = await axios.get(
'https://sensors.mooreforge.com/api/teasense/', process.env.TEASENSE_URL ?? ''
{
headers: {
Authorization: 'Basic Y2FyYW5tZWdpbDplOHl0cjl1dQ==',
},
},
); );
const result = response.data.reduce( const result = response.data.reduce(
@ -57,25 +54,32 @@ async function pullTempFromBackend() {
null, null,
); );
if (result && result.value >= 78.0) { if (result?.value && result?.value >= parseInt(process.env.TEASENSE_TEMP ?? '100.0')) {
tempValue = result?.value;
}
} catch (e) {
console.error(e);
} finally {
setTimeout(() => pullTempFromBackend(), 2000);
}
}
(async function () {
await pullTempFromBackend();
setInterval(async () => {
if (tempValue > 0.) {
try { try {
const resultStr = await messaging.send({ await messaging.send({
data: { notification: {
value: `${result?.value}` body: `♨️ ${tempValue} C`,
}, },
topic: 'teasense', topic: 'teasense',
}); });
console.log(resultStr);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
tempValue = 0.;
} }
} catch (e) { }, 5000);
console.log(e); })();
} finally {
setTimeout(() => pullTempFromBackend(), 1000);
}
}
pullTempFromBackend();