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
EXPOSE 3000
WORKDIR /usr/app

View File

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