ugly hack
This commit is contained in:
+34
-37
@@ -1,14 +1,42 @@
|
||||
#include "filesys.h"
|
||||
|
||||
// listDir("/");
|
||||
// deleteFile("/hello.txt");
|
||||
// writeFile("/hello.txt", "Hello ");
|
||||
// appendFile("/hello.txt", "World!\n\r");
|
||||
// readFile("/hello.txt");
|
||||
// listDir("/");
|
||||
// listDir("/");
|
||||
// deleteFile("/hello.txt");
|
||||
// writeFile("/hello.txt", "Hello ");
|
||||
// appendFile("/hello.txt", "World!\n\r");
|
||||
// readFile("/hello.txt");
|
||||
// listDir("/");
|
||||
|
||||
FSInfo fsinfo;
|
||||
|
||||
bool mount_fs() {
|
||||
if(!LittleFS.begin()) {
|
||||
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!LittleFS.info(fsinfo)) {
|
||||
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Filesystem opened:\n\r");
|
||||
printf("\ttotalBytes:\t%d\n\r", fsinfo.totalBytes);
|
||||
printf("\tusedBytes:\t%d\n\r", fsinfo.usedBytes);
|
||||
printf("\tblockSize:\t%d\n\r", fsinfo.blockSize);
|
||||
printf("\tpageSize:\t%d\n\r", fsinfo.pageSize);
|
||||
printf("\tmaxOpenFiles:\t%d\n\r", fsinfo.maxOpenFiles);
|
||||
printf("\tmaxPathLength:\t%d\n\r", fsinfo.maxPathLength);
|
||||
printf("\n\r");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool format_fs() {
|
||||
printf("Formatting FS ! \n\r");
|
||||
return LittleFS.format();
|
||||
}
|
||||
|
||||
void ls(const char * dirname) {
|
||||
Serial.printf("ls -l %s\n\r", dirname);
|
||||
Dir root = LittleFS.openDir(dirname);
|
||||
@@ -30,7 +58,6 @@ void ls(const char * dirname) {
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void readFile(const char * path) {
|
||||
Serial.printf("Reading file: %s\n\r", path);
|
||||
|
||||
@@ -99,35 +126,5 @@ void deleteFile(const char * path) {
|
||||
}
|
||||
|
||||
|
||||
bool mount_fs() {
|
||||
if(!LittleFS.begin()) {
|
||||
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!LittleFS.info(fsinfo)) {
|
||||
Serial.println("[ERROR] LittleFS.info(), reset ...");
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Filesystem opened:\n\r");
|
||||
printf("\ttotalBytes:\t%d\n\r", fsinfo.totalBytes);
|
||||
printf("\tusedBytes:\t%d\n\r", fsinfo.usedBytes);
|
||||
printf("\tblockSize:\t%d\n\r", fsinfo.blockSize);
|
||||
printf("\tpageSize:\t%d\n\r", fsinfo.pageSize);
|
||||
printf("\tmaxOpenFiles:\t%d\n\r", fsinfo.maxOpenFiles);
|
||||
printf("\tmaxPathLength:\t%d\n\r", fsinfo.maxPathLength);
|
||||
printf("\n\r");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool format_fs() {
|
||||
printf("Formatting FS ! \n\r");
|
||||
return LittleFS.format();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "httpserver.h"
|
||||
|
||||
|
||||
bool HTTPServer::addRootFileHandler() {
|
||||
|
||||
// //experimental, see doku.md
|
||||
// server.serveStatic("/compressed", LittleFS, "/compressed.html.gzip");
|
||||
|
||||
server.serveStatic("", LittleFS, "/index.html");
|
||||
server.serveStatic("/", LittleFS, "/index.html");
|
||||
server.serveStatic("/#", LittleFS, "/index.html");
|
||||
server.serveStatic("/style.css", LittleFS, "/style.css");
|
||||
server.serveStatic("/input.js", LittleFS, "/input.js");
|
||||
server.serveStatic("/favicon.png", LittleFS, "/favicon.png");
|
||||
server.onNotFound(callbackFn);
|
||||
|
||||
server.begin();
|
||||
|
||||
configured = true;
|
||||
}
|
||||
+14
-32
@@ -19,9 +19,7 @@ extern "C" {
|
||||
#include <WiFiUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
#include "filesys.h"
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiClient.h>
|
||||
#include "httpserver.h"
|
||||
|
||||
#include "index.html.gz.h"
|
||||
#include "style.css.gz.h"
|
||||
@@ -40,40 +38,29 @@ void setup_pwm_pca9685();
|
||||
void handleNotFound();
|
||||
|
||||
const int led = 13;
|
||||
ESP8266WebServer server(80);
|
||||
PCA9685 pwmController;
|
||||
|
||||
HTTPServer httpServer(80, "/", handleNotFound);
|
||||
void handleNotFound() {
|
||||
String message = "File Not Found\n\n";
|
||||
message += "URI: ";
|
||||
message += server.uri();
|
||||
message += httpServer.server.uri();
|
||||
message += "\nMethod: ";
|
||||
message += (server.method() == HTTP_GET) ? "GET" : "POST";
|
||||
message += (httpServer.server.method() == HTTP_GET) ? "GET" : "POST";
|
||||
message += "\nArguments: ";
|
||||
message += server.args();
|
||||
message += httpServer.server.args();
|
||||
message += "\n";
|
||||
|
||||
for (uint8_t i = 0; i < server.args(); i++) {
|
||||
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
|
||||
for (uint8_t i = 0; i < httpServer.server.args(); i++) {
|
||||
message += " " + httpServer.server.argName(i) + ": " + httpServer.server.arg(i) + "\n";
|
||||
}
|
||||
server.send(404, "text/plain", message);
|
||||
|
||||
httpServer.server.send(404, "text/plain", message);
|
||||
}
|
||||
|
||||
PCA9685 pwmController;
|
||||
|
||||
void setup_webserver() {
|
||||
// //experimental, see doku.md
|
||||
// server.serveStatic("/compressed", LittleFS, "/compressed.html.gzip");
|
||||
|
||||
server.serveStatic("", LittleFS, "/index.html");
|
||||
server.serveStatic("/", LittleFS, "/index.html");
|
||||
server.serveStatic("/#", LittleFS, "/index.html");
|
||||
server.serveStatic("/style.css", LittleFS, "/style.css");
|
||||
server.serveStatic("/index.js", LittleFS, "/index.js");
|
||||
server.serveStatic("/favicon.png", LittleFS, "/favicon.png");
|
||||
server.onNotFound(handleNotFound);
|
||||
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void setup_ota() {
|
||||
ArduinoOTA.setPort(8266);
|
||||
@@ -153,11 +140,6 @@ void setup() {
|
||||
|
||||
Serial.println(F("Booting ...."));
|
||||
|
||||
mount_fs();
|
||||
//format_fs();
|
||||
ls("/");
|
||||
ls("http/");
|
||||
// readFile("/test.txt");
|
||||
|
||||
pinMode(NODEMCU_LED, OUTPUT);
|
||||
pinMode(ESP12_LED, OUTPUT);
|
||||
@@ -183,7 +165,7 @@ void setup() {
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
os_timer_setfn(&timer1, timer_callback, &timer_arg);
|
||||
os_timer_arm(&timer1, 1000, true);
|
||||
os_timer_arm(&timer1, 1, true);
|
||||
|
||||
Serial.println("Ready");
|
||||
Serial.print("IP address: ");
|
||||
@@ -191,7 +173,7 @@ void setup() {
|
||||
|
||||
setup_ota();
|
||||
|
||||
setup_webserver();
|
||||
httpServer.start();
|
||||
Serial.println("HTTP server started !");
|
||||
|
||||
setup_pwm_pca9685();
|
||||
@@ -295,11 +277,11 @@ void loop() {
|
||||
direction = 0;
|
||||
}
|
||||
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
||||
TIMEIF_US(server.handleClient(), 1000, "HTTP");
|
||||
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
||||
|
||||
if(flag) {
|
||||
flag = 0;
|
||||
ledsequence(direction, onoff, 4);
|
||||
Serial.printf("[%lu] interrupt\n\r", millis());
|
||||
//Serial.printf("[%lu] interrupt\n\r", millis());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user