new class for managing heating

This commit is contained in:
Lukas Heiligenbrunner 2020-11-10 17:38:33 +01:00
parent e0a27bf155
commit de792719ee
7 changed files with 109 additions and 14 deletions

50
src/Heating.cpp Normal file
View File

@ -0,0 +1,50 @@
//
// Created by lukas on 10.11.20.
//
#include "Heating.h"
#include "Pins.h"
void Heating::init(Temperature *tempsensor) {
mFanWaiting = false;
mHeizungTicker.attach(10, [&tempsensor, this]() {
// shedule this function because tempread is blocking
schedule_function([this, &tempsensor](){
// check temperature
Serial.println("checking humidity");
const float hum = tempsensor->getHum();
if (hum == -1) return;
Serial.print("humidity read: ");
Serial.println(hum);
if (hum > 65) {
// turn off active turnoff timers
mLuefterTicker.detach();
// turn on heating and fan
digitalWrite(LuefterPin, HIGH);
digitalWrite(HeizungPin, HIGH);
// if fan waiting detach its ticker
if (mFanWaiting) {
mLuefterTicker.detach();
mFanWaiting = false;
}
} else if (hum < 60) {
// if humidity too low turn off heating and fan after 60secs
digitalWrite(HeizungPin, LOW);
if (!mFanWaiting) {
mFanWaiting = true;
mLuefterTicker.once(60, []() {
// turn off fan
digitalWrite(LuefterPin, LOW);
Serial.println("turning off fan");
});
}
}
});
});
}

18
src/Heating.h Normal file
View File

@ -0,0 +1,18 @@
//
// Created by lukas on 10.11.20.
//
#pragma once
#include <Ticker.h>
#include "Temperature.h"
class Heating {
public:
void init(Temperature* tempsensor);
private:
Ticker mHeizungTicker;
Ticker mLuefterTicker;
bool mFanWaiting;
};

18
src/Pins.h Normal file
View File

@ -0,0 +1,18 @@
//
// Created by lukas on 10.11.20.
//
#ifndef PUMPENSTEUERUNG_PINS_H
#define PUMPENSTEUERUNG_PINS_H
#include <Arduino.h>
/** pin config */
#define WasserSensorPin D5 // GPIO 14
#define DruckSensorPin D6 // GPIO 12
#define SchuetzPin D2 // GPIO 4
#define LuefterPin D3 // GPIO 0
#define HeizungPin D1
#define TempSensorPin D4
#endif //PUMPENSTEUERUNG_PINS_H

View File

@ -6,10 +6,11 @@
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include "Pins.h"
class Temperature {
public:
Temperature() : dht(2, DHT22){};
Temperature() : dht(TempSensorPin, DHT22){};
/**
* initialize the temperature sensor

View File

@ -5,7 +5,7 @@
#include <EEPROM.h>
#include "WifiManager.h"
void WifiManager::init() {
void WifiManager::init(Temperature* tempsensor) {
Serial.print("Setting up Access Point");
// start softap
const bool result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2");
@ -32,7 +32,7 @@ void WifiManager::init() {
}
// init temperature sensor
temp.init();
temp = *tempsensor;
}
WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), lastPumpDuration(0) {}
@ -170,3 +170,7 @@ void WifiManager::setlastWaterOutage(unsigned long lastWaterOutage) {
void WifiManager::setPumpDuration(unsigned long lastPumpDuration) {
this->lastPumpDuration = lastPumpDuration;
}
Temperature *WifiManager::getTemperatureSensor() {
return &temp;
}

View File

@ -16,7 +16,7 @@ public:
/**
* initialize the webserver
*/
void init();
void init(Temperature* tempsensor);
/**
* handles new web requests and holds the webserver alive
@ -48,6 +48,8 @@ public:
*/
void setPumpDuration(unsigned long lastPumpDuration);
Temperature* getTemperatureSensor();
private:
// todo more dynamic
static const uint8_t WasserSensorPin = 14;

View File

@ -3,18 +3,17 @@
#include <EEPROM.h>
#include "WifiManager.h"
#include "Heating.h"
#include "Pins.h"
#include "Temperature.h"
#define VERSION "v1.1"
bool allow;
bool error = false;
/** pin config */
static const uint8_t WasserSensorPin = D5; // GPIO 14
static const uint8_t DruckSensorPin = D6; // GPIO 12
static const uint8_t SchuetzPin = D2; // GPIO 4
static const uint8_t LuefterPin = D3; // GPIO 0
static const uint8_t HeizungPin = D1;
/** time config */
static const int maxpumpdauer = 600; //sek
@ -25,10 +24,9 @@ Ticker status;
//pumpendauer maximum ticker
Ticker pumpendauer;
Ticker heizung;
Ticker luefter;
WifiManager mang;
Heating mHeat;
Temperature temp;
long turnontime = -1;
@ -179,7 +177,11 @@ void setup() {
// initialize wifi
mang.init();
temp.init();
mang.init(&temp);
mHeat.init(&temp);
Serial.println("startup sequence complete!\n");
digitalWrite(LED_BUILTIN, HIGH);