added gzip for webpage and preprocessor timing wrapper

This commit is contained in:
2021-06-11 00:01:04 +02:00
parent dbf2d51769
commit 03d9f87159
11 changed files with 5757 additions and 77 deletions
+28 -46
View File
@@ -1,20 +1,22 @@
#include <Arduino.h>
#include <Wire.h>
#include "wifi_credentials.h"
#include "PCA9685.h"
// OTA & WEB
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h> // evtl weghauen ?
#include "wifi_credentials.h"
#include "index.html.h"
#include "index.html.gz.h"
#include "style.css.gz.h"
// images are possible
// maybe check out FS <- SPIFFS
const char* ssid = STASSID;
const char* password = STAPSK;
@@ -22,15 +24,19 @@ const char* password = STAPSK;
const int led = 13;
ESP8266WebServer server(80);
void handleRoot() {
digitalWrite(led, 1);
// char temp[sizeof(index_html)];
// snprintf(temp, sizeof(index_html), index_html);
server.send(200, "text/html", index_html);
digitalWrite(led, 0);
void handleRootGz() {
const char* dataType = "text/html";
server.sendHeader(F("Content-Encoding"), F("gzip"));
server.send(200, dataType, (const char*)index_html_gz, index_html_gz_len);
}
void handleCssGz() {
const char* dataType = "text/css";
server.sendHeader(F("Content-Encoding"), F("gzip"));
server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len);
}
void handleNotFound() {
digitalWrite(led, 1);
String message = "File Not Found\n\n";
@@ -68,15 +74,11 @@ void setup_webserver() {
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
});
//server.on("/", handleRoot);
server.on("/", handleRootGz);
server.on("/styles/style.css", handleCssGz);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
@@ -157,32 +159,12 @@ void setup() {
}
unsigned long i = 0;
unsigned long a = 0;
unsigned long s = 0;
float ard_ota_time = 0;
float server_handle = 0;
uint32_t t;
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("µs")
#define TIMEIF_US(_str,_f, _l) t=micros(); _f; t=micros()-t; if(t > _l) { SP_US(_str, t); }
void loop() {
a = micros();
ArduinoOTA.handle();
ard_ota_time += micros()-a;
TIMEIF_US("OTA", ArduinoOTA.handle(), 20000);
s = micros();
server.handleClient();
server_handle += micros()-s;
if(++i >= 10000) {
Serial.print("Mittlere Laufzeit\tOTA: ");
Serial.print(ard_ota_time/10000.0);
Serial.print("µs\tHTTP: ");
Serial.print(server_handle/10000.0);
Serial.println("µs");
ard_ota_time = 0;
server_handle = 0;
i = 0;
}
TIMEIF_US("HTTP", server.handleClient(), 20000);
}