Merge branch 'newHardware' into 'master'
New hardware See merge request lukas/pumpensteuerung!2
This commit is contained in:
commit
94b635252d
86
src/Heating.cpp
Normal file
86
src/Heating.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
//
|
||||
// Created by lukas on 10.11.20.
|
||||
//
|
||||
|
||||
#include "Heating.h"
|
||||
#include "Pins.h"
|
||||
|
||||
void Heating::init(Temperature *tempsensor, unsigned mode) {
|
||||
switch (mode) {
|
||||
case TIME: {
|
||||
const unsigned percentOn = 20;
|
||||
const unsigned refreshperiod = 60;
|
||||
|
||||
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(refreshperiod * percentOn / 100, []() {
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
|
||||
Serial.println("Turned off heating!");
|
||||
});
|
||||
|
||||
mLuefterTicker.once((refreshperiod * percentOn / 100) + 30, []() {
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
|
||||
Serial.println("Turned off fan!");
|
||||
});
|
||||
};
|
||||
|
||||
func();
|
||||
mHeizungTicker.attach(60, func);
|
||||
break;
|
||||
}
|
||||
case HUMIDITY:
|
||||
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.0) {
|
||||
// turn off active turnoff timers
|
||||
mLuefterTicker.detach();
|
||||
Serial.println("heating should run now!");
|
||||
// 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.0) {
|
||||
// if humidity too low turn off heating and fan after 60secs
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
Serial.println("heating should NOT run now!");
|
||||
if (!mFanWaiting) {
|
||||
mFanWaiting = true;
|
||||
mLuefterTicker.once(60, []() {
|
||||
// turn off fan
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
Serial.println("turning off fan");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
21
src/Heating.h
Normal file
21
src/Heating.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by lukas on 10.11.20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Ticker.h>
|
||||
#include "Temperature.h"
|
||||
|
||||
class Heating {
|
||||
public:
|
||||
void init(Temperature* tempsensor, unsigned mode);
|
||||
|
||||
enum MODES {TIME, HUMIDITY};
|
||||
private:
|
||||
Ticker mHeizungTicker;
|
||||
Ticker mLuefterTicker;
|
||||
Ticker mTurnOffTicker;
|
||||
|
||||
bool mFanWaiting;
|
||||
};
|
18
src/Pins.h
Normal file
18
src/Pins.h
Normal 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
|
@ -6,10 +6,11 @@
|
||||
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include "Pins.h"
|
||||
|
||||
class Temperature {
|
||||
public:
|
||||
Temperature() : dht(4, DHT22){};
|
||||
Temperature() : dht(TempSensorPin, DHT22){};
|
||||
|
||||
/**
|
||||
* initialize the temperature sensor
|
||||
|
@ -4,8 +4,9 @@
|
||||
|
||||
#include <EEPROM.h>
|
||||
#include "WifiManager.h"
|
||||
#include "Pins.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 +33,7 @@ void WifiManager::init() {
|
||||
}
|
||||
|
||||
// init temperature sensor
|
||||
temp.init();
|
||||
temp = *tempsensor;
|
||||
}
|
||||
|
||||
WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), lastPumpDuration(0) {}
|
||||
@ -170,3 +171,7 @@ void WifiManager::setlastWaterOutage(unsigned long lastWaterOutage) {
|
||||
void WifiManager::setPumpDuration(unsigned long lastPumpDuration) {
|
||||
this->lastPumpDuration = lastPumpDuration;
|
||||
}
|
||||
|
||||
Temperature *WifiManager::getTemperatureSensor() {
|
||||
return &temp;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
/**
|
||||
* initialize the webserver
|
||||
*/
|
||||
void init();
|
||||
void init(Temperature* tempsensor);
|
||||
|
||||
/**
|
||||
* handles new web requests and holds the webserver alive
|
||||
@ -48,10 +48,9 @@ public:
|
||||
*/
|
||||
void setPumpDuration(unsigned long lastPumpDuration);
|
||||
|
||||
Temperature* getTemperatureSensor();
|
||||
|
||||
private:
|
||||
// todo more dynamic
|
||||
static const uint8_t WasserSensorPin = 14;
|
||||
static const uint8_t DruckSensorPin = 12;
|
||||
|
||||
ESP8266WebServer server;
|
||||
Temperature temp;
|
||||
|
43
src/main.cpp
43
src/main.cpp
@ -3,16 +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 = 14;
|
||||
static const uint8_t DruckSensorPin = 12;
|
||||
static const uint8_t SchuetzPin = 13;
|
||||
|
||||
|
||||
/** time config */
|
||||
static const int maxpumpdauer = 600; //sek
|
||||
@ -24,6 +25,8 @@ Ticker status;
|
||||
Ticker pumpendauer;
|
||||
|
||||
WifiManager mang;
|
||||
Heating mHeat;
|
||||
Temperature temp;
|
||||
|
||||
long turnontime = -1;
|
||||
|
||||
@ -132,17 +135,25 @@ ICACHE_RAM_ATTR void WasserSensorInt() {
|
||||
}
|
||||
|
||||
void setup() {
|
||||
digitalWrite(SchuetzPin, LOW); //pumpe anfangs sofort abschalten
|
||||
// set pins as output
|
||||
pinMode(SchuetzPin, OUTPUT);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
pinMode(LuefterPin, OUTPUT);
|
||||
pinMode(HeizungPin, OUTPUT);
|
||||
|
||||
pinMode(WasserSensorPin, INPUT);
|
||||
pinMode(DruckSensorPin, INPUT);
|
||||
|
||||
// initialize pins
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
digitalWrite(SchuetzPin, LOW); //pumpe anfangs sofort abschalten
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
//
|
||||
// digitalWrite(HeizungPin, HIGH);
|
||||
// delay(1000000);
|
||||
|
||||
// initilize serial connection
|
||||
Serial.begin(9600);
|
||||
Serial.println("\n\n\n\nstartup of ESP");
|
||||
Serial.print("Version: ");
|
||||
@ -162,16 +173,26 @@ void setup() {
|
||||
DruckschalterInt();
|
||||
|
||||
|
||||
|
||||
//anhängen der Pin-Interrupts
|
||||
attachInterrupt(digitalPinToInterrupt(DruckSensorPin), DruckschalterInt, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(WasserSensorPin), WasserSensorInt, CHANGE);
|
||||
|
||||
|
||||
// initialize wifi
|
||||
Serial.println("initializing temperature sensor!");
|
||||
temp.init();
|
||||
Serial.print("initial read temperature: ");
|
||||
Serial.println(temp.getTemp());
|
||||
|
||||
Serial.println("Initializing wifi");
|
||||
mang.init(&temp);
|
||||
|
||||
Serial.println("initializing heating service");
|
||||
mHeat.init(&temp, Heating::TIME);
|
||||
|
||||
Serial.println("startup sequence complete!\n");
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
|
||||
mang.init();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user