Open buddace opened 3 years ago
Hi ! Just did some tests yesterday. Works very well on ESP8266 and ESP32. This was my testcode for both chips:
#include <Arduino.h>
//#include "LittleFS.h"
#include "LITTLEFS.h"
#define LittleFS LITTLEFS
#include "SPIFFS_ini.h"
void setup() {
Serial.begin(115200);
if (!LittleFS.begin()) {
Serial.println("An Error has occurred while mounting LittleFS");
return;
}
//LittleFS.format();
File file = LittleFS.open("/setup.ini", "r");
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.println("File Content:");
while (file.available()) {
Serial.write(file.read());
}
file.close();
Serial.println(ini_open("/setup.ini"));
Serial.println(ini_write("Test", "Key", String(123.33)));
Serial.println(ini_write("Device_3", "Pin_Mode", "NIX"));
Serial.println(ini_close());
for (size_t i = 0; i < 10; i++)
{
Serial.println(ESP.getFreeHeap());
Serial.println(ini_open("/setup.ini"));
Serial.println(ESP.getFreeHeap());
String ClientSSID = ini_read("Wifi", "SSID", "N/A");
Serial.println(ClientSSID);
Serial.println(ESP.getFreeHeap());
String ClientPassword = ini_read("Device_1", "Description", " ");
Serial.println(ClientPassword);
ini_close();
Serial.println(ESP.getFreeHeap());
delay(400);
}
}
void loop() {
}
The only problem where the slightly different LittleFS Libs ...
And I made a small fix in the cpp file (Typecast p_ini_file). Otherwise it won´t compile for ESP32:
bool ini_close() {
if (ini) ini.close();
ini = LittleFS.open(ini_fname, "w");
ini.write((const uint8_t*)p_ini_file, size_ini_file);
Maybe your filesystem is not formatted correctly with LittleFS ?
Dominik
Hi have problem in ESP8266, open return false: Serial.println(ini_open ("/setup.ini")); ClientSSID = ini_read ("network", "ClientSSID","prova"); Serial.println(ClientSSID); ClientPassword = ini_read ("network", "ClientPassword"," "); Serial.println(ClientPassword); HostSSID = ini_read ("network", "HostSSID","CV19Archimede"); HostPassword = ini_read ("network", "HostPassword","cv19"); HostIp = ini_read ("network", "HostIp","192.168.1.1"); ini_close();
ini file: [network] ClientSSID = sadad ClientPassword = 25399 HostSSID = dfsdd HostPassword = 123 HostIp = 192.168.1.1