redirecting serial
This commit is contained in:
parent
abe85144a1
commit
e37fa901ab
3
fan_control/include/serial.hpp
Normal file
3
fan_control/include/serial.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#define DEBUG_OUT Serial
|
@ -1,4 +1,5 @@
|
||||
#include "collector.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
@ -33,14 +34,14 @@ void collector_setup(){
|
||||
|
||||
void collector_loop(){
|
||||
delay(delayMS);
|
||||
|
||||
// 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");
|
||||
float in = dht_in.readTemperature();
|
||||
float out = dht_out.readTemperature();
|
||||
DEBUG_OUT.print(F("Temperature inside: "));
|
||||
DEBUG_OUT.println(in);
|
||||
DEBUG_OUT.print(F("Temperature outside: "));
|
||||
DEBUG_OUT.println(out);
|
||||
collector.add(in , out);
|
||||
}
|
||||
|
||||
void Collector::add(float in , float out)
|
||||
@ -48,12 +49,12 @@ void Collector::add(float in , float out)
|
||||
minute += in;
|
||||
counter++ ;
|
||||
if(counter % bucket){
|
||||
int at_week = counter / bucket;
|
||||
int at_week = counter / bucket;
|
||||
week_in[at_week] = minute / bucket;
|
||||
minute = 0;
|
||||
}
|
||||
if(counter % (bucket*bucket)){
|
||||
int at_week = counter / bucket;
|
||||
int at_week = counter / bucket;
|
||||
month_in[at_week] = minute / bucket;
|
||||
counter = 0;
|
||||
}
|
||||
@ -63,7 +64,7 @@ String Collector::one_week(float week[]){
|
||||
String data = "[";
|
||||
data += week[0];
|
||||
for( int a = 1; a < WEEK ; a = a + 1 ) {
|
||||
data += "," ;
|
||||
data += "," ;
|
||||
data += week[a] ;
|
||||
}
|
||||
return data + "]";
|
||||
@ -78,7 +79,7 @@ String Collector::one_month(float month[]){
|
||||
String data = "[";
|
||||
data += month[0];
|
||||
for( int a = 1; a < MONTH ; a = a + 1 ) {
|
||||
data += "," ;
|
||||
data += "," ;
|
||||
data += month[a] ;
|
||||
}
|
||||
return data + "]";
|
||||
|
@ -3,18 +3,18 @@
|
||||
#include "ota.hpp"
|
||||
#include "server.hpp"
|
||||
#include "collector.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
|
||||
const char* ssid = "fan_XXX";
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
DEBUG_OUT.begin(115200);
|
||||
ota_setup(ssid);
|
||||
server_setup();
|
||||
Serial.println(F("Setup done"));
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
DEBUG_OUT.println(F("Setup done"));
|
||||
DEBUG_OUT.print("IP address: ");
|
||||
DEBUG_OUT.println(WiFi.softAPIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -1,15 +1,16 @@
|
||||
#include "ota.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
void ota_setup(const char* ssid) {
|
||||
|
||||
Serial.println("Booting");
|
||||
DEBUG_OUT.println("Booting");
|
||||
boolean result = WiFi.softAP(ssid);
|
||||
while (result == false) {
|
||||
Serial.println("Connection Failed! Rebooting...");
|
||||
DEBUG_OUT.println("Connection Failed! Rebooting...");
|
||||
delay(5000);
|
||||
ESP.restart();
|
||||
}
|
||||
Serial.println(WiFi.softAPIP());
|
||||
DEBUG_OUT.println(WiFi.softAPIP());
|
||||
|
||||
// Port defaults to 3232
|
||||
// ArduinoOTA.setPort(8266);
|
||||
@ -32,21 +33,21 @@ void ota_setup(const char* ssid) {
|
||||
type = "filesystem";
|
||||
|
||||
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
||||
Serial.println("Start updating " + type);
|
||||
DEBUG_OUT.println("Start updating " + type);
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
Serial.println("\nEnd");
|
||||
DEBUG_OUT.println("\nEnd");
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
DEBUG_OUT.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
DEBUG_OUT.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) DEBUG_OUT.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) DEBUG_OUT.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) DEBUG_OUT.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) DEBUG_OUT.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) DEBUG_OUT.println("End Failed");
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "server.hpp"
|
||||
#include "collector.hpp"
|
||||
#include <FS.h>
|
||||
#include "serial.hpp"
|
||||
|
||||
#define DBG_OUTPUT_PORT Serial
|
||||
#include <FS.h>
|
||||
|
||||
|
||||
String getContentType(String filename){
|
||||
@ -20,11 +20,11 @@ String getContentType(String filename){
|
||||
}
|
||||
|
||||
bool handleFileRead(String path ){
|
||||
DBG_OUTPUT_PORT.println("handleFileRead: " + path);
|
||||
DEBUG_OUT.println("handleFileRead: " + path);
|
||||
if(path.endsWith("/")) path += "index.html";
|
||||
String contentType = getContentType(path) + ";charset=utf-8";
|
||||
if(LittleFS.exists(path)){
|
||||
DBG_OUTPUT_PORT.println("handle: " + path);
|
||||
DEBUG_OUT.println("handle: " + path);
|
||||
File file = LittleFS.open(path, "r");
|
||||
if(path.endsWith(".gz")){
|
||||
//server.sendHeader("Content-Encoding" , "gzip");
|
||||
@ -39,15 +39,15 @@ bool handleFileRead(String path ){
|
||||
}
|
||||
|
||||
void getWeekly() {
|
||||
Serial.println("Weekly start");
|
||||
DEBUG_OUT.println("Weekly start");
|
||||
String data = collector.week_data();
|
||||
Serial.println("Weekly end");
|
||||
DEBUG_OUT.println("Weekly end");
|
||||
server.send(200, "text/html", data);
|
||||
}
|
||||
void getMonthly() {
|
||||
Serial.println("Monthly start");
|
||||
DEBUG_OUT.println("Monthly start");
|
||||
String data = collector.month_data();
|
||||
Serial.println("Monthly end");
|
||||
DEBUG_OUT.println("Monthly end");
|
||||
server.send(200, "text/html", data);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ void server_setup(){
|
||||
server.on("/monthly", getMonthly);
|
||||
|
||||
server.begin();
|
||||
Serial.println("HTTP server started");
|
||||
DEBUG_OUT.println("HTTP server started");
|
||||
|
||||
server.onNotFound([](){
|
||||
if(!handleFileRead(server.uri()))
|
||||
@ -67,4 +67,4 @@ void server_setup(){
|
||||
|
||||
void server_loop() {
|
||||
server.handleClient();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user