From b4b80ae1b0a19d553c2f52d49ace467ee5b3cc5f Mon Sep 17 00:00:00 2001 From: ryokusei Date: Sun, 17 Feb 2019 17:57:36 -0300 Subject: [PATCH] Fixed the example to work with SPIFFS --- examples/IniFileExample/README.md | 29 ----------- .../SPIFFSIniFileExample.ino} | 50 ++++++++----------- .../data}/net.ini | 0 3 files changed, 21 insertions(+), 58 deletions(-) delete mode 100644 examples/IniFileExample/README.md rename examples/{IniFileExample/IniFileExample.ino => SPIFFSIniFileExample/SPIFFSIniFileExample.ino} (75%) rename examples/{IniFileExample => SPIFFSIniFileExample/data}/net.ini (100%) diff --git a/examples/IniFileExample/README.md b/examples/IniFileExample/README.md deleted file mode 100644 index 867fedd..0000000 --- a/examples/IniFileExample/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# IniFile example - -## Instructions for use - - * Copy the `net.ini` file to the root directory of your (micro)SD card. - * Modify the `IniFileExample.ino` file so that `SD_SELECT` defines - the correct pin number. - * Compile and upload the sketch. - - -## Expected output - -It may take a few seconds from the sketch starting before anything is -printed to the serial port, be patient. If the sketch runs correctly -the output should appear as below: - - - Ini file exists - section 'network' has an entry 'mac' with value 01:23:45:67:89:AB - Could not read 'nosuchkey' from section 'network', error was key not found - Could not read 'nosuchkey' from section 'nosuchsection', error was section not found - The value of 'allow put' in section '/upload' is TRUE - - -If the SD card is missing or cannot be read the sketch will print: - - SD.begin() failed - - diff --git a/examples/IniFileExample/IniFileExample.ino b/examples/SPIFFSIniFileExample/SPIFFSIniFileExample.ino similarity index 75% rename from examples/IniFileExample/IniFileExample.ino rename to examples/SPIFFSIniFileExample/SPIFFSIniFileExample.ino index 9e7134e..a081974 100644 --- a/examples/IniFileExample/IniFileExample.ino +++ b/examples/SPIFFSIniFileExample/SPIFFSIniFileExample.ino @@ -1,42 +1,41 @@ -#include +/* + Remeber to upload the data directory to your board! + + Serial baud rate in this example is 9600 +*/ -#include -#include -#include +#include "FS.h" -// The select pin used for the SD card -//#define SD_SELECT 4 -#define SD_SELECT 22 -#define ETHERNET_SELECT 10 +#include void printErrorMessage(uint8_t e, bool eol = true) { switch (e) { - case IniFile::errorNoError: + case SPIFFSIniFile::errorNoError: Serial.print("no error"); break; - case IniFile::errorFileNotFound: + case SPIFFSIniFile::errorFileNotFound: Serial.print("file not found"); break; - case IniFile::errorFileNotOpen: + case SPIFFSIniFile::errorFileNotOpen: Serial.print("file not open"); break; - case IniFile::errorBufferTooSmall: + case SPIFFSIniFile::errorBufferTooSmall: Serial.print("buffer too small"); break; - case IniFile::errorSeekError: + case SPIFFSIniFile::errorSeekError: Serial.print("seek error"); break; - case IniFile::errorSectionNotFound: + case SPIFFSIniFile::errorSectionNotFound: Serial.print("section not found"); break; - case IniFile::errorKeyNotFound: + case SPIFFSIniFile::errorKeyNotFound: Serial.print("key not found"); break; - case IniFile::errorEndOfFile: + case SPIFFSIniFile::errorEndOfFile: Serial.print("end of file"); break; - case IniFile::errorUnknownError: + case SPIFFSIniFile::errorUnknownError: Serial.print("unknown error"); break; default: @@ -49,26 +48,19 @@ void printErrorMessage(uint8_t e, bool eol = true) void setup() { - // Configure all of the SPI select pins as outputs and make SPI - // devices inactive, otherwise the earlier init routines may fail - // for devices which have not yet been configured. - pinMode(SD_SELECT, OUTPUT); - digitalWrite(SD_SELECT, HIGH); // disable SD card - pinMode(ETHERNET_SELECT, OUTPUT); - digitalWrite(ETHERNET_SELECT, HIGH); // disable Ethernet - const size_t bufferLen = 80; char buffer[bufferLen]; const char *filename = "/net.ini"; Serial.begin(9600); - SPI.begin(); - if (!SD.begin(SD_SELECT)) + + //Mount the SPIFFS + if (!SPIFFS.begin()) while (1) - Serial.println("SD.begin() failed"); + Serial.println("SPIFFS.begin() failed"); - IniFile ini(filename); + SPIFFSIniFile ini(filename); if (!ini.open()) { Serial.print("Ini file "); Serial.print(filename); diff --git a/examples/IniFileExample/net.ini b/examples/SPIFFSIniFileExample/data/net.ini similarity index 100% rename from examples/IniFileExample/net.ini rename to examples/SPIFFSIniFileExample/data/net.ini