Update to add merrysky and use a .env file

This commit is contained in:
William Moore 2023-06-06 13:46:13 -05:00
parent 34d6294bd0
commit b5d9849c9a
7 changed files with 4175 additions and 8 deletions

13
gulpfile.js Normal file
View File

@ -0,0 +1,13 @@
const replace = require('gulp-replace');
const { src, dest } = require('gulp');
require('dotenv/config');
// or replace multiple strings
function replaceTemplate() {
return src(['./public/js/**/*.js'])
.pipe(replace(/TEASENSE_URI/g, process.env.TEASENSE_URI))
.pipe(replace(/RAINFALL_URI/g, process.env.RAINFALL_URI))
.pipe(dest('./public/js'));
};
exports.default = replaceTemplate;

4123
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,8 @@
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"type": "module",
"scripts": { "scripts": {
"start": "npx tsc && npx rollup -c", "start": "npx tsc && npx gulp && npx rollup -c",
"clean": "rm -rf build", "clean": "rm -rf build",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
@ -13,6 +12,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
"dotenv": "^16.1.4",
"lit": "^2.7.5", "lit": "^2.7.5",
"typescript": "^5.1.3" "typescript": "^5.1.3"
}, },
@ -23,6 +23,8 @@
"@web/rollup-plugin-copy": "^0.4.0", "@web/rollup-plugin-copy": "^0.4.0",
"@web/rollup-plugin-html": "^2.0.0", "@web/rollup-plugin-html": "^2.0.0",
"@web/rollup-plugin-polyfills-loader": "^2.0.0", "@web/rollup-plugin-polyfills-loader": "^2.0.0",
"gulp": "^4.0.2",
"gulp-replace": "^1.1.4",
"rollup": "^2.79.1", "rollup": "^2.79.1",
"rollup-plugin-minify-html-literals": "^1.2.6", "rollup-plugin-minify-html-literals": "^1.2.6",
"rollup-plugin-summary": "^2.0.0" "rollup-plugin-summary": "^2.0.0"

9
public/merrysky.html Normal file
View File

@ -0,0 +1,9 @@
<html>
<head>
<meta http-equiv="refresh" content="86400">
<script type="module" src="./js/MerrySky.js"></script>
</head>
<body>
<merry-sky></merry-sky>
</body>
</html>

15
src/MerrySky.ts Normal file
View File

@ -0,0 +1,15 @@
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('merry-sky')
export class MerrySky extends LitElement {
override render() {
return html`<iframe framespacing="0" width="100%" height="100%" frameborder="no" src="https://merrysky.net">View MerrySky</iframe>`;
}
}
declare global {
interface HTMLElementTagNameMap {
'merry-sky': MerrySky;
}
}

View File

@ -11,7 +11,7 @@ export class Rainfall extends LitElement {
} }
async pullValueFromBackend() { async pullValueFromBackend() {
const response = await fetch('https://sensors.mooreforge.com/api/rainfall'); const response = await fetch('RAINFALL_URI');
const data = await response.json(); const data = await response.json();
const result = data const result = data
.map((datum: any) => datum.value) .map((datum: any) => datum.value)

View File

@ -12,12 +12,17 @@ export class TeaSense extends LitElement {
} }
async pullTempFromBackend() { async pullTempFromBackend() {
const response = await fetch('https://sensors.mooreforge.com/api/teasense'); try {
const response = await fetch('TEASENSE_URI');
const data = await response.json(); const data = await response.json();
const result = data const result = data
.reduce((accum: any, datum: any) => (((accum && isBefore(new Date(accum?.timestamp), new Date(datum?.timestamp))) || !accum) ? datum : accum)); .reduce((accum: any, datum: any) => (((accum && isBefore(new Date(accum?.timestamp), new Date(datum?.timestamp))) || !accum) ? datum : accum));
this.setTemp(result.value); this.setTemp(result.value);
} catch (error) {
console.log(error);
}
setTimeout(() => this.pullTempFromBackend(), 5000); setTimeout(() => this.pullTempFromBackend(), 5000);
} }