Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
6291c9311a | |||
0817fcf492 | |||
747e7bbbf8 | |||
cb3850134a | |||
ee91b36c66 |
@ -6,6 +6,7 @@ stages:
|
||||
cache:
|
||||
paths:
|
||||
- "~/.platformio"
|
||||
- ./interface/node_modules
|
||||
|
||||
before_script:
|
||||
- "pip install -U platformio"
|
||||
@ -13,7 +14,10 @@ before_script:
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script: "platformio run -e esp12e"
|
||||
script:
|
||||
- "platformio run -e esp12e"
|
||||
- vers=$(grep -Po '[0-9]*\.[0-9]*\.[0-9]*(?=\")' ./src/Pins.h)
|
||||
- mv .pio/build/esp12e/*.bin Pumpensteuerung-${vers}.bin
|
||||
artifacts:
|
||||
paths:
|
||||
- .pio/build/esp12e/*.bin
|
||||
- ./*.bin
|
Binary file not shown.
Before Width: | Height: | Size: 8.7 KiB |
@ -1,12 +0,0 @@
|
||||
{
|
||||
"name":"ESP8266 React",
|
||||
"icons":[
|
||||
{
|
||||
"src":"/app/icon.png",
|
||||
"sizes":"48x48 72x72 96x96 128x128 256x256"
|
||||
}
|
||||
],
|
||||
"start_url":"/",
|
||||
"display":"fullscreen",
|
||||
"orientation":"any"
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/* Just supporting latin due to size constrains on the esp chip */
|
||||
@font-face {
|
||||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
src: local('Roboto Light'), local('Roboto-Light'), url(../fonts/li.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2212, U+2215;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Roboto'), local('Roboto-Regular'), url(../fonts/re.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2212, U+2215;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
src: local('Roboto Medium'), local('Roboto-Medium'), url(../fonts/me.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2212, U+2215;
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,12 +1,6 @@
|
||||
import React, {Component} from 'react';
|
||||
import {Box, List, ListItem, ListItemText} from '@material-ui/core';
|
||||
import {
|
||||
FormButton,
|
||||
restController,
|
||||
RestControllerProps,
|
||||
RestFormLoader,
|
||||
SectionContent
|
||||
} from '../components';
|
||||
import {FormButton, restController, RestControllerProps, RestFormLoader, SectionContent} from '../components';
|
||||
import {ENDPOINT_ROOT} from "../api";
|
||||
import {GeneralInformaitonState} from "./types";
|
||||
import RefreshIcon from "@material-ui/icons/Refresh";
|
||||
@ -21,12 +15,6 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
|
||||
|
||||
componentDidMount() {
|
||||
this.props.loadData();
|
||||
|
||||
// this.intervalhandler = window.setInterval(() => {
|
||||
// this.props.loadData();
|
||||
// console.log("refreshing data");
|
||||
// console.log(this.props.data)
|
||||
// }, 10000);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@ -39,58 +27,62 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
|
||||
<RestFormLoader
|
||||
{...this.props}
|
||||
render={props => (
|
||||
<>
|
||||
<List>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Chip läuft seit:"
|
||||
secondary={this.stringifyTime(props.data.runtime)}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Zuletzt zu wenig Wasser:"
|
||||
secondary={props.data.lastWaterOutage !== 0 ? "vor " + this.stringifyTime(props.data.lastWaterOutage) : "noch nie!"}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Letzer Pumpenzyklus"
|
||||
secondary={props.data.lastpumptime !== 0 ? "vor " + this.stringifyTime(props.data.lastpumptime) : "noch nie!"}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Letze Pumpdauer:"
|
||||
secondary={props.data.lastPumpDuration !== 0 ? this.stringifyTime(props.data.lastPumpDuration) : "-"}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Temperatur/Luftfeuchtigkeit:"
|
||||
secondary={(props.data.temp !== -1 ? props.data.temp + "C" : "Auslesefehler!") + " / " + (props.data.hum !== -1 ? props.data.hum + "%" : "Auslesefehler!")}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="WasserSensor / DruckSensor"
|
||||
secondary={(props.data.watersensor ? "EIN" : "AUS!") + " / " + (props.data.pressuresensor ? "EIN" : "AUS")}
|
||||
/>
|
||||
</ListItem>
|
||||
</List>
|
||||
<Box display="flex" flexWrap="wrap">
|
||||
<Box flexGrow={1} padding={1}>
|
||||
<FormButton startIcon={<RefreshIcon/>} variant="contained" color="secondary"
|
||||
onClick={this.props.loadData}>
|
||||
Refresh
|
||||
</FormButton>
|
||||
</Box>
|
||||
<Box flexWrap="none" padding={1} whiteSpace="nowrap">
|
||||
Version: {props.data.version}
|
||||
</Box>
|
||||
<>
|
||||
<List>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Chip läuft seit:"
|
||||
secondary={this.stringifyTime(props.data.runtime) + ' / ' + this.getRealTimeString(props.data.runtime)}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Zuletzt zu wenig Wasser:"
|
||||
secondary={props.data.lastWaterOutage !== 0 ? "vor " +
|
||||
this.stringifyTime(props.data.lastWaterOutage) + ' / ' +
|
||||
this.getRealTimeString(props.data.lastWaterOutage) : "noch nie!"}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Letzer Pumpenzyklus"
|
||||
secondary={props.data.lastpumptime !== 0 ? "vor " +
|
||||
this.stringifyTime(props.data.lastpumptime) + ' / ' +
|
||||
this.getRealTimeString(props.data.lastpumptime) : "noch nie!"}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Letze Pumpdauer:"
|
||||
secondary={props.data.lastPumpDuration !== 0 ? this.stringifyTime(props.data.lastPumpDuration) : "-"}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="Temperatur/Luftfeuchtigkeit:"
|
||||
secondary={(props.data.temp !== -1 ? props.data.temp + "C" : "Auslesefehler!") + " / " + (props.data.hum !== -1 ? props.data.hum + "%" : "Auslesefehler!")}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary="WasserSensor / DruckSensor"
|
||||
secondary={(props.data.watersensor ? "EIN" : "AUS!") + " / " + (props.data.pressuresensor ? "EIN" : "AUS")}
|
||||
/>
|
||||
</ListItem>
|
||||
</List>
|
||||
<Box display="flex" flexWrap="wrap">
|
||||
<Box flexGrow={1} padding={1}>
|
||||
<FormButton startIcon={<RefreshIcon/>} variant="contained" color="secondary"
|
||||
onClick={this.props.loadData}>
|
||||
Refresh
|
||||
</FormButton>
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
<Box flexWrap="none" padding={1} whiteSpace="nowrap">
|
||||
Version: {props.data.version}
|
||||
</Box>
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
</SectionContent>
|
||||
);
|
||||
@ -100,7 +92,7 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
|
||||
* stringify seconds to a pretty format
|
||||
* @param sec number of seconds
|
||||
*/
|
||||
stringifyTime(sec: number): string {
|
||||
private stringifyTime(sec: number): string {
|
||||
if (sec >= 86400) {
|
||||
// display days
|
||||
return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec");
|
||||
@ -115,6 +107,20 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
|
||||
return (sec + "sec");
|
||||
}
|
||||
}
|
||||
|
||||
private getRealTimeString(runtime: number): string {
|
||||
const timestamp = Date.now();
|
||||
|
||||
const a = new Date(timestamp - (runtime * 1000));
|
||||
const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
|
||||
const year = a.getFullYear();
|
||||
const month = months[a.getMonth()];
|
||||
const date = a.getDate();
|
||||
const hour = a.getHours();
|
||||
const min = "0" + a.getMinutes();
|
||||
const sec = "0" + a.getSeconds();
|
||||
return '[' + date + ' ' + month + ' ' + year + ' ' + hour + ':' + min.substr(-2) + ':' + sec.substr(-2) + ']';
|
||||
}
|
||||
}
|
||||
|
||||
export default restController(GENERALINFORMATION_SETTINGS_ENDPOINT, GeneralInformation);
|
||||
|
@ -20,11 +20,12 @@ build_flags=
|
||||
lib_compat_mode = strict
|
||||
|
||||
; Uncomment & modify the lines below in order to configure OTA updates
|
||||
upload_flags =
|
||||
--port=8266
|
||||
--auth=esp-react
|
||||
--host_port=14515
|
||||
upload_port = 192.168.0.230
|
||||
;upload_flags =
|
||||
; --port=8266
|
||||
; --auth=esp-react
|
||||
; --host_port=14515
|
||||
;upload_port = 192.168.0.230
|
||||
;upload_protocol = espota
|
||||
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "GeneralInfoService.h"
|
||||
#include "Pins.h"
|
||||
#include "Timer.h"
|
||||
|
||||
GeneralInfoService::GeneralInfoService(AsyncWebServer *server, float *lasthum, float *lasttemp) :
|
||||
hum(lasthum),
|
||||
@ -21,10 +22,12 @@ void GeneralInfoService::reply(AsyncWebServerRequest *request) {
|
||||
root["temp"] = *temp;
|
||||
root["hum"] = *hum;
|
||||
|
||||
root["lastpumptime"] = lastPumpTime != 0 ? (millis() - lastPumpTime) / 1000 : 0;
|
||||
root["lastWaterOutage"] = lastWaterOutage != 0 ? (millis() - lastWaterOutage) / 1000 : 0;
|
||||
root["lastPumpDuration"] = lastPumpDuration != 0 ? lastPumpDuration / 1000 : 0;
|
||||
root["runtime"] = millis() / 1000;
|
||||
const uint32_t systime = Timer::getSystemSeconds();
|
||||
|
||||
root["lastpumptime"] = lastPumpTime != 0 ? systime - lastPumpTime : 0;
|
||||
root["lastWaterOutage"] = lastWaterOutage != 0 ? systime - lastWaterOutage : 0;
|
||||
root["lastPumpDuration"] = lastPumpDuration != 0 ? lastPumpDuration : 0;
|
||||
root["runtime"] = systime;
|
||||
|
||||
root["watersensor"] = digitalRead(WasserSensorPin) ? true : false;
|
||||
root["pressuresensor"] = digitalRead(DruckSensorPin) ? true : false;
|
||||
@ -35,14 +38,14 @@ void GeneralInfoService::reply(AsyncWebServerRequest *request) {
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
void GeneralInfoService::setlastPumpTime(unsigned long lastPumpTime) {
|
||||
void GeneralInfoService::setlastPumpTime(uint32_t lastPumpTime) {
|
||||
this->lastPumpTime = lastPumpTime;
|
||||
}
|
||||
|
||||
void GeneralInfoService::setlastWaterOutage(unsigned long lastWaterOutage) {
|
||||
void GeneralInfoService::setlastWaterOutage(uint32_t lastWaterOutage) {
|
||||
this->lastWaterOutage = lastWaterOutage;
|
||||
}
|
||||
|
||||
void GeneralInfoService::setPumpDuration(unsigned long lastPumpDuration) {
|
||||
void GeneralInfoService::setPumpDuration(uint32_t lastPumpDuration) {
|
||||
this->lastPumpDuration = lastPumpDuration;
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ public:
|
||||
* sets the last time when the pump was on
|
||||
* @param lastPumpTime pump time in ms
|
||||
*/
|
||||
void setlastPumpTime(unsigned long lastPumpTime);
|
||||
void setlastPumpTime(uint32_t lastPumpTime);
|
||||
|
||||
/**
|
||||
* sets the last time of a water outage
|
||||
* @param lastWaterOutage last wateroutage time in ms
|
||||
*/
|
||||
void setlastWaterOutage(unsigned long lastWaterOutage);
|
||||
void setlastWaterOutage(uint32_t lastWaterOutage);
|
||||
|
||||
/**
|
||||
* sets the duration of the last pump cycle
|
||||
* @param lastPumpDuration duration in ms
|
||||
*/
|
||||
void setPumpDuration(unsigned long lastPumpDuration);
|
||||
void setPumpDuration(uint32_t lastPumpDuration);
|
||||
|
||||
private:
|
||||
void reply(AsyncWebServerRequest* request);
|
||||
|
135
src/Heating.cpp
135
src/Heating.cpp
@ -5,37 +5,21 @@
|
||||
#include "Heating.h"
|
||||
#include "Pins.h"
|
||||
|
||||
Heating::Heating() : mHeizungTicker(),
|
||||
mLuefterTicker(),
|
||||
mTurnOffTicker(),
|
||||
msettings(nullptr),
|
||||
mHeatingStatus(),
|
||||
lasttemp(0),
|
||||
lasthum(0),
|
||||
sensor() {}
|
||||
|
||||
void Heating::init(unsigned mode, const SettingState *settings) {
|
||||
msettings = settings;
|
||||
|
||||
void Heating::init(unsigned mode, const SettingState* settings) {
|
||||
switch (mode) {
|
||||
case TIME: {
|
||||
const unsigned percentOn = 20;
|
||||
const unsigned refreshperiod = 900;
|
||||
|
||||
const auto func = [this]() {
|
||||
mLuefterTicker.detach();
|
||||
|
||||
// every minute turn on the heating
|
||||
digitalWrite(LuefterPin, HIGH);
|
||||
digitalWrite(HeizungPin, HIGH);
|
||||
|
||||
Serial.println("Turning on heating");
|
||||
|
||||
mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
|
||||
Serial.println("Turned off heating!");
|
||||
});
|
||||
|
||||
mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
|
||||
Serial.println("Turned off fan!");
|
||||
});
|
||||
};
|
||||
|
||||
func();
|
||||
mHeizungTicker.attach(refreshperiod, func);
|
||||
this->handleTimeHeater();
|
||||
break;
|
||||
}
|
||||
case HUMIDITY:
|
||||
@ -51,31 +35,7 @@ void Heating::init(unsigned mode, const SettingState* settings) {
|
||||
this->lasttemp = temp;
|
||||
this->lasthum = hum;
|
||||
|
||||
if (hum > (float)settings->heatUp) {
|
||||
// turn off active turnoff timers
|
||||
mLuefterTicker.detach();
|
||||
Serial.println("heating should run now!");
|
||||
// turn on heating and fan
|
||||
digitalWrite(LuefterPin, HIGH);
|
||||
digitalWrite(HeizungPin, HIGH);
|
||||
mHeatingStatus = true;
|
||||
} else if (hum < (float)settings->heatLow) {
|
||||
// if humidity too low turn off heating and fan after 60secs
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
Serial.println("heating should NOT run now!");
|
||||
|
||||
// if heating status in on set ticker to turn of fan in 60sec
|
||||
if (mHeatingStatus) {
|
||||
mLuefterTicker.once((float)settings->fanRuntime, []() {
|
||||
// turn off fan
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
schedule_function([]() {
|
||||
Serial.println("turning off fan");
|
||||
});
|
||||
});
|
||||
}
|
||||
mHeatingStatus = false;
|
||||
}
|
||||
this->handleHeatingEvents();
|
||||
});
|
||||
});
|
||||
|
||||
@ -83,6 +43,11 @@ void Heating::init(unsigned mode, const SettingState* settings) {
|
||||
this->lasttemp = -1.0;
|
||||
this->lasthum = -1.0;
|
||||
|
||||
// emergency turnoff of heating
|
||||
if(mHeatingStatus){
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
}
|
||||
|
||||
schedule_function([e]() {
|
||||
Serial.printf("Error: %d\n", e);
|
||||
});
|
||||
@ -106,10 +71,60 @@ float *Heating::getLastHum() {
|
||||
return &lasthum;
|
||||
}
|
||||
|
||||
Heating::Heating() : mHeizungTicker(),
|
||||
mLuefterTicker(),
|
||||
mTurnOffTicker(),
|
||||
mHeatingStatus(),
|
||||
lasttemp(0),
|
||||
lasthum(0),
|
||||
sensor() {}
|
||||
void Heating::handleHeatingEvents() {
|
||||
if (this->lasthum > (float) msettings->heatUp) {
|
||||
// turn off active turnoff timers
|
||||
mLuefterTicker.detach();
|
||||
Serial.println("heating should run now!");
|
||||
// turn on heating and fan
|
||||
digitalWrite(LuefterPin, HIGH);
|
||||
digitalWrite(HeizungPin, HIGH);
|
||||
mHeatingStatus = true;
|
||||
} else if (this->lasthum < (float) msettings->heatLow) {
|
||||
// if humidity too low turn off heating and fan after 60secs
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
Serial.println("heating should NOT run now!");
|
||||
|
||||
// if heating status in on set ticker to turn of fan in 60sec
|
||||
if (mHeatingStatus) {
|
||||
mLuefterTicker.once((float) msettings->fanRuntime, []() {
|
||||
// turn off fan
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
schedule_function([]() {
|
||||
Serial.println("turning off fan");
|
||||
});
|
||||
});
|
||||
}
|
||||
mHeatingStatus = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Heating::handleTimeHeater() {
|
||||
const unsigned percentOn = 20;
|
||||
const unsigned refreshperiod = 900;
|
||||
|
||||
const auto func = [this]() {
|
||||
mLuefterTicker.detach();
|
||||
|
||||
// every minute turn on the heating
|
||||
digitalWrite(LuefterPin, HIGH);
|
||||
digitalWrite(HeizungPin, HIGH);
|
||||
|
||||
Serial.println("Turning on heating");
|
||||
|
||||
mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
|
||||
Serial.println("Turned off heating!");
|
||||
});
|
||||
|
||||
mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
|
||||
Serial.println("Turned off fan!");
|
||||
});
|
||||
};
|
||||
|
||||
func();
|
||||
mHeizungTicker.attach(refreshperiod, func);
|
||||
}
|
||||
|
@ -13,9 +13,23 @@ class Heating {
|
||||
public:
|
||||
Heating();
|
||||
|
||||
/**
|
||||
* initialize the heater
|
||||
* @param mode select the operating mode
|
||||
* @param settings a settings object is needed for HUMIDITY mode to get percent values set by user
|
||||
*/
|
||||
void init(unsigned mode, const SettingState* settings);
|
||||
|
||||
/**
|
||||
* get the last captured humidity value
|
||||
* @return humidity value
|
||||
*/
|
||||
float* getLastHum();
|
||||
|
||||
/**
|
||||
* get the last captured temperature value
|
||||
* @return temperature value
|
||||
*/
|
||||
float* getLastTemp();
|
||||
|
||||
enum MODES {TIME, HUMIDITY};
|
||||
@ -24,10 +38,25 @@ private:
|
||||
Ticker mLuefterTicker;
|
||||
Ticker mTurnOffTicker;
|
||||
|
||||
const SettingState* msettings;
|
||||
|
||||
bool mHeatingStatus;
|
||||
|
||||
float lasttemp;
|
||||
float lasthum;
|
||||
|
||||
DHT22 sensor;
|
||||
|
||||
/**
|
||||
* handle events after successfully received a humidity value
|
||||
* - turn on/off of heating
|
||||
* - afterrun of fan
|
||||
*/
|
||||
void handleHeatingEvents();
|
||||
|
||||
/**
|
||||
* handle events for time-heating mode
|
||||
* when to turn on/off heating + fan
|
||||
*/
|
||||
void handleTimeHeater();
|
||||
};
|
||||
|
@ -16,6 +16,6 @@
|
||||
#define TempSensorPin D4
|
||||
|
||||
// version info
|
||||
#define VERSION "v1.2.0"
|
||||
#define VERSION "v1.2.2"
|
||||
|
||||
#endif //PUMPENSTEUERUNG_PINS_H
|
||||
|
10
src/Timer.cpp
Normal file
10
src/Timer.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by lukas on 09.12.20.
|
||||
//
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Timer.h"
|
||||
|
||||
uint32_t Timer::getSystemSeconds() {
|
||||
return (uint32_t)(micros64() / 1000000);
|
||||
}
|
18
src/Timer.h
Normal file
18
src/Timer.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by lukas on 09.12.20.
|
||||
//
|
||||
|
||||
#ifndef PUMPENSTEUERUNG_TIMER_H
|
||||
#define PUMPENSTEUERUNG_TIMER_H
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
/**
|
||||
* get system time in seconds
|
||||
* @return system time in seconds
|
||||
*/
|
||||
static uint32_t getSystemSeconds();
|
||||
};
|
||||
|
||||
|
||||
#endif //PUMPENSTEUERUNG_TIMER_H
|
13
src/main.cpp
13
src/main.cpp
@ -5,6 +5,7 @@
|
||||
#include "Pins.h"
|
||||
#include "GeneralInfoService.h"
|
||||
#include "SettingsService.h"
|
||||
#include "Timer.h"
|
||||
|
||||
bool allow;
|
||||
bool error = false;
|
||||
@ -18,7 +19,7 @@ Ticker pumpendauer;
|
||||
//WifiManager mang;
|
||||
Heating mHeat;
|
||||
|
||||
unsigned long turnontime = 0;
|
||||
uint32_t turnontime = 0;
|
||||
|
||||
AsyncWebServer server(80);
|
||||
ESP8266React esp8266React(&server);
|
||||
@ -31,7 +32,7 @@ void pumpeSchalten(bool on) {
|
||||
if (on) {
|
||||
Serial.println("versuche Pumpe EIN zuschalten");
|
||||
// refresh last pump counter
|
||||
generalinfo.setlastPumpTime(millis());
|
||||
generalinfo.setlastPumpTime(Timer::getSystemSeconds());
|
||||
} else {
|
||||
Serial.println("versuche Pumpe AUS zuschalten");
|
||||
}
|
||||
@ -40,7 +41,7 @@ void pumpeSchalten(bool on) {
|
||||
if (on) {
|
||||
pumpendauer.once((float)settingsservice.getSettings()->maxpumpduration + 1, []() {
|
||||
//erlaube keine einschaltung von mehr als 60 sek
|
||||
if (millis() - turnontime >= (unsigned)settingsservice.getSettings()->maxpumpduration * 1000 && turnontime != 0) {
|
||||
if (Timer::getSystemSeconds() - turnontime >= (unsigned)settingsservice.getSettings()->maxpumpduration && turnontime != 0) {
|
||||
//error zu lange
|
||||
Serial.println("\n\npumpe lief mehr als 10 Minuten durchgaengig");
|
||||
pumpeSchalten(false);
|
||||
@ -48,11 +49,11 @@ void pumpeSchalten(bool on) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
generalinfo.setPumpDuration(millis() - turnontime);
|
||||
generalinfo.setPumpDuration(Timer::getSystemSeconds() - turnontime);
|
||||
}
|
||||
|
||||
// save pump start time
|
||||
turnontime = millis();
|
||||
turnontime = Timer::getSystemSeconds();
|
||||
|
||||
digitalWrite(SchuetzPin, on);
|
||||
Serial.println("[Erfolg] pumpe wird geschalten");
|
||||
@ -90,7 +91,7 @@ void WasserSensorCheck() {
|
||||
//kein Wasser dh timer auf 10min stellen
|
||||
|
||||
// refresh wateroutage counter
|
||||
generalinfo.setlastWaterOutage(millis());
|
||||
generalinfo.setlastWaterOutage(Timer::getSystemSeconds());
|
||||
|
||||
allow = false;
|
||||
Serial.println("Schalte pumpe aus");
|
||||
|
Reference in New Issue
Block a user