diff --git a/data/compress.html b/data/compress.html deleted file mode 100644 index e806476..0000000 --- a/data/compress.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - Ich bin ein komrpimierter Test - I bims der Head - - - I bims der Body - - - \ No newline at end of file diff --git a/data/index.html b/data/index.html index 204f746..5268123 100644 --- a/data/index.html +++ b/data/index.html @@ -62,9 +62,9 @@
- + - +
diff --git a/data/input.js b/data/input.js index d7dd8fd..89ff368 100644 --- a/data/input.js +++ b/data/input.js @@ -17,7 +17,7 @@ xhr.onreadystatechange = function(){ console.log(xhr.responseText); terminal = document.getElementById("term"); autoscroll = document.getElementById("scroll"); - terminal.innerHTML += xhr.responseText + '\n'; + terminal.innerHTML += xhr.responseText; if(autoscroll.checked) terminal.scrollTop = terminal.scrollHeight; } diff --git a/data/style.css b/data/style.css index beb3812..b7f5c5b 100644 --- a/data/style.css +++ b/data/style.css @@ -116,7 +116,7 @@ input:checked + .slider:before { #term { font-size: large; width: 100%; - height: 10em; + height: 20em; } #clear_term { diff --git a/lib/httpserver/httpserver.cpp b/lib/httpserver/httpserver.cpp index a053852..cba3375 100644 --- a/lib/httpserver/httpserver.cpp +++ b/lib/httpserver/httpserver.cpp @@ -6,8 +6,8 @@ bool HTTPServer::start() { logf("cant mount filesystem, EXIT !\n\r"); return false; } - logf("[HTTPServer] LittleFS mounted !\n\r"); - logf("[HTTPServer] root:\n\r"); + logf("LittleFS mounted !\n\r"); + logf("root:\n\r"); this->listRoot(); logf("\n\r"); @@ -30,15 +30,39 @@ bool HTTPServer::start() { // add static root file handler for http this->serveStatic("/", LittleFS, "/"); - + this->begin(); + Serial.printf("Server active on Port 80 !\n\r"); + return true; +} + +void HTTPServer::logf(const char *format, ...) { + va_list args; + va_start(args, format); + char temp[64]; + size_t len = vsnprintf(temp, sizeof(temp), format, args); + Serial.print(log_prefix); + Serial.write(temp, len); + va_end(args); +} + +void HTTPServer::logt(const char *format, ...) { + va_list args; + va_start(args, format); + // append logging string to local buffer + if(tbuf_head < TBUF_LEN) { + size_t len = vsnprintf(tbuf+tbuf_head, TBUF_LEN-tbuf_head, format, args); + tbuf_head += len; + } + va_end(args); +} + +void HTTPServer::start_apps() { // application handler this->on("/app=terminal", HTTP_POST, [this]() { - String log_msg = "terminal: millis: "; - log_msg += millis(); - send(200, "text/plain", log_msg); + if(tbuf_head) { + send(200, "text/plain", tbuf); + tbuf_head = 0; + } }); - this->begin(); - Serial.printf("[HTTPServer] Server active on Port 80 !\n\r"); - return true; } \ No newline at end of file diff --git a/lib/httpserver/httpserver.h b/lib/httpserver/httpserver.h index 0595ac7..e0471f9 100644 --- a/lib/httpserver/httpserver.h +++ b/lib/httpserver/httpserver.h @@ -2,6 +2,8 @@ #pragma once +#include + #include #include #include "filesys.h" @@ -9,24 +11,22 @@ // debug log // #define DEBUGV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) -#define LOG_STR "[HTTPServer]" +#define TBUF_LEN 256 class HTTPServer : public ESP8266WebServer { private: const char* rootDir = "/"; + const char* log_prefix = "[HTTPServer] "; + + size_t tbuf_head = 0; + char tbuf[TBUF_LEN]; void listRoot() { ls(rootDir); } - void logf(const char *format, ...) { - va_list args; - va_start(args, format); - Serial.print(LOG_STR); - Serial.printf(format, args); - va_end(args); - } + public: HTTPServer(const int _port, const char* _rootDir) : @@ -35,7 +35,11 @@ public: ~HTTPServer() { Serial.printf("[HTTPServer] shut down ...\n\r"); - } - + } + bool start(); + void start_apps(); + + void logf(const char *format, ...); + void logt(const char *format, ...); }; diff --git a/src/main.cpp b/src/main.cpp index bf7540e..995ee00 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,13 @@ Treppe stairs(16); const char* ssid = STASSID; const char* password = STAPSK; +// port 80, root directory of server '/' +HTTPServer httpServer(80, "/"); + +uint32_t _t=0; +#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us") +#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); } + void timerCallback(void *pArg) { @@ -34,16 +41,9 @@ void timerCallback(void *pArg) stairs.task(); } -// port 80, root directory of server '/' -HTTPServer httpServer(80, "/"); - -uint32_t _t=0; -#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us") -#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); } // =============================================== - void setup() { #ifdef WITH_DEBUGGING_ON Serial.begin(460800); @@ -78,6 +78,8 @@ void setup() { ota_setup(); httpServer.start(); + httpServer.start_apps(); + Serial.println("HTTP server started !"); stairs.setup(); @@ -89,6 +91,8 @@ void setup() { #include +uint32_t c = 0; + void loop() { // if(stairs.getState() == 0) { // delay(1000); @@ -102,6 +106,8 @@ void loop() { // stairs.setDirection(!stairs.getDirection()); // stairs.setState(1); // } + if(c++%1000000 == 0) + httpServer.logt("[%d] starting :)\n", c); TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA"); TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");