LittleFS.format on ESP32 needs LittleFS.begin() before
This commit is contained in:
parent
7dcfc375bb
commit
26f0939cc6
5 changed files with 63 additions and 13 deletions
|
@ -27,16 +27,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* CanGrow includes
|
||||
*/
|
||||
|
||||
#include "include/CanGrow.h"
|
||||
#include "include/CanGrow_Core.h"
|
||||
|
||||
/*
|
||||
* Libraries
|
||||
* Libraries include
|
||||
*/
|
||||
|
||||
// * ESP8266 *
|
||||
|
@ -47,8 +40,11 @@
|
|||
|
||||
// * ESP32 *
|
||||
#ifdef ESP32
|
||||
#include "Arduino.h"
|
||||
#include <WiFi.h>
|
||||
#include "AsyncTCP.h"
|
||||
// LittleFS auto format
|
||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||
#endif
|
||||
|
||||
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI
|
||||
|
@ -66,6 +62,14 @@
|
|||
#include "LittleFS.h"
|
||||
|
||||
|
||||
/*
|
||||
* CanGrow includes
|
||||
*/
|
||||
|
||||
#include "include/CanGrow.h"
|
||||
#include "include/CanGrow_Core.h"
|
||||
#include "include/CanGrow_LittleFS.h"
|
||||
|
||||
|
||||
void setup() {
|
||||
// define output for onboard LED/WIPE pin
|
||||
|
@ -118,23 +122,33 @@ void setup() {
|
|||
if(digitalRead(PinWIPE) == HIGH) {
|
||||
#endif
|
||||
Serial.println("!! formatting LittleFS !!");
|
||||
|
||||
#ifdef ESP32
|
||||
LittleFS.begin();
|
||||
#endif
|
||||
LittleFS.format();
|
||||
Panic();
|
||||
}
|
||||
|
||||
|
||||
Serial.println(":: initialise LittleFS ::");
|
||||
if(LittleFS.begin()) {
|
||||
Serial.println(":: LittleFS: successfully initialised");
|
||||
} else {
|
||||
#ifdef ESP8266
|
||||
if(!LittleFS.begin()) {
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)) {
|
||||
#endif
|
||||
Serial.println("!! LittleFS: failed initialising !!");
|
||||
Panic();
|
||||
}
|
||||
|
||||
// read the configfile from LittleFS
|
||||
File lfs_configfile = LittleFS.open(configfile, "r");
|
||||
if(!lfs_configfile) {
|
||||
Serial.println("!! LittleFS: config.json not found, creating it !!");
|
||||
lfs_configfile.close();
|
||||
lfs_configfile = LittleFS.open(configfile, "w");
|
||||
lfs_configfile.close();
|
||||
if(lfs_configfile) {
|
||||
Serial.println(":: LittleFS: config.json successfully created");
|
||||
// write into the file
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "CanGrow_Version.h"
|
||||
|
||||
|
||||
//#define FORMAT_LITTLEFS_IF_FAILED false
|
||||
|
||||
const char* configfile = "config.json";
|
||||
|
||||
#ifdef ESP8266
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
// blink fast with the built in LED in an infinite loop
|
||||
void Panic() {
|
||||
Serial.println("!! PANIC !!");
|
||||
byte i = 0;
|
||||
while(true) {
|
||||
if(i % 2) {
|
||||
|
|
35
Arduino/CanGrow/include/CanGrow_LittleFS.h
Normal file
35
Arduino/CanGrow/include/CanGrow_LittleFS.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
*
|
||||
* include/CanGrow_LittleFS.h - LittleFS handling header file
|
||||
*
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2024 DeltaLima
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ESP32
|
||||
#endif
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
|
||||
test -z $TTY && TTY="/dev/ttyUSB0"
|
||||
test -z $IP && IP="192.168.30.212"
|
||||
test -z $IP && IP="192.168.4.20"
|
||||
test -z $VER && VER="0.2-dev"
|
||||
test -z $BOARD && BOARD="esp8266:esp8266:d1_mini_clone"
|
||||
|
||||
|
|
Loading…
Reference in a new issue