updates to http terminal
This commit is contained in:
parent
a0f6a5aec3
commit
66e8ddb2d9
@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>Ich bin ein komrpimierter Test</title>
|
|
||||||
I bims der Head
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
I bims der Body
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -62,9 +62,9 @@
|
|||||||
|
|
||||||
<div class="terminal">
|
<div class="terminal">
|
||||||
<input type="button" id="clear_term" value="clear" onclick="clearTerminal();">
|
<input type="button" id="clear_term" value="clear" onclick="clearTerminal();">
|
||||||
<input type="checkbox" id="scroll" name="scroll" value="scroll">
|
<input type="checkbox" id="scroll" name="scroll" value="scroll" checked>
|
||||||
<label for="scroll"> autoscroll </label>
|
<label for="scroll"> autoscroll </label>
|
||||||
<textarea id="term"> waiting for log messages ... </textarea>
|
<textarea id="term">waiting for log messages ... </textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -17,7 +17,7 @@ xhr.onreadystatechange = function(){
|
|||||||
console.log(xhr.responseText);
|
console.log(xhr.responseText);
|
||||||
terminal = document.getElementById("term");
|
terminal = document.getElementById("term");
|
||||||
autoscroll = document.getElementById("scroll");
|
autoscroll = document.getElementById("scroll");
|
||||||
terminal.innerHTML += xhr.responseText + '\n';
|
terminal.innerHTML += xhr.responseText;
|
||||||
if(autoscroll.checked)
|
if(autoscroll.checked)
|
||||||
terminal.scrollTop = terminal.scrollHeight;
|
terminal.scrollTop = terminal.scrollHeight;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ input:checked + .slider:before {
|
|||||||
#term {
|
#term {
|
||||||
font-size: large;
|
font-size: large;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 10em;
|
height: 20em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#clear_term {
|
#clear_term {
|
||||||
|
@ -6,8 +6,8 @@ bool HTTPServer::start() {
|
|||||||
logf("cant mount filesystem, EXIT !\n\r");
|
logf("cant mount filesystem, EXIT !\n\r");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
logf("[HTTPServer] LittleFS mounted !\n\r");
|
logf("LittleFS mounted !\n\r");
|
||||||
logf("[HTTPServer] root:\n\r");
|
logf("root:\n\r");
|
||||||
this->listRoot();
|
this->listRoot();
|
||||||
logf("\n\r");
|
logf("\n\r");
|
||||||
|
|
||||||
@ -30,15 +30,39 @@ bool HTTPServer::start() {
|
|||||||
|
|
||||||
// add static root file handler for http
|
// add static root file handler for http
|
||||||
this->serveStatic("/", LittleFS, "/");
|
this->serveStatic("/", LittleFS, "/");
|
||||||
|
|
||||||
// application handler
|
|
||||||
this->on("/app=terminal", HTTP_POST, [this]() {
|
|
||||||
String log_msg = "terminal: millis: ";
|
|
||||||
log_msg += millis();
|
|
||||||
send(200, "text/plain", log_msg);
|
|
||||||
});
|
|
||||||
|
|
||||||
this->begin();
|
this->begin();
|
||||||
Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
|
Serial.printf("Server active on Port 80 !\n\r");
|
||||||
return true;
|
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]() {
|
||||||
|
if(tbuf_head) {
|
||||||
|
send(200, "text/plain", tbuf);
|
||||||
|
tbuf_head = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "filesys.h"
|
#include "filesys.h"
|
||||||
@ -9,24 +11,22 @@
|
|||||||
// debug log <ESP8266WebServer.h>
|
// debug log <ESP8266WebServer.h>
|
||||||
// #define DEBUGV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
// #define DEBUGV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
||||||
|
|
||||||
#define LOG_STR "[HTTPServer]"
|
#define TBUF_LEN 256
|
||||||
|
|
||||||
|
|
||||||
class HTTPServer : public ESP8266WebServer {
|
class HTTPServer : public ESP8266WebServer {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* rootDir = "/";
|
const char* rootDir = "/";
|
||||||
|
const char* log_prefix = "[HTTPServer] ";
|
||||||
|
|
||||||
|
size_t tbuf_head = 0;
|
||||||
|
char tbuf[TBUF_LEN];
|
||||||
|
|
||||||
void listRoot() {
|
void listRoot() {
|
||||||
ls(rootDir);
|
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:
|
public:
|
||||||
HTTPServer(const int _port, const char* _rootDir) :
|
HTTPServer(const int _port, const char* _rootDir) :
|
||||||
@ -38,4 +38,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool start();
|
bool start();
|
||||||
|
void start_apps();
|
||||||
|
|
||||||
|
void logf(const char *format, ...);
|
||||||
|
void logt(const char *format, ...);
|
||||||
};
|
};
|
||||||
|
20
src/main.cpp
20
src/main.cpp
@ -27,6 +27,13 @@ Treppe stairs(16);
|
|||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
const char* password = STAPSK;
|
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)
|
void timerCallback(void *pArg)
|
||||||
{
|
{
|
||||||
@ -34,16 +41,9 @@ void timerCallback(void *pArg)
|
|||||||
stairs.task();
|
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() {
|
void setup() {
|
||||||
#ifdef WITH_DEBUGGING_ON
|
#ifdef WITH_DEBUGGING_ON
|
||||||
Serial.begin(460800);
|
Serial.begin(460800);
|
||||||
@ -78,6 +78,8 @@ void setup() {
|
|||||||
ota_setup();
|
ota_setup();
|
||||||
|
|
||||||
httpServer.start();
|
httpServer.start();
|
||||||
|
httpServer.start_apps();
|
||||||
|
|
||||||
Serial.println("HTTP server started !");
|
Serial.println("HTTP server started !");
|
||||||
|
|
||||||
stairs.setup();
|
stairs.setup();
|
||||||
@ -89,6 +91,8 @@ void setup() {
|
|||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
|
uint32_t c = 0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// if(stairs.getState() == 0) {
|
// if(stairs.getState() == 0) {
|
||||||
// delay(1000);
|
// delay(1000);
|
||||||
@ -102,6 +106,8 @@ void loop() {
|
|||||||
// stairs.setDirection(!stairs.getDirection());
|
// stairs.setDirection(!stairs.getDirection());
|
||||||
// stairs.setState(1);
|
// stairs.setState(1);
|
||||||
// }
|
// }
|
||||||
|
if(c++%1000000 == 0)
|
||||||
|
httpServer.logt("[%d] starting :)\n", c);
|
||||||
|
|
||||||
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
||||||
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user