diff --git a/dashboard/src/lib/sensor.ts b/dashboard/src/lib/sensor.ts index cadd041..a98c26a 100644 --- a/dashboard/src/lib/sensor.ts +++ b/dashboard/src/lib/sensor.ts @@ -1,7 +1,7 @@ import { browser } from '$app/environment'; import { readable } from 'svelte/store'; -const url = 'http://192.168.116.72'; +const url = 'http://192.168.116.48'; export type SensorData = { temp: number; @@ -10,6 +10,15 @@ export type SensorData = { out2: boolean; }; +export type Settings = { + refreshInterval: number; + sensorPin: number; + onTemp: number; + onHum: number; + tempOffset: number; + humOffset: number; +}; + const defaultData: SensorData = { temp: 0, hum: 0, @@ -63,3 +72,33 @@ export async function setOnHum(hum: number) { body: JSON.stringify({ onHum: hum }), }); } + +export async function setTempOffset(tempOffset: number) { + await fetch(`${url}/settings`, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify({ tempOffset }), + }); +} + +export async function setHumOffset(humOffset: number) { + await fetch(`${url}/settings`, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify({ humOffset }), + }); +} + +export async function getSettings(): Promise { + const res = await fetch(`${url}/settings`, { + method: 'GET', + headers: { Accept: 'application/json' }, + }); + return await res.json(); +} diff --git a/dashboard/src/routes/+page.svelte b/dashboard/src/routes/+page.svelte index b947987..c69f31c 100644 --- a/dashboard/src/routes/+page.svelte +++ b/dashboard/src/routes/+page.svelte @@ -1,56 +1,92 @@ -

Temperature {$sensor.temp} °C

-

Humidity {$sensor.hum} %

- -
- - - {temp} - - {hum}% - -
+{#if loading} +
Loading
+{:else} +
+
+
+
+ Heater + {$sensor.out1 ? 'ON' : 'OFF'} +
+
+ Dehumidifier + {$sensor.out2 ? 'ON' : 'OFF'} +
+
+
+ Temperature + {$sensor.temp}°C + Target: {temp}°C + setOnTemp(temp)} + /> + Hysteresis: {tempOffset}°C + setTempOffset(tempOffset)} + /> +
+
+ Humidity + {$sensor.hum}% + Target: {hum}% + setOnHum(hum)} + /> + Hysteresis: {humOffset}% + setHumOffset(humOffset)} + /> +
+
+
+{/if}