Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP8266 #2

Open
buddace opened this issue Mar 24, 2021 · 1 comment
Open

ESP8266 #2

buddace opened this issue Mar 24, 2021 · 1 comment

Comments

@buddace
Copy link

buddace commented Mar 24, 2021

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

@moelski
Copy link

moelski commented Jun 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants