Code Monkey home page Code Monkey logo

Comments (3)

Jason2866 avatar Jason2866 commented on June 12, 2024

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.

from platform-espressif32.

danielvegafer avatar danielvegafer commented on June 12, 2024

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;
}
}

from platform-espressif32.

danielvegafer avatar danielvegafer commented on June 12, 2024

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

from platform-espressif32.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.