From 6596346d3d3bd3d6823738902cfeca76a6717140 Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Wed, 23 Jun 2021 01:30:28 +0200 Subject: [PATCH] ls -l implement and ota fw fix --- .vscode/settings.json | 4 ++- data/tt.html | 1 + doku.md | 15 +++++++++++ include/filesys.h | 2 +- src/filesys.cpp | 53 +++++++++++++++++++------------------- src/main.cpp | 60 ++++++++++++++++++++++++++----------------- 6 files changed, 83 insertions(+), 52 deletions(-) create mode 100644 data/tt.html diff --git a/.vscode/settings.json b/.vscode/settings.json index e9afe7d..34629f0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,8 @@ "vector": "cpp", "string_view": "cpp", "memory": "cpp", - "ranges": "cpp" + "ranges": "cpp", + "initializer_list": "cpp", + "utility": "cpp" } } \ No newline at end of file diff --git a/data/tt.html b/data/tt.html new file mode 100644 index 0000000..74076d0 --- /dev/null +++ b/data/tt.html @@ -0,0 +1 @@ +Hello from LittleFS ;) \ No newline at end of file diff --git a/doku.md b/doku.md index 20bbf7b..6f9dc96 100644 --- a/doku.md +++ b/doku.md @@ -22,4 +22,19 @@ GDB-Version aus Arduino Toolchain hat Support ```sh $ ./start_xtensa_gdb_stub.sh +``` + +### __Achtung !__ +Don`t forget __\r__ + +ESP-OTA wird von ufw oder Defender geblockt. +- Windows -> Python needs to be granted with rights +- Linux -> open udp port in ufw -> + +```sh +platform.ini +upload_flags = + --host-port +... +$ sudo ufw allow tcp/ ``` \ No newline at end of file diff --git a/include/filesys.h b/include/filesys.h index 1603367..454079b 100644 --- a/include/filesys.h +++ b/include/filesys.h @@ -6,7 +6,7 @@ bool mount_fs(); bool format_fs(); -void listDir(const char * dirname); +void ls(const char * dirname); void readFile(const char * path); void writeFile(const char * path, const char * message); void appendFile(const char * path, const char * message); diff --git a/src/filesys.cpp b/src/filesys.cpp index 2771761..8b84428 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -3,35 +3,36 @@ // listDir("/"); // deleteFile("/hello.txt"); // writeFile("/hello.txt", "Hello "); -// appendFile("/hello.txt", "World!\n"); +// appendFile("/hello.txt", "World!\n\r"); // readFile("/hello.txt"); // listDir("/"); FSInfo fsinfo; -void listDir(const char * dirname) { - Serial.printf("Listing directory: %s\n", dirname); +void ls(const char * dirname) { + Serial.printf("ls -l %s\n\r", dirname); Dir root = LittleFS.openDir(dirname); while (root.next()) { File file = root.openFile("r"); - Serial.print(" FILE: "); - Serial.print(root.fileName()); - Serial.print(" SIZE: "); - Serial.print(file.size()); - time_t cr = file.getCreationTime(); + time_t lw = file.getLastWrite(); + struct tm * tmstruct = localtime(&lw); + Serial.printf("%8d %02d %02d %02d:%02d %s\n\r", + file.size(), + tmstruct->tm_mon + 1, + tmstruct->tm_mday, + tmstruct->tm_hour, + tmstruct->tm_min, + root.fileName().c_str()); file.close(); - struct tm * tmstruct = localtime(&cr); - Serial.printf(" CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); - tmstruct = localtime(&lw); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); } + Serial.println(); } void readFile(const char * path) { - Serial.printf("Reading file: %s\n", path); + Serial.printf("Reading file: %s\n\r", path); File file = LittleFS.open(path, "r"); if (!file) { @@ -47,7 +48,7 @@ void readFile(const char * path) { } void writeFile(const char * path, const char * message) { - Serial.printf("Writing file: %s\n", path); + Serial.printf("Writing file: %s\n\r", path); File file = LittleFS.open(path, "w"); if (!file) { @@ -64,7 +65,7 @@ void writeFile(const char * path, const char * message) { } void appendFile(const char * path, const char * message) { - Serial.printf("Appending to file: %s\n", path); + Serial.printf("Appending to file: %s\n\r", path); File file = LittleFS.open(path, "a"); if (!file) { @@ -80,7 +81,7 @@ void appendFile(const char * path, const char * message) { } void renameFile(const char * path1, const char * path2) { - Serial.printf("Renaming file %s to %s\n", path1, path2); + Serial.printf("Renaming file %s to %s\n\r", path1, path2); if (LittleFS.rename(path1, path2)) { Serial.println("File renamed"); } else { @@ -89,7 +90,7 @@ void renameFile(const char * path1, const char * path2) { } void deleteFile(const char * path) { - Serial.printf("Deleting file: %s\n", path); + Serial.printf("Deleting file: %s\n\r", path); if (LittleFS.remove(path)) { Serial.println("File deleted"); } else { @@ -109,20 +110,20 @@ bool mount_fs() { return false; } - printf("Filesystem opened: \n"); - printf("\ttotalBytes:\t%d\n", fsinfo.totalBytes); - printf("\tusedBytes:\t%d\n", fsinfo.usedBytes); - printf("\tblockSize:\t%d\n", fsinfo.blockSize); - printf("\tpageSize:\t%d\n", fsinfo.pageSize); - printf("\tmaxOpenFiles:\t%d\n", fsinfo.maxOpenFiles); - printf("\tmaxPathLength:\t%d\n", fsinfo.maxPathLength); - printf("\n"); + 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"); + printf("Formatting FS ! \n\r"); return LittleFS.format(); } diff --git a/src/main.cpp b/src/main.cpp index 7451a3c..db09149 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,6 +87,10 @@ void setup_webserver() { server.on("/", handleRootGz); server.on("/style.css", handleCssGz); server.on("/favicon.png", handleFaviconGz); + // void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL ); + + server.serveStatic("/static", LittleFS, "/tt.html"); + server.onNotFound(handleNotFound); server.begin(); @@ -152,15 +156,15 @@ uint8_t onoff = 1; void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor); uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval, uint8_t factor); +uint8_t flag = 0; void timer_callback(void *pArg) { *((int *) pArg) += 1; - ledsequence(direction, onoff, 4); + flag = 1; } - void setup() { #ifdef WITH_DEBUGGING_ON Serial.begin(460800); @@ -173,8 +177,9 @@ void setup() { mount_fs(); //format_fs(); - listDir(""); - readFile("/test.txt"); + ls("/"); + ls("tester/"); + // readFile("/test.txt"); pinMode(NODEMCU_LED, OUTPUT); pinMode(ESP12_LED, OUTPUT); @@ -191,6 +196,23 @@ void setup() { ESP.restart(); } + + + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + + os_timer_setfn(&timer1, timer_callback, &timer_arg); + os_timer_arm(&timer1, 1000, true); + + Serial.println("Ready"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + + setup_ota(); + pinMode(led, OUTPUT); digitalWrite(led, 0); Serial.println(""); @@ -200,21 +222,6 @@ void setup() { delay(500); Serial.print("."); } - - Serial.println(""); - Serial.print("Connected to "); - Serial.println(ssid); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); - - os_timer_setfn(&timer1, timer_callback, &timer_arg); - os_timer_arm(&timer1, 1, true); - - Serial.println("Ready"); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); - - setup_ota(); setup_webserver(); setup_pwm_pca9685(); } @@ -301,9 +308,9 @@ void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor){ } } -uint32_t t; +uint32_t _t=0; #define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us") -#define TIMEIF_US(_str,_f, _l) t=micros(); _f; t=micros()-t; if(t > _l) { SP_US(_str, t); } +#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); } void loop() { if(millis() - dimmtimer > 2){ @@ -313,9 +320,14 @@ void loop() { if(millis() > 25000 && onoff == 1 && direction == 1) onoff = 0; if(millis() > 35000 && direction == 1){ onoff = 1; - direction = 0; + direction = 0; } - TIMEIF_US("OTA", ArduinoOTA.handle(), 1000); - TIMEIF_US("HTTP", server.handleClient(), 1000); + TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA"); + TIMEIF_US(server.handleClient(), 1000, "HTTP"); + if(flag) { + flag = 0; + ledsequence(direction, onoff, 4); + Serial.printf("[%lu] interrupt\n\r", millis()); + } } \ No newline at end of file