fixing logging

This commit is contained in:
Torsten Ruger 2021-07-03 20:49:43 +03:00
parent 1785f07706
commit 9c6b39fd50
5 changed files with 32 additions and 24 deletions

View File

@ -23,7 +23,6 @@
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
var series = JSON.parse(this.responseText);
var data = { series: series };
chart = new Chartist.Line(clazz, data , {high: 30 , low: -25});
@ -38,19 +37,17 @@
}
var log = document.getElementById("log")
function myCallback() {
function get_log( ){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
log.innerHTML += this.responseText;
}
function get_log( ){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
log.innerHTML = this.responseText + log.innerHTML;
}
xhttp.open("GET", "/log", true);
xhttp.send();
};
}
}
xhttp.open("GET", "/log", true);
xhttp.send();
};
var intervalID = window.setInterval(get_log, 1500);
</script>
<script onload="load_charts();" src="/chartist.min.js.gz"> </script>

View File

@ -5,15 +5,22 @@ class WsSerial{
std::queue<String> debug;
public:
inline void print(const String& line){ debug.push(line); }
inline void println(const String& line){ debug.push(line); }
inline void print(const String& line){
// enable debug the debugging Serial.println(line.c_str());
debug.push(line);
}
inline void println(const String& line){
// enable debug the debugging Serial.println(line.c_str());
debug.push(line);
}
inline void println(const float num){ println(String(num)) ; };
inline const String& pop(){ const String& first = debug.front(); debug.pop(); return first;};
inline const String& first(){ return debug.front();};
inline void pop(){ debug.pop(); };
inline bool empty(){ return debug.empty();};
};
static WsSerial debug_out;
extern WsSerial debug_out;
#if(false)
#define DEBUG_OUT Serial

View File

@ -1,10 +1,8 @@
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncEventSource.h>
#include <LittleFS.h>
static AsyncWebServer server(80);
static AsyncEventSource events("/events");
void server_setup();
void server_loop();

View File

@ -5,6 +5,8 @@
#include <DHT.h>
#include <DHT_U.h>
WsSerial debug_out;
// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries

View File

@ -83,9 +83,15 @@ void server_setup(){
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);
String to_send = String(maxLen);
while(!debug_out.empty()){
String add_next = debug_out.first();
if( (add_next.length() + 5 + to_send.length() ) > maxLen ) break ; // dont overflow buffer
to_send.concat(add_next);
to_send.concat("<br/>");
debug_out.pop();
}
to_send.getBytes(buffer, maxLen);
return to_send.length();
});
request->send(response);
@ -116,8 +122,6 @@ void server_setup(){
server.onNotFound(notFound);
server.addHandler(&events);
server.begin();
}