ls -l implement and ota fw fix

This commit is contained in:
Simon Schmidt 2021-06-23 01:30:28 +02:00
parent b696703d45
commit 6596346d3d
6 changed files with 83 additions and 52 deletions

View File

@ -10,6 +10,8 @@
"vector": "cpp", "vector": "cpp",
"string_view": "cpp", "string_view": "cpp",
"memory": "cpp", "memory": "cpp",
"ranges": "cpp" "ranges": "cpp",
"initializer_list": "cpp",
"utility": "cpp"
} }
} }

1
data/tt.html Normal file
View File

@ -0,0 +1 @@
Hello from LittleFS ;)

15
doku.md
View File

@ -22,4 +22,19 @@ GDB-Version aus Arduino Toolchain hat Support
```sh ```sh
$ ./start_xtensa_gdb_stub.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 <PORT>
...
$ sudo ufw allow tcp/<PORT>
``` ```

View File

@ -6,7 +6,7 @@
bool mount_fs(); bool mount_fs();
bool format_fs(); bool format_fs();
void listDir(const char * dirname); void ls(const char * dirname);
void readFile(const char * path); void readFile(const char * path);
void writeFile(const char * path, const char * message); void writeFile(const char * path, const char * message);
void appendFile(const char * path, const char * message); void appendFile(const char * path, const char * message);

View File

@ -3,35 +3,36 @@
// listDir("/"); // listDir("/");
// deleteFile("/hello.txt"); // deleteFile("/hello.txt");
// writeFile("/hello.txt", "Hello "); // writeFile("/hello.txt", "Hello ");
// appendFile("/hello.txt", "World!\n"); // appendFile("/hello.txt", "World!\n\r");
// readFile("/hello.txt"); // readFile("/hello.txt");
// listDir("/"); // listDir("/");
FSInfo fsinfo; FSInfo fsinfo;
void listDir(const char * dirname) { void ls(const char * dirname) {
Serial.printf("Listing directory: %s\n", dirname); Serial.printf("ls -l %s\n\r", dirname);
Dir root = LittleFS.openDir(dirname); Dir root = LittleFS.openDir(dirname);
while (root.next()) { while (root.next()) {
File file = root.openFile("r"); 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(); 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(); 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) { 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"); File file = LittleFS.open(path, "r");
if (!file) { if (!file) {
@ -47,7 +48,7 @@ void readFile(const char * path) {
} }
void writeFile(const char * path, const char * message) { 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"); File file = LittleFS.open(path, "w");
if (!file) { if (!file) {
@ -64,7 +65,7 @@ void writeFile(const char * path, const char * message) {
} }
void appendFile(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"); File file = LittleFS.open(path, "a");
if (!file) { if (!file) {
@ -80,7 +81,7 @@ void appendFile(const char * path, const char * message) {
} }
void renameFile(const char * path1, const char * path2) { 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)) { if (LittleFS.rename(path1, path2)) {
Serial.println("File renamed"); Serial.println("File renamed");
} else { } else {
@ -89,7 +90,7 @@ void renameFile(const char * path1, const char * path2) {
} }
void deleteFile(const char * path) { void deleteFile(const char * path) {
Serial.printf("Deleting file: %s\n", path); Serial.printf("Deleting file: %s\n\r", path);
if (LittleFS.remove(path)) { if (LittleFS.remove(path)) {
Serial.println("File deleted"); Serial.println("File deleted");
} else { } else {
@ -109,20 +110,20 @@ bool mount_fs() {
return false; return false;
} }
printf("Filesystem opened: \n"); printf("Filesystem opened:\n\r");
printf("\ttotalBytes:\t%d\n", fsinfo.totalBytes); printf("\ttotalBytes:\t%d\n\r", fsinfo.totalBytes);
printf("\tusedBytes:\t%d\n", fsinfo.usedBytes); printf("\tusedBytes:\t%d\n\r", fsinfo.usedBytes);
printf("\tblockSize:\t%d\n", fsinfo.blockSize); printf("\tblockSize:\t%d\n\r", fsinfo.blockSize);
printf("\tpageSize:\t%d\n", fsinfo.pageSize); printf("\tpageSize:\t%d\n\r", fsinfo.pageSize);
printf("\tmaxOpenFiles:\t%d\n", fsinfo.maxOpenFiles); printf("\tmaxOpenFiles:\t%d\n\r", fsinfo.maxOpenFiles);
printf("\tmaxPathLength:\t%d\n", fsinfo.maxPathLength); printf("\tmaxPathLength:\t%d\n\r", fsinfo.maxPathLength);
printf("\n"); printf("\n\r");
return true; return true;
} }
bool format_fs() { bool format_fs() {
printf("Formatting FS ! \n"); printf("Formatting FS ! \n\r");
return LittleFS.format(); return LittleFS.format();
} }

View File

@ -87,6 +87,10 @@ void setup_webserver() {
server.on("/", handleRootGz); server.on("/", handleRootGz);
server.on("/style.css", handleCssGz); server.on("/style.css", handleCssGz);
server.on("/favicon.png", handleFaviconGz); 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.onNotFound(handleNotFound);
server.begin(); server.begin();
@ -152,15 +156,15 @@ uint8_t onoff = 1;
void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor); 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 softstart_led(uint8_t led, uint16_t startval, uint16_t stopval, uint8_t factor);
uint8_t flag = 0;
void timer_callback(void *pArg) void timer_callback(void *pArg)
{ {
*((int *) pArg) += 1; *((int *) pArg) += 1;
ledsequence(direction, onoff, 4); flag = 1;
} }
void setup() { void setup() {
#ifdef WITH_DEBUGGING_ON #ifdef WITH_DEBUGGING_ON
Serial.begin(460800); Serial.begin(460800);
@ -173,8 +177,9 @@ void setup() {
mount_fs(); mount_fs();
//format_fs(); //format_fs();
listDir(""); ls("/");
readFile("/test.txt"); ls("tester/");
// readFile("/test.txt");
pinMode(NODEMCU_LED, OUTPUT); pinMode(NODEMCU_LED, OUTPUT);
pinMode(ESP12_LED, OUTPUT); pinMode(ESP12_LED, OUTPUT);
@ -191,6 +196,23 @@ void setup() {
ESP.restart(); 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); pinMode(led, OUTPUT);
digitalWrite(led, 0); digitalWrite(led, 0);
Serial.println(""); Serial.println("");
@ -200,21 +222,6 @@ void setup() {
delay(500); delay(500);
Serial.print("."); 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_webserver();
setup_pwm_pca9685(); 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 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() { void loop() {
if(millis() - dimmtimer > 2){ if(millis() - dimmtimer > 2){
@ -313,9 +320,14 @@ void loop() {
if(millis() > 25000 && onoff == 1 && direction == 1) onoff = 0; if(millis() > 25000 && onoff == 1 && direction == 1) onoff = 0;
if(millis() > 35000 && direction == 1){ if(millis() > 35000 && direction == 1){
onoff = 1; onoff = 1;
direction = 0; direction = 0;
} }
TIMEIF_US("OTA", ArduinoOTA.handle(), 1000); TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
TIMEIF_US("HTTP", server.handleClient(), 1000); TIMEIF_US(server.handleClient(), 1000, "HTTP");
if(flag) {
flag = 0;
ledsequence(direction, onoff, 4);
Serial.printf("[%lu] interrupt\n\r", millis());
}
} }