"vector": "cpp", | "vector": "cpp", | ||||
"string_view": "cpp", | "string_view": "cpp", | ||||
"memory": "cpp", | "memory": "cpp", | ||||
"ranges": "cpp" | |||||
"ranges": "cpp", | |||||
"initializer_list": "cpp", | |||||
"utility": "cpp" | |||||
} | } | ||||
} | } |
Hello from LittleFS ;) |
```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> | |||||
``` | ``` |
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); |
// 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) { | |||||
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); | 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) { | ||||
} | } | ||||
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) { | ||||
} | } | ||||
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) { | ||||
} | } | ||||
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 { | ||||
} | } | ||||
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 { | ||||
return false; | 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; | return true; | ||||
} | } | ||||
bool format_fs() { | bool format_fs() { | ||||
printf("Formatting FS ! \n"); | |||||
printf("Formatting FS ! \n\r"); | |||||
return LittleFS.format(); | return LittleFS.format(); | ||||
} | } | ||||
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(); | ||||
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); | ||||
mount_fs(); | mount_fs(); | ||||
//format_fs(); | //format_fs(); | ||||
listDir(""); | |||||
readFile("/test.txt"); | |||||
ls("/"); | |||||
ls("tester/"); | |||||
// readFile("/test.txt"); | |||||
pinMode(NODEMCU_LED, OUTPUT); | pinMode(NODEMCU_LED, OUTPUT); | ||||
pinMode(ESP12_LED, OUTPUT); | pinMode(ESP12_LED, OUTPUT); | ||||
ESP.restart(); | 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.println(""); | ||||
Serial.print("Connected to "); | Serial.print("Connected to "); | ||||
Serial.println(WiFi.localIP()); | Serial.println(WiFi.localIP()); | ||||
os_timer_setfn(&timer1, timer_callback, &timer_arg); | os_timer_setfn(&timer1, timer_callback, &timer_arg); | ||||
os_timer_arm(&timer1, 1, true); | |||||
os_timer_arm(&timer1, 1000, true); | |||||
Serial.println("Ready"); | Serial.println("Ready"); | ||||
Serial.print("IP address: "); | Serial.print("IP address: "); | ||||
Serial.println(WiFi.localIP()); | Serial.println(WiFi.localIP()); | ||||
setup_ota(); | 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_webserver(); | ||||
setup_pwm_pca9685(); | setup_pwm_pca9685(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
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){ | ||||
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("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()); | |||||
} | |||||
} | } |