sending debug over ws events (wip)

This commit is contained in:
2021-07-01 23:46:32 +03:00
parent a0b01f4839
commit 3fad0f86f6
8 changed files with 90 additions and 9 deletions

View File

@ -9,17 +9,19 @@
const char* ssid = "fan_XXX";
void setup() {
DEBUG_OUT.begin(115200);
ota_setup(ssid);
Serial.begin(115200);
server_setup();
serial_setup();
ota_setup(ssid);
collector_setup();
DEBUG_OUT.println(F("Setup done"));
DEBUG_OUT.print("IP address: ");
DEBUG_OUT.println(WiFi.softAPIP());
DEBUG_OUT.println(WiFi.softAPIP().toString());
}
void loop() {
ArduinoOTA.handle();
server_loop();
serial_loop();
collector_loop();
}

View File

@ -10,7 +10,7 @@ void ota_setup(const char* ssid) {
delay(5000);
ESP.restart();
}
DEBUG_OUT.println(WiFi.softAPIP());
DEBUG_OUT.println(WiFi.softAPIP().toString());
// Port defaults to 3232
// ArduinoOTA.setPort(8266);
@ -39,10 +39,10 @@ void ota_setup(const char* ssid) {
DEBUG_OUT.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
DEBUG_OUT.printf("Progress: %u%%\r", (progress / (total / 100)));
DEBUG_OUT.println("Progress:" +String(progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
DEBUG_OUT.printf("Error[%u]: ", error);
DEBUG_OUT.print("Error[" + String(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");

View File

@ -0,0 +1,31 @@
#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

@ -4,7 +4,6 @@
#include <FS.h>
#define DEBUG_OUT Serial
String getContentType(String filename){
if(filename.indexOf(".htm") > 0) return "text/html";
@ -106,6 +105,8 @@ void server_setup(){
server.onNotFound(notFound);
server.addHandler(&events);
server.begin();
}