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

platformio File System erased when upload hex #1313

Open
danielvegafer opened this issue Feb 19, 2024 · 3 comments
Open

platformio File System erased when upload hex #1313

danielvegafer opened this issue Feb 19, 2024 · 3 comments

Comments

@danielvegafer
Copy link

danielvegafer commented Feb 19, 2024

Hello. Im developing in platformio for a while right now. My current application is about WiFi server. Everything works great. But… I seems that every time i upload my elf file with upload option, my wifi web page files in spiff partition are also erased. There are some way to configure upload options so platformio dont erases all the flash or at least avoid to erase spiffs partition when upload my program to esp32?
My code is mostly similar to internet examples of AsyncServer wifi server page from internet. That is my platform.ini file

[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = arduino
monitor_filters = default, time, log2file
monitor_speed = 115200
build_flags = -Os
build_unflags = -O2cntp
board_build.filesystem = littlefs

I test both spiffs and littlefs
At some point i test to use a custom partition table with .csv file, due to unrelated issue, but i left because it don’t fulfill my expected targets, i don’t use anymore these csv indication in the ini file, so i don’t believe there are related to these, i just mention to supply all the information possible.

@Jason2866
Copy link
Contributor

Do you have a link to the project? Using LittleFS too, and flash over the firmware with the Pio function flash. The FS and the content isn't erased or touched.

@danielvegafer
Copy link
Author

Do you have a link to the project? Using LittleFS too, and flash over the firmware with the Pio function flash. The FS and the content isn't erased or touched.
#include "WifiServerController.h"
// Globals
#include "system_global.h"
#include "system_global_types.h"

#include "debugs_controller.h"
#include "Wifiutils.h"
// Search for parameter in HTTP POST request
const char *PARAM_INPUT_1 = "input1";

// Variables to save values from HTML form
// String pilot;
// String pass;
String comando;
String MessageR("igual");
String LastMessage("igual");
String Message1 = "Message1";
String Message2 = "Message2";
String Message3 = "Message3";
String Message = "Message";
SMSData sms;
PhonebookData phone;
// IPAddress localIP;
IPAddress localIP(192, 168, 1, 200); // hardcoded

// Set your Gateway IP address
// IPAddress localGateway;
IPAddress localGateway(192, 168, 1, 1); // hardcoded
IPAddress subnet(255, 255, 255, 0);
String ip;
String gateway;
bool authenticated = false;
unsigned long previousMillis, currentMillis = 0;
const long interval = 10000; // interval to wait for Wi-Fi connection (milliseconds)
String PARAM_MESSAGE = "status";
// AsyncWebServer* WifiServerController::_wifi_server = nullptr;
AsyncWebServer WifiServerController::_wifi_server(80);

WifiServerController::WifiServerController()
{
//_wifi_server = new AsyncWebServer(WIFI_SERVER_PORT);
}

WifiServerController::~WifiServerController()
{
// delete _wifi_server;
}
/**

/
AsyncWebServer WifiServerController::getServer()
{
// return _wifi_server;
}
/

  • @brief Initializing Wifi Server
  • @return true Wifi Server Initiated succesfully
  • @return false Wifi Server Initiation Error
    /
    bool WifiServerController::init()
    {
    #ifdef WIFI_DEBUG_DEEP
    PRINTLN_N("
    *** --> Initializing Wifi server...");
    #endif
    #ifdef WIFI_DEBUG_TIME
    unsigned long routine_start_time = millis();
    #endif

// WiFi.mode(WIFI_STA);
// localIP.fromString(ip.c_str());
// localGateway.fromString(gateway.c_str());
// //if (!WiFi.config(localIP, localGateway, subnet))
// if (!WiFi.softAPConfig(localIP, localGateway, subnet))
// {
// #ifdef WIFI_DEBUG_DEEP
// PRINTLN_N("****Error Configuring Wifi...");
// #endif
// #ifdef WIFI_DEBUG_TIME
// PRINT_TIME(routine_start_time);
// #endif
// return false;
// }
// WiFi.setAutoReconnect(false);

if (WiFi.softAP(WIFI_SERVER_SSIS, NULL))
{

// WiFi.begin(WIFI_SERVER_SSIS, WIFI_SERVER_PASSWORD);

//   if (WiFi.waitForConnectResult() != WL_CONNECTED)
//   {
//     WiFi.disconnect(false);
//     WiFi.begin(WIFI_SERVER_SSIS, WIFI_SERVER_PASSWORD);
//   }

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("****LOCAL IP");
PRINTLN_N(WiFi.softAPIP());
#endif

// if (WiFi.waitForConnectResult() != WL_CONNECTED)
// {
//   WiFi.disconnect(false);
//  // nonBlockingDelayWifi(1000);
//  // WiFi.begin(WIFI_SERVER_SSIS, WIFI_SERVER_PASSWORD);
// }

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("**** --> Wifi Initiated succesfully..");
#endif
#ifdef WIFI_DEBUG_TIME
PRINT_TIME(routine_start_time);
#endif
return true;
}
else
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("**** --> Wifi S Initiation error..");
#endif
#ifdef WIFI_DEBUG_TIME
PRINT_TIME(routine_start_time);
#endif
return false;
}
}
/**

  • @brief check file structure
  • @param fs
  • @param dirname
  • @param levels
    */
    void WifiServerController::listDir(fs::FS &fs, const char *dirname, uint8_t levels)
    {
    Serial.printf("Listing directory: %s\r\n", dirname);

File root = fs.open(dirname);
if (!root)
{
Serial.println("- failed to open directory");
return;
}
if (!root.isDirectory())
{
Serial.println(" - not a directory");
return;
}

File file = root.openNextFile();
while (file)
{
if (file.isDirectory())
{
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels)
{
listDir(fs, file.name(), levels - 1);
}
}
else
{
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print("\tSIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}

/**

  • @brief processor
  • @param var
  • @return String
    */
    // String processor(const String &var)
    // {
    // // if(var == "STATE") {
    // // if(digitalRead(ledPin)) {
    // // ledState = "ON";
    // // }
    // // else {
    // // ledState = "OFF";
    // // }
    // // return ledState;
    // // }
    // // return String();
    // }

void notFound(AsyncWebServerRequest request)
{
request->send(404, "text/plain", "Not found");
}
/
*

  • @brief Set Wifi Serve Routes

/
void WifiServerController::setWifiServerRoutes()
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("
*** --> Setting Wifi server Routes...");
#endif

// Route for root index.html
_wifi_server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(SPIFFS, "/index.html", "text/html"); });

// Route for root index.css
_wifi_server.on("/index.css", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(SPIFFS, "/index.css", "text/css"); });

// Route for root entireframework.min.css
_wifi_server.on("/entireframework.min.css", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(SPIFFS, "/entireframework.min.css", "text/css"); });

// Route for root index.js
// _wifi_server.on("/index.js", HTTP_GET, [](AsyncWebServerRequest *request)
// { request->send(SPIFFS, "/index.js", "text/javascript"); });

_wifi_server.serveStatic("/", SPIFFS, "/");
// Send a GET request to <ESP_IP>/get?input1=
_wifi_server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request)
{
//String inputMessage;
String inputParam;
// GET input1 value on <ESP_IP>/get?input1=
if (request->hasParam(PARAM_INPUT_1))
{
MessageR = request->getParam(PARAM_INPUT_1)->value();
inputParam = PARAM_INPUT_1;
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(inputParam);
PRINTLN_N(MessageR);

#endif
}

                else
                {
                  MessageR = "No message sent";
                  inputParam = "none";
                }
               // Serial.println(inputMessage);
                 request->send(200, "text/html", "Se envió comando al Gateway SMS <br><a href=\"/\">Regresar a la página principal</a>"); });

