moving sensor data collection to collector src
This commit is contained in:
58
fan_control/src/collector.cpp
Normal file
58
fan_control/src/collector.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "collector.hpp"
|
||||
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
// DHT Temperature & Humidity Sensor
|
||||
// Unified Sensor Library Example
|
||||
// Written by Tony DiCola for Adafruit Industries
|
||||
// Released under an MIT license.
|
||||
|
||||
// REQUIRES the following Arduino libraries:
|
||||
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
|
||||
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
|
||||
|
||||
// Set delay between sensor readings based on sensor details.
|
||||
uint32_t delayMS = 3000 ;
|
||||
|
||||
|
||||
// mini https://chewett.co.uk/blog/1066/pin-numbering-for-wemos-d1-mini-esp8266/
|
||||
DHT dht_in(4, DHT11); // D2 on mini
|
||||
DHT dht_out(5, DHT11); // D1 on mini
|
||||
|
||||
Collector collector;
|
||||
|
||||
void collector_setup(){
|
||||
// Initialize device.
|
||||
dht_in.begin();
|
||||
dht_out.begin();
|
||||
}
|
||||
|
||||
void collector_loop(){
|
||||
delay(delayMS);
|
||||
collector.add(1 , 2);
|
||||
|
||||
// Get temperature event and print its value.
|
||||
Serial.print(F("Temperature inside: "));
|
||||
Serial.print(dht_in.readTemperature());
|
||||
Serial.println(F("°C"));
|
||||
Serial.print(F("Temperature outside: "));
|
||||
Serial.print(dht_out.readTemperature());
|
||||
Serial.println("°C");
|
||||
}
|
||||
|
||||
void Collector::add(float in , float out)
|
||||
{
|
||||
minute += in;
|
||||
counter++ ;
|
||||
if(counter % bucket){
|
||||
int at_week = counter / bucket;
|
||||
week_in[at_week] = minute / bucket;
|
||||
minute = 0;
|
||||
}
|
||||
if(counter % (bucket*bucket)){
|
||||
int at_week = counter / bucket;
|
||||
month_in[at_week] = minute / bucket;
|
||||
counter = 0;
|
||||
}
|
||||
}
|
@ -4,26 +4,6 @@
|
||||
#include "server.hpp"
|
||||
#include "collector.hpp"
|
||||
|
||||
// DHT Temperature & Humidity Sensor
|
||||
// Unified Sensor Library Example
|
||||
// Written by Tony DiCola for Adafruit Industries
|
||||
// Released under an MIT license.
|
||||
|
||||
// REQUIRES the following Arduino libraries:
|
||||
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
|
||||
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
|
||||
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
|
||||
|
||||
// mini https://chewett.co.uk/blog/1066/pin-numbering-for-wemos-d1-mini-esp8266/
|
||||
DHT dht_in(4, DHT11); // D2 on mini
|
||||
DHT dht_out(5, DHT11); // D1 on mini
|
||||
|
||||
// Set delay between sensor readings based on sensor details.
|
||||
uint32_t delayMS = 3000 ;
|
||||
|
||||
const char* ssid = "fan_XXX";
|
||||
|
||||
@ -32,9 +12,6 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
ota_setup(ssid);
|
||||
server_setup();
|
||||
// Initialize device.
|
||||
dht_in.begin();
|
||||
dht_out.begin();
|
||||
Serial.println(F("Setup done"));
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
@ -43,15 +20,5 @@ void setup() {
|
||||
void loop() {
|
||||
ArduinoOTA.handle();
|
||||
server_loop();
|
||||
|
||||
// Delay between measurements.
|
||||
delay(1000);
|
||||
|
||||
// Get temperature event and print its value.
|
||||
Serial.print(F("Temperature inside: "));
|
||||
Serial.print(dht_in.readTemperature());
|
||||
Serial.println(F("°C"));
|
||||
Serial.print(F("Temperature outside: "));
|
||||
Serial.print(dht_out.readTemperature());
|
||||
Serial.println("°C");
|
||||
collector_loop();
|
||||
}
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#define DBG_OUTPUT_PORT Serial
|
||||
|
||||
ESP8266WebServer* serv = NULL;
|
||||
|
||||
|
||||
String getContentType(String filename){
|
||||
if(filename.indexOf(".htm") > 0) return "text/html";
|
||||
@ -28,7 +26,6 @@ bool handleFileRead(String path ){
|
||||
DBG_OUTPUT_PORT.println("handle: " + path);
|
||||
File file = LittleFS.open(path, "r");
|
||||
if(path.endsWith(".gz")){
|
||||
DBG_OUTPUT_PORT.println("sETTING GZIP" );
|
||||
//server.sendHeader("Content-Encoding" , "gzip");
|
||||
} else {
|
||||
contentType += ";charset=utf-8";
|
||||
|
Reference in New Issue
Block a user