new class for managing heating
This commit is contained in:
		
							
								
								
									
										50
									
								
								src/Heating.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/Heating.cpp
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										18
									
								
								src/Heating.h
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										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 <Adafruit_Sensor.h>
 | 
				
			||||||
#include <DHT.h>
 | 
					#include <DHT.h>
 | 
				
			||||||
 | 
					#include "Pins.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Temperature {
 | 
					class Temperature {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    Temperature() : dht(2, DHT22){};
 | 
					    Temperature() : dht(TempSensorPin, DHT22){};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * initialize the temperature sensor
 | 
					     * initialize the temperature sensor
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@
 | 
				
			|||||||
#include <EEPROM.h>
 | 
					#include <EEPROM.h>
 | 
				
			||||||
#include "WifiManager.h"
 | 
					#include "WifiManager.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WifiManager::init() {
 | 
					void WifiManager::init(Temperature* tempsensor) {
 | 
				
			||||||
    Serial.print("Setting up Access Point");
 | 
					    Serial.print("Setting up Access Point");
 | 
				
			||||||
    // start softap
 | 
					    // start softap
 | 
				
			||||||
    const bool result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2");
 | 
					    const bool result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2");
 | 
				
			||||||
@@ -32,7 +32,7 @@ void WifiManager::init() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // init temperature sensor
 | 
					    // init temperature sensor
 | 
				
			||||||
    temp.init();
 | 
					    temp = *tempsensor;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), lastPumpDuration(0) {}
 | 
					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) {
 | 
					void WifiManager::setPumpDuration(unsigned long lastPumpDuration) {
 | 
				
			||||||
    this->lastPumpDuration = lastPumpDuration;
 | 
					    this->lastPumpDuration = lastPumpDuration;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Temperature *WifiManager::getTemperatureSensor() {
 | 
				
			||||||
 | 
					    return &temp;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,7 @@ public:
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * initialize the webserver
 | 
					     * initialize the webserver
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void init();
 | 
					    void init(Temperature* tempsensor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * handles new web requests and holds the webserver alive
 | 
					     * handles new web requests and holds the webserver alive
 | 
				
			||||||
@@ -48,6 +48,8 @@ public:
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    void setPumpDuration(unsigned long lastPumpDuration);
 | 
					    void setPumpDuration(unsigned long lastPumpDuration);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Temperature* getTemperatureSensor();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    // todo more dynamic
 | 
					    // todo more dynamic
 | 
				
			||||||
    static const uint8_t WasserSensorPin = 14;
 | 
					    static const uint8_t WasserSensorPin = 14;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -3,18 +3,17 @@
 | 
				
			|||||||
#include <EEPROM.h>
 | 
					#include <EEPROM.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "WifiManager.h"
 | 
					#include "WifiManager.h"
 | 
				
			||||||
 | 
					#include "Heating.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Pins.h"
 | 
				
			||||||
 | 
					#include "Temperature.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define VERSION "v1.1"
 | 
					#define VERSION "v1.1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool allow;
 | 
					bool allow;
 | 
				
			||||||
bool error = false;
 | 
					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 */
 | 
					/** time config */
 | 
				
			||||||
static const int maxpumpdauer = 600; //sek
 | 
					static const int maxpumpdauer = 600; //sek
 | 
				
			||||||
@@ -25,10 +24,9 @@ Ticker status;
 | 
				
			|||||||
//pumpendauer maximum ticker
 | 
					//pumpendauer maximum ticker
 | 
				
			||||||
Ticker pumpendauer;
 | 
					Ticker pumpendauer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Ticker heizung;
 | 
					 | 
				
			||||||
Ticker luefter;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
WifiManager mang;
 | 
					WifiManager mang;
 | 
				
			||||||
 | 
					Heating mHeat;
 | 
				
			||||||
 | 
					Temperature temp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
long turnontime = -1;
 | 
					long turnontime = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -179,7 +177,11 @@ void setup() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // initialize wifi
 | 
					    // initialize wifi
 | 
				
			||||||
    mang.init();
 | 
					    temp.init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mang.init(&temp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mHeat.init(&temp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Serial.println("startup sequence complete!\n");
 | 
					    Serial.println("startup sequence complete!\n");
 | 
				
			||||||
    digitalWrite(LED_BUILTIN, HIGH);
 | 
					    digitalWrite(LED_BUILTIN, HIGH);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user