_wifi_server.onNotFound(notFound);

_wifi_server.begin();
}
/**

  • @brief init SPIFFS
  • @return true SPIFFS initiated succesfully
  • @return false SPIFFS initiation error
    /
    bool WifiServerController::initSPIFFS()
    {
    #ifdef WIFI_DEBUG_DEEP
    PRINTLN_N("
    *** --> Initiating SPIFFS...");
    #endif
    #ifdef WIFI_DEBUG_TIME
    unsigned long routine_start_time = millis();
    #endif
    if (SPIFFS.begin(true))
    {
    #ifdef WIFI_DEBUG_DEEP
    PRINTLN_N("**** --> SPIFFS Initiated succesfully..");
    #endif
    #ifdef WIFI_DEBUG_TIME
    PRINT_TIME(routine_start_time);
    #endif
    return true;
    }
    #ifdef WIFI_DEBUG_DEEP
    PRINTLN_N("**** --> SPIFFS Initiation Error..");
    #endif
    #ifdef WIFI_DEBUG_TIME
    PRINT_TIME(routine_start_time);
    #endif
    return false;
    }

// /**
// * @brief init LittleFS
// *
// * @return true SPIFFS initiated succesfully
// * @return false SPIFFS initiation error
// /
// bool WifiServerController::initLittleFS()
// {
// #ifdef WIFI_DEBUG_DEEP
// PRINTLN_N("
*** --> Initiating LIttleFS...");
// #endif
// #ifdef WIFI_DEBUG_TIME
// unsigned long routine_start_time = millis();
// #endif
// if (LittleFS.begin(true))
// {
// #ifdef WIFI_DEBUG_DEEP
// PRINTLN_N("**** --> LittleFS Initiated succesfully..");
// #endif
// #ifdef WIFI_DEBUG_TIME
// PRINT_TIME(routine_start_time);
// #endif
// return true;
// }
// #ifdef WIFI_DEBUG_DEEP
// PRINTLN_N("**** --> LittleFS Initiation Error..");
// #endif
// #ifdef WIFI_DEBUG_TIME
// PRINT_TIME(routine_start_time);
// #endif
// return false;
// }
/**

  • @brief Wifi Task
  • @param args
    /
    void WifiServerController::wifiTask(void args)
    {
    #ifdef WIFI_DEBUG_DEEP
    PRINTLN_N("
    ** --> WIFI Task Running...");
    #endif

WifiServerController *obj = static_cast<WifiServerController *>(args);
// Initialize GPIO

while (!obj->initSPIFFS())
{
yield();
}
obj->listDir(SPIFFS, "/", 0);
while (!obj->init())
{
yield();
}
obj->setWifiServerRoutes();

for (;;)
{
if (MessageR.equals(LastMessage) == false)
{
obj->ParseMessage(MessageR);
LastMessage = MessageR;
}
// if (WiFi.waitForConnectResult() != WL_CONNECTED)
// {
// //WiFi.disconnect(false);
// nonBlockingDelayWifi(1000);
// WiFi.softAP(WIFI_SERVER_SSIS, WIFI_SERVER_PASSWORD);
// WiFi.begin(WIFI_SERVER_SSIS, WIFI_SERVER_PASSWORD);
// }
}
}

/**

  • @brief Parse Wifi Message
  • @param message receoved message
    */
    void WifiServerController::ParseMessage(String MessageS)

{
String Subs;
int8_t index;
index = MessageS.indexOf("CMD");
if (index > 0)
MessageS.remove(0, index);
Subs = MessageS.substring(0, 3);
// Subs.getBytes((unsigned char *)reader,4);
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());
PRINTLN_N(MessageS.c_str());
PRINTLN_N("command received by Wifi");
#endif
// if (strcmp(reader,"CMD")==0)
if (Subs == "CMD")
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("header CMD identified");
#endif
Subs.clear();
//---------------------------------------------------------
//----ident command----------------------------------------
Subs = MessageS.substring(4, 7);
PRINTLN_N(Subs.c_str());
if (Subs == "SMS")
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("sms command identified");
#endif
Subs.clear();
Subs = MessageS.substring(8, 20);
if (Subs == "Message_type")
{

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());
PRINTLN_N("message type header identified");
#endif
Subs.clear();
Subs = MessageS.substring(21, 22);
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("message type ");
PRINTLN_N(Subs.c_str());
#endif
//---------------------------------------------------------
//----message_type ----------------------------------------
switch (Subs.toInt())
{
case 1:
// sim_controller.sendSms(phone_number, Message1);
Message1.getBytes((unsigned char *)sms.message, 9);
break;
case 2:
// sim_controller.sendSms(phone_number, Message2);
Message2.getBytes((unsigned char *)sms.message, 9);
break;
case 3:
/// sim_controller.sendSms(phone_number, Message3);
Message3.getBytes((unsigned char *)sms.message, 9);
break;
default:
// sim_controller.sendSms(phone_number, Message);
Message.getBytes((unsigned char *)sms.message, 8);
break;
}
Subs.clear();

    //---------------------------------------------------------
    //----phone_number header----------------------------------------
    Subs = MessageS.substring(23, 35);
    // Subs.getBytes((unsigned char *)reader, 12);
    if (Subs == "Phone_number")
    {

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());
// PRINTLN_N(reader);
PRINTLN_N("phone number header identified");
#endif
Subs.clear();
//---------------------------------------------------------
//----phone_number ----------------------------------------
Subs = MessageS.substring(36, 49);
// Subs.getBytes((unsigned char *)reader, 12);
Subs.getBytes((unsigned char *)sms.phone_number, 12);
// memcpy (sms.phone_number,Messagec,13);
Subs.clear();
BaseType_t rc = xQueueSend(system_sms_data__queue_handle, &sms, 0);

      if (rc == pdPASS)
      {

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("sms Mailbox writed");
#endif
xEventGroupSetBits(system_event_handle, SMS_REQUEST_RECEIVED);
}
else
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("sms Mailbox write error");
#endif
}

      if (strcmp(sms.phone_number, "1") == 0 || strcmp(sms.phone_number, "2") == 0) // sms to group
      {
        int8_t group;
        group = atoi(sms.phone_number);
        BaseType_t rc = xQueueOverwrite(storage_server_groupsms_mailbox_handle, &group);

        if (rc == pdPASS)
        {

#ifdef SERVER_DEBUG_DEEP
PRINTLN_N("sms group Mailbox writed");
#endif
xEventGroupSetBits(sd_event_handle, SD_GROUP_SMS_NOTIFICATION);
}
else
{
#ifdef SERVER_DEBUG_DEEP
PRINTLN_N("sms group Mailbox write error");
#endif
}
// Just an response example
}
}
else
{
return;
}
}
else
{
return;
}
}
else
{
Subs.clear();
Subs = MessageS.substring(4, 10);
if (Subs == "PhoneB")
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());
PRINTLN_N("phonebook command identified");
#endif
Subs.clear();
//---------------------------------------------------------
//----group header----------------------------------------
Subs = MessageS.substring(11, 16);
if (Subs == "Group")
{

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());
PRINTLN_N("group header identified");
#endif
Subs.clear();
Subs = MessageS.substring(17, 18);
phone.phonebook = Subs.toInt();
//---------------------------------------------------------
//----group ----------------------------------------
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("group");
PRINTLN_N(Subs.c_str());
PRINTLN_N(phone.phonebook);
#endif

      if (phone.phonebook != 1 && phone.phonebook != 2)
        phone.phonebook = 1;
      Subs.clear();
      //---------------------------------------------------------
      //----phone_number header----------------------------------------
      Subs = MessageS.substring(19, 31);
      if (Subs == "Phone_number")
      {

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());
PRINTLN_N("phone number header identified");
#endif
Subs.clear();
//---------------------------------------------------------
//----phone_number ----------------------------------------
Subs = MessageS.substring(32, 43);
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());
PRINTLN_N("phone number");
#endif
Subs.getBytes((unsigned char *)phone.phone_number, 12);
Subs.clear();
Subs = MessageS.substring(44, 50);
//---------------------------------------------------------
//----action ----------------------------------------
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());

#endif
Subs.clear();
Subs = MessageS.substring(51, 52);
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N(Subs.c_str());

#endif
phone.action = Subs.toInt();
Subs.clear();
BaseType_t rc = xQueueSend(system_phonebook_data__queue_handle, &phone, 0);

        if (rc == pdPASS)
        {

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("phonebook Mailbox writed");
#endif
}
else
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("phonebook Mailbox write error");
#endif
}
}
else
{

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("Wifi command not identified");
#endif
return;
}
}
else
{

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("Wifi command not identified");
#endif
return;
}
}
else
{

#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("Wifi command not identified");
#endif
return;
}
}
}
else
{
#ifdef WIFI_DEBUG_DEEP
PRINTLN_N("Wifi command not found");
#endif
return;
}
}

@danielvegafer
Copy link
Author

I test both littlefs and spifss. when using littlefs, internal log of littlefs or asyncwebserver library, i dont know for sure, reports not exist from old files who are not any more in data folder and even i not request on AsyncWebserver request anymore in these stage of project, so i dont know why check for exist of this files. Every time i upgrade esp32 with new hex , when i try to open the web site after successful connection, the load of the web stucks in the middle and never occurs, and when i build again file system image and upload the image everything works ok

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