abort events, polling instead

This commit is contained in:
Torsten Ruger
2021-07-02 23:20:42 +03:00
parent 3fad0f86f6
commit 1785f07706
6 changed files with 35 additions and 63 deletions

View File

@ -10,9 +10,8 @@ const char* ssid = "fan_XXX";
void setup() {
Serial.begin(115200);
server_setup();
serial_setup();
ota_setup(ssid);
server_setup();
collector_setup();
DEBUG_OUT.println(F("Setup done"));
DEBUG_OUT.print("IP address: ");
@ -22,6 +21,5 @@ void setup() {
void loop() {
ArduinoOTA.handle();
server_loop();
serial_loop();
collector_loop();
collector_loop();
}

View File

@ -1,31 +0,0 @@
#include "serial.hpp"
#include "server.hpp"
void WsSerial::print(const String& line){
debug.push(line);
}
void WsSerial::println(const String& line){
debug.push(line);
}
void serial_setup(){
events.onConnect([](AsyncEventSourceClient *client){
if(client->lastId()){
Serial.printf("Client reconnected! Last message ID that it gat is: %u\n", client->lastId());
}
//send event with message "hello!", id current millis
// and set reconnect delay to 1 second
client->send("hello!",NULL,millis(),1000);
});
}
void serial_loop(){
#if DEBUG_SERIAL
return;
#else
if(debug_out.empty()) return ;
const String & line = debug_out.pop();
Serial.println(line.c_str());
events.send(line.c_str() , "message");
#endif
}

View File

@ -37,6 +37,7 @@ void server_setup(){
if(week_counter == 2*WEEK){ // sent all data (ret 0), reset counter
week_counter = 0;
DEBUG_OUT.println("weekly end");
return 0;
}
String to_send = "";
@ -51,7 +52,6 @@ void server_setup(){
return to_send.length();
});
request->send(response);
DEBUG_OUT.println("weekly end");
});
server.on("/monthly", HTTP_ANY, [](AsyncWebServerRequest * request) {
@ -61,6 +61,7 @@ void server_setup(){
if(month_counter == 2*MONTH){ // sent all data (ret 0), reset counter
month_counter = 0;
DEBUG_OUT.println("monthly done");
return 0;
}
String to_send = "";
@ -76,8 +77,18 @@ void server_setup(){
return to_send.length();
});
request->send(response);
DEBUG_OUT.println("monthly done");
});
server.on("/log", HTTP_ANY, [](AsyncWebServerRequest * request) {
DEBUG_OUT.println("log start");
AsyncWebServerResponse *response = request->beginChunkedResponse("text/html", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
if(debug_out.empty()) return 0;
String to_send = debug_out.pop();
to_send += "<br/>";
to_send.getBytes(buffer, maxLen);
return to_send.length();
});
request->send(response);
});
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){