Work
This commit is contained in:
parent
59252e81b0
commit
8e64445c25
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -20,5 +20,5 @@
|
||||||
"valarray": "cpp",
|
"valarray": "cpp",
|
||||||
"vector": "cpp"
|
"vector": "cpp"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "enabled"
|
"C_Cpp.errorSquiggles": "disabled"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"useTabs": true,
|
"useTabs": true,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "none",
|
"trailingComma": "all",
|
||||||
"printWidth": 100,
|
"printWidth": 100,
|
||||||
"plugins": ["prettier-plugin-svelte"],
|
"plugins": ["prettier-plugin-svelte"],
|
||||||
"pluginSearchDirs": ["."],
|
"pluginSearchDirs": ["."],
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build && cp -r ./build/* ../data",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
|
@ -14,19 +14,27 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^2.0.0",
|
"@sveltejs/adapter-auto": "^2.0.0",
|
||||||
"@sveltejs/adapter-static": "^2.0.1",
|
"@sveltejs/adapter-static": "^2.0.1",
|
||||||
"@sveltejs/kit": "^1.5.0",
|
"@sveltejs/kit": "^1.10.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
||||||
"@typescript-eslint/parser": "^5.45.0",
|
"@typescript-eslint/parser": "^5.54.0",
|
||||||
"eslint": "^8.28.0",
|
"autoprefixer": "^10.4.7",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"daisyui": "^2.51.3",
|
||||||
|
"eslint": "^8.35.0",
|
||||||
|
"eslint-config-prettier": "^8.7.0",
|
||||||
"eslint-plugin-svelte3": "^4.0.0",
|
"eslint-plugin-svelte3": "^4.0.0",
|
||||||
"prettier": "^2.8.0",
|
"gauge-chart-js": "^2.0.1",
|
||||||
"prettier-plugin-svelte": "^2.8.1",
|
"postcss": "^8.4.14",
|
||||||
"svelte": "^3.54.0",
|
"postcss-load-config": "^4.0.1",
|
||||||
"svelte-check": "^3.0.1",
|
"prettier": "^2.8.4",
|
||||||
"tslib": "^2.4.1",
|
"prettier-plugin-svelte": "^2.9.0",
|
||||||
"typescript": "^4.9.3",
|
"sass": "^1.58.3",
|
||||||
"vite": "^4.0.0"
|
"svelte": "^3.55.1",
|
||||||
|
"svelte-check": "^3.0.4",
|
||||||
|
"tailwindcss": "^3.1.5",
|
||||||
|
"tslib": "^2.5.0",
|
||||||
|
"typescript": "^4.9.5",
|
||||||
|
"vite": "^4.1.4",
|
||||||
|
"svelte-preprocess": "^4.10.7"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
13
dashboard/postcss.config.cjs
Normal file
13
dashboard/postcss.config.cjs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
const tailwindcss = require('tailwindcss');
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
plugins: [
|
||||||
|
//Some plugins, like tailwindcss/nesting, need to run before Tailwind,
|
||||||
|
tailwindcss(),
|
||||||
|
//But others, like autoprefixer, need to run after,
|
||||||
|
autoprefixer,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
4
dashboard/src/app.postcss
Normal file
4
dashboard/src/app.postcss
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/* Write your global styles here, in PostCSS syntax */
|
||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
26
dashboard/src/lib/components/Gauge.svelte
Normal file
26
dashboard/src/lib/components/Gauge.svelte
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { Gauge } from 'gauge-chart-js';
|
||||||
|
|
||||||
|
export let value: number;
|
||||||
|
export let color = '#000';
|
||||||
|
export let lineWidth = 1;
|
||||||
|
export let gaugeRadius = 10;
|
||||||
|
|
||||||
|
let gauge: Gauge;
|
||||||
|
let container: HTMLElement;
|
||||||
|
|
||||||
|
$: gauge?.setValue(value);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
gauge = new Gauge({
|
||||||
|
container,
|
||||||
|
color,
|
||||||
|
lineWidth,
|
||||||
|
gaugeRadius,
|
||||||
|
});
|
||||||
|
gauge.setValue(value);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={container} />
|
|
@ -1,22 +1,65 @@
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { readable } from 'svelte/store';
|
import { readable } from 'svelte/store';
|
||||||
|
|
||||||
|
const url = 'http://192.168.116.72';
|
||||||
|
|
||||||
export type SensorData = {
|
export type SensorData = {
|
||||||
temp: number;
|
temp: number;
|
||||||
hum: number;
|
hum: number;
|
||||||
|
out1: boolean;
|
||||||
|
out2: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sensor = readable<SensorData | null>(null, (set) => {
|
const defaultData: SensorData = {
|
||||||
|
temp: 0,
|
||||||
|
hum: 0,
|
||||||
|
out1: false,
|
||||||
|
out2: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sensor = readable<SensorData>(defaultData, (set) => {
|
||||||
if (browser) {
|
if (browser) {
|
||||||
const source = new EventSource('http://10.50.0.113/events');
|
const source = new EventSource(`${url}/events`);
|
||||||
|
|
||||||
source.addEventListener('open', () => {
|
source.addEventListener('open', () => {
|
||||||
console.log('Connected');
|
console.log('Connected');
|
||||||
});
|
});
|
||||||
|
|
||||||
source.addEventListener('message', (e) => {
|
source.addEventListener('message', (e) => {
|
||||||
const data: SensorData = JSON.parse(e.data);
|
set(JSON.parse(e.data));
|
||||||
set(data);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export async function setOutput(pin: number, value: boolean) {
|
||||||
|
await fetch(`${url}/set`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Accept: 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ pin, value }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setOnTemp(temp: number) {
|
||||||
|
await fetch(`${url}/settings`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Accept: 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ onTemp: temp }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setOnHum(hum: number) {
|
||||||
|
await fetch(`${url}/settings`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Accept: 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ onHum: hum }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
5
dashboard/src/routes/+layout.svelte
Normal file
5
dashboard/src/routes/+layout.svelte
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<script>
|
||||||
|
import '../app.postcss';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot />
|
|
@ -1,8 +1,56 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { sensor } from '../lib/sensor';
|
import { sensor, setOnHum, setOnTemp, setOutput } from '../lib/sensor';
|
||||||
|
|
||||||
|
let temp = 26;
|
||||||
|
let hum = 50;
|
||||||
|
|
||||||
|
async function handleTempChange() {
|
||||||
|
await setOnTemp(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleHumChange() {
|
||||||
|
await setOnHum(hum);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $sensor}
|
<p>Temperature {$sensor.temp} °C</p>
|
||||||
<p>Temperature {$sensor.temp} °C</p>
|
<p>Humidity {$sensor.hum} %</p>
|
||||||
<p>Humidity {$sensor.hum}%</p>
|
|
||||||
{/if}
|
<div class="form-control w-full p-16">
|
||||||
|
<label class="label cursor-pointer">
|
||||||
|
<span class="label-text">Heater</span>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="toggle"
|
||||||
|
checked={$sensor.out1}
|
||||||
|
on:change={(e) => setOutput(16, e.currentTarget.checked)}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="label cursor-pointer">
|
||||||
|
<span class="label-text">Dehumidifier</span>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="toggle"
|
||||||
|
checked={$sensor.out2}
|
||||||
|
on:change={(e) => setOutput(17, e.currentTarget.checked)}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<span>{temp}</span>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="100"
|
||||||
|
bind:value={temp}
|
||||||
|
class="range"
|
||||||
|
on:change={handleTempChange}
|
||||||
|
/>
|
||||||
|
<span>{hum}%</span>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="100"
|
||||||
|
bind:value={hum}
|
||||||
|
class="range"
|
||||||
|
on:change={handleHumChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
|
import preprocess from 'svelte-preprocess';
|
||||||
import adapter from '@sveltejs/adapter-static';
|
import adapter from '@sveltejs/adapter-static';
|
||||||
import { vitePreprocess } from '@sveltejs/kit/vite';
|
import { vitePreprocess } from '@sveltejs/kit/vite';
|
||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
preprocess: vitePreprocess(),
|
preprocess: [
|
||||||
|
vitePreprocess(),
|
||||||
|
preprocess({
|
||||||
|
postcss: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
kit: {
|
kit: {
|
||||||
adapter: adapter({
|
adapter: adapter({
|
||||||
pages: 'build',
|
pages: 'build',
|
||||||
assets: 'build',
|
assets: 'build',
|
||||||
fallback: null,
|
fallback: null,
|
||||||
precompress: false,
|
precompress: false,
|
||||||
strict: true
|
strict: true,
|
||||||
})
|
}),
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|
9
dashboard/tailwind.config.cjs
Normal file
9
dashboard/tailwind.config.cjs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const config = {
|
||||||
|
content: ['./src/**/*.{html,js,svelte,ts}'],
|
||||||
|
theme: {
|
||||||
|
extend: {},
|
||||||
|
},
|
||||||
|
plugins: [require('daisyui')],
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
|
@ -10,6 +10,7 @@
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"strict": true
|
"strict": true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||||
//
|
//
|
||||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||||
|
|
|
@ -2,5 +2,5 @@ import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit()]
|
plugins: [sveltekit()],
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,12 @@
|
||||||
Settings::Settings() {
|
Settings::Settings() {
|
||||||
refreshInterval = 1000;
|
refreshInterval = 1000;
|
||||||
sensorPin = 26;
|
sensorPin = 26;
|
||||||
|
onTemp = 26.0;
|
||||||
|
onHum = 60.0;
|
||||||
|
tempOffset = 2.0;
|
||||||
|
humOffset = -2.0;
|
||||||
|
heaterOn = false;
|
||||||
|
dehumOn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::load() {
|
void Settings::load() {
|
||||||
|
@ -29,3 +35,45 @@ void Settings::setSensorPin(unsigned int sensorPin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Settings::getSensorPin() { return sensorPin; }
|
unsigned int Settings::getSensorPin() { return sensorPin; }
|
||||||
|
|
||||||
|
void Settings::setOnTemp(float temp) {
|
||||||
|
onTemp = temp;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
float Settings::getOnTemp() { return onTemp; }
|
||||||
|
|
||||||
|
void Settings::setOnHum(float hum) {
|
||||||
|
onHum = hum;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
float Settings::getOnHum() { return onHum; }
|
||||||
|
|
||||||
|
void Settings::setTempOffset(float temp) {
|
||||||
|
tempOffset = temp;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
float Settings::getTempOffset() { return tempOffset; }
|
||||||
|
|
||||||
|
void Settings::setHumOffset(float hum) {
|
||||||
|
humOffset = hum;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
float Settings::getHumOffset() { return humOffset; }
|
||||||
|
|
||||||
|
void Settings::setHeaterOn(bool on) {
|
||||||
|
heaterOn = on;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Settings::getHeaterOn() { return heaterOn; }
|
||||||
|
|
||||||
|
void Settings::setDehumOn(bool on) {
|
||||||
|
dehumOn = on;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Settings::getDehumOn() { return dehumOn; }
|
|
@ -11,9 +11,33 @@ public:
|
||||||
void setSensorPin(unsigned int);
|
void setSensorPin(unsigned int);
|
||||||
unsigned int getSensorPin();
|
unsigned int getSensorPin();
|
||||||
|
|
||||||
|
void setOnTemp(float temp);
|
||||||
|
float getOnTemp();
|
||||||
|
|
||||||
|
void setOnHum(float hum);
|
||||||
|
float getOnHum();
|
||||||
|
|
||||||
|
void setTempOffset(float temp);
|
||||||
|
float getTempOffset();
|
||||||
|
|
||||||
|
void setHumOffset(float hum);
|
||||||
|
float getHumOffset();
|
||||||
|
|
||||||
|
void setHeaterOn(bool on);
|
||||||
|
bool getHeaterOn();
|
||||||
|
|
||||||
|
void setDehumOn(bool on);
|
||||||
|
bool getDehumOn();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long refreshInterval;
|
unsigned long refreshInterval;
|
||||||
unsigned int sensorPin;
|
unsigned int sensorPin;
|
||||||
|
float onTemp;
|
||||||
|
float onHum;
|
||||||
|
float tempOffset;
|
||||||
|
float humOffset;
|
||||||
|
bool heaterOn;
|
||||||
|
bool dehumOn;
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
};
|
};
|
81
src/main.cpp
81
src/main.cpp
|
@ -8,11 +8,11 @@
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
|
||||||
void sendSensorData();
|
void readSensor();
|
||||||
void setupSensor();
|
void setupSensor();
|
||||||
|
|
||||||
const char *ssid = "stoenka";
|
const char *ssid = "Vegova RVP4";
|
||||||
const char *password = "topavem2020";
|
const char *password = "Vegova_RVP4";
|
||||||
|
|
||||||
DHT *dht;
|
DHT *dht;
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -35,7 +35,7 @@ void setupWifi() {
|
||||||
|
|
||||||
void onConnect(AsyncEventSourceClient *client) {
|
void onConnect(AsyncEventSourceClient *client) {
|
||||||
Serial.println("New client connected");
|
Serial.println("New client connected");
|
||||||
sendSensorData();
|
readSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupServer() {
|
void setupServer() {
|
||||||
|
@ -44,11 +44,30 @@ void setupServer() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POST /set - set the output pin
|
||||||
|
AsyncCallbackJsonWebHandler *setHandler = new AsyncCallbackJsonWebHandler(
|
||||||
|
"/set", [](AsyncWebServerRequest *req, JsonVariant &json) {
|
||||||
|
if (json["pin"].isNull() || json["value"].isNull()) {
|
||||||
|
req->send(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
digitalWrite(json["pin"].as<int>(), json["value"].as<bool>());
|
||||||
|
readSensor();
|
||||||
|
req->send(200);
|
||||||
|
});
|
||||||
|
server.addHandler(setHandler);
|
||||||
|
|
||||||
// GET /settings - Get the current settings
|
// GET /settings - Get the current settings
|
||||||
server.on("/settings", HTTP_GET, [](AsyncWebServerRequest *req) {
|
server.on("/settings", HTTP_GET, [](AsyncWebServerRequest *req) {
|
||||||
StaticJsonDocument<200> json;
|
StaticJsonDocument<200> json;
|
||||||
json["refreshInterval"] = settings.getRefreshInterval();
|
json["refreshInterval"] = settings.getRefreshInterval();
|
||||||
json["sensorPin"] = settings.getSensorPin();
|
json["sensorPin"] = settings.getSensorPin();
|
||||||
|
json["onTemp"] = settings.getOnTemp();
|
||||||
|
json["onHum"] = settings.getOnHum();
|
||||||
|
json["tempOffset"] = settings.getTempOffset();
|
||||||
|
json["humOffset"] = settings.getHumOffset();
|
||||||
|
json["heaterOn"] = settings.getHeaterOn();
|
||||||
|
json["dehumOn"] = settings.getDehumOn();
|
||||||
|
|
||||||
String buffer;
|
String buffer;
|
||||||
serializeJson(json, buffer);
|
serializeJson(json, buffer);
|
||||||
|
@ -67,10 +86,30 @@ void setupServer() {
|
||||||
settings.setSensorPin(json["sensorPin"].as<unsigned int>());
|
settings.setSensorPin(json["sensorPin"].as<unsigned int>());
|
||||||
setupSensor();
|
setupSensor();
|
||||||
}
|
}
|
||||||
|
if (!json["onTemp"].isNull()) {
|
||||||
|
settings.setOnTemp(json["onTemp"].as<float>());
|
||||||
|
}
|
||||||
|
if (!json["onHum"].isNull()) {
|
||||||
|
settings.setOnHum(json["onHum"].as<float>());
|
||||||
|
}
|
||||||
|
if (!json["tempOffset"].isNull()) {
|
||||||
|
settings.setTempOffset(json["tempOffset"].as<float>());
|
||||||
|
}
|
||||||
|
if (!json["humOffset"].isNull()) {
|
||||||
|
settings.setHumOffset(json["humOffset"].as<float>());
|
||||||
|
}
|
||||||
req->send(200);
|
req->send(200);
|
||||||
});
|
});
|
||||||
server.addHandler(settingsHandler);
|
server.addHandler(settingsHandler);
|
||||||
|
|
||||||
|
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
|
if (request->method() == HTTP_OPTIONS) {
|
||||||
|
request->send(200);
|
||||||
|
} else {
|
||||||
|
request->send(404);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
events.onConnect(onConnect);
|
events.onConnect(onConnect);
|
||||||
server.addHandler(&events);
|
server.addHandler(&events);
|
||||||
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
||||||
|
@ -84,10 +123,33 @@ void setupSensor() {
|
||||||
dht->begin();
|
dht->begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendSensorData() {
|
void readSensor() {
|
||||||
|
float temp = dht->readTemperature();
|
||||||
|
float hum = dht->readHumidity();
|
||||||
|
|
||||||
|
float onTemp = settings.getOnTemp();
|
||||||
|
float offTemp = onTemp + settings.getTempOffset();
|
||||||
|
|
||||||
|
float onHum = settings.getOnHum();
|
||||||
|
float offHum = onHum + settings.getHumOffset();
|
||||||
|
|
||||||
|
if (temp <= onTemp) {
|
||||||
|
digitalWrite(16, HIGH);
|
||||||
|
} else {
|
||||||
|
digitalWrite(16, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hum >= onHum) {
|
||||||
|
digitalWrite(17, HIGH);
|
||||||
|
} else {
|
||||||
|
digitalWrite(17, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
StaticJsonDocument<200> json;
|
StaticJsonDocument<200> json;
|
||||||
json["temp"] = (int)(dht->readTemperature() * 100 + 0.5) / 100.0;
|
json["temp"] = (int)(temp * 100 + 0.5) / 100.0;
|
||||||
json["hum"] = dht->readHumidity();
|
json["hum"] = hum;
|
||||||
|
json["out1"] = (bool)digitalRead(16);
|
||||||
|
json["out2"] = (bool)digitalRead(17);
|
||||||
|
|
||||||
String buffer;
|
String buffer;
|
||||||
serializeJson(json, buffer);
|
serializeJson(json, buffer);
|
||||||
|
@ -98,6 +160,9 @@ void sendSensorData() {
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
pinMode(16, OUTPUT);
|
||||||
|
pinMode(17, OUTPUT);
|
||||||
|
|
||||||
setupWifi();
|
setupWifi();
|
||||||
setupServer();
|
setupServer();
|
||||||
|
|
||||||
|
@ -112,6 +177,6 @@ void loop() {
|
||||||
unsigned long currMillis = millis();
|
unsigned long currMillis = millis();
|
||||||
if (currMillis - prevMillis > settings.getRefreshInterval()) {
|
if (currMillis - prevMillis > settings.getRefreshInterval()) {
|
||||||
prevMillis = currMillis;
|
prevMillis = currMillis;
|
||||||
sendSensorData();
|
readSensor();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user