Last active
November 27, 2015 11:02
-
-
Save sticilface/20c9973da4ccbe993c97 to your computer and use it in GitHub Desktop.
demonstrates the file length issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266WebServer.h> | |
#include <FS.h> | |
#include <ArduinoOTA.h> | |
#include <ESP8266mDNS.h> | |
const char* ssid = "xxx"; | |
const char* password = "xxx"; | |
void setup ( void ) { | |
Serial.begin ( 115200 ); | |
WiFi.begin ( ssid, password ); | |
Serial.println ( "" ); | |
SPIFFS.begin(); | |
// Wait for connection | |
while ( WiFi.status() != WL_CONNECTED ) { | |
delay ( 500 ); | |
Serial.print ( "." ); | |
} | |
Serial.println ( "" ); | |
Serial.print ( "Connected to " ); | |
Serial.println ( ssid ); | |
Serial.print ( "IP address: " ); | |
Serial.println ( WiFi.localIP() ); | |
ArduinoOTA.begin(); | |
ListSPIFFS(); | |
DeleteSPIFFS(); | |
ListSPIFFS(); | |
String name = String(); | |
File f; | |
for (int i = 4; i < 34; i++) { | |
char buf[3]; | |
sprintf(buf, "%02u", i); | |
name += "a"; | |
String filename = "/" + String(buf) + name; | |
Serial.println(filename); | |
f = SPIFFS.open(filename, "w"); | |
f.println(filename); | |
f.close(); | |
} | |
ListSPIFFS(); | |
} | |
void loop ( void ) { | |
ArduinoOTA.handle(); | |
} | |
void ListSPIFFS() { | |
Serial.println("SPIFFS FILES:"); | |
{ | |
Dir dir = SPIFFS.openDir("/"); | |
while (dir.next()) { | |
String fileName = dir.fileName(); | |
size_t fileSize = dir.fileSize(); | |
Serial.printf(" FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str()); | |
} | |
Serial.printf("\n"); | |
} | |
} | |
void DeleteSPIFFS() { | |
Serial.println("Deleting SPIFFS FILES:"); | |
{ | |
Dir dir = SPIFFS.openDir("/"); | |
while (dir.next()) { | |
String fileName = dir.fileName(); | |
Serial.printf("Deleting File: %s\n", fileName.c_str()); | |
SPIFFS.remove(fileName); | |
} | |
Serial.printf("\n"); | |
} | |
} | |
//format bytes | |
String formatBytes(size_t bytes){ | |
if (bytes < 1024){ | |
return String(bytes)+"B"; | |
} else if(bytes < (1024 * 1024)){ | |
return String(bytes/1024.0)+"KB"; | |
} else if(bytes < (1024 * 1024 * 1024)){ | |
return String(bytes/1024.0/1024.0)+"MB"; | |
} else { | |
return String(bytes/1024.0/1024.0/1024.0)+"GB"; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment