Browse Source

ls -l implement and ota fw fix

tags/v0.3.0
Simon Schmidt 3 years ago
parent
commit
6596346d3d
6 changed files with 77 additions and 46 deletions
  1. 3
    1
      .vscode/settings.json
  2. 1
    0
      data/tt.html
  3. 15
    0
      doku.md
  4. 1
    1
      include/filesys.h
  5. 27
    26
      src/filesys.cpp
  6. 30
    18
      src/main.cpp

+ 3
- 1
.vscode/settings.json View File

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

+ 1
- 0
data/tt.html View File

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

+ 15
- 0
doku.md View File

@@ -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 <PORT>
...
$ sudo ufw allow tcp/<PORT>
```

+ 1
- 1
include/filesys.h View File

@@ -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);

+ 27
- 26
src/filesys.cpp View File

@@ -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();
}


+ 30
- 18
src/main.cpp View File

@@ -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,15 +196,7 @@ void setup() {
ESP.restart();
}

pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.print("Connected to ");
@@ -208,13 +205,23 @@ void setup() {
Serial.println(WiFi.localIP());

os_timer_setfn(&timer1, timer_callback, &timer_arg);
os_timer_arm(&timer1, 1, true);
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("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
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());
}
}

Loading…
Cancel
Save