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

Added dedicated AP SSID an Passphrase configuration fields. #749

Merged
merged 13 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ bool ResetWiFi = false;
bool IsBooting = true; // Configuration initialization flag
time_t ConfigLoadNeeded = NO_CONFIG_NEEDED;
bool ConfigSaveNeeded = false;
bool RestoredConfig = false;

uint32_t DiscardedRxData = 0;
const String RestoredConfigFileName = "/RestoredConfig.json";

/////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -171,6 +174,15 @@ void setup()
// DEBUG_V("");
FileMgr.Begin();

if(FileMgr.FlashFileExists (RestoredConfigFileName))
{
// DEBUG_V("Setting Restored Config flag to true");
RestoredConfig = true;
}
else
{
// DEBUG_V("Setting Restored Config flag to false");
}
// Load configuration from the File System and set Hostname
// TestHeap(uint32_t(15));
// DEBUG_V(String("LoadConfig Heap: ") + String(ESP.getFreeHeap()));
Expand Down Expand Up @@ -218,6 +230,14 @@ void setup()
// Done with initialization
IsBooting = false;

if(RestoredConfig)
{
// DEBUG_V("Delete Restored Config Flag file");
FileMgr.DeleteFlashFile(RestoredConfigFileName);
ConfigSaveNeeded = true;
RestoredConfig = false;
}

// DEBUG_END;

} // setup
Expand Down Expand Up @@ -285,7 +305,7 @@ void SetConfig (const char * DataString)
// of the data. Chance for 3rd party software to muck up the configuraton
// if they send bad json data.

FileMgr.SaveConfigFile (ConfigFileName, DataString);
FileMgr.SaveFlashFile (ConfigFileName, DataString);
ScheduleLoadConfig();

// DEBUG_END;
Expand Down Expand Up @@ -388,7 +408,7 @@ void SaveConfig()

GetConfig(JsonConfig);

FileMgr.SaveConfigFile(ConfigFileName, jsonConfigDoc);
FileMgr.SaveFlashFile(ConfigFileName, jsonConfigDoc);

// DEBUG_END;
} // SaveConfig
Expand All @@ -405,7 +425,7 @@ void LoadConfig()

String temp;
// DEBUG_V ("");
FileMgr.LoadConfigFile (ConfigFileName, &deserializeCoreHandler);
FileMgr.LoadFlashFile (ConfigFileName, &deserializeCoreHandler);

ConfigSaveNeeded |= !validateConfig ();

Expand All @@ -415,7 +435,7 @@ void LoadConfig()
void DeleteConfig ()
{
// DEBUG_START;
FileMgr.DeleteConfigFile (ConfigFileName);
FileMgr.DeleteFlashFile (ConfigFileName);

// DEBUG_END;

Expand Down Expand Up @@ -487,7 +507,7 @@ void loop()
/*
if(millis() > HeapTime)
{
DEBUG_V(String("Heap: ") + String(ESP.getFreeHeap()));
// DEBUG_V(String("Heap: ") + String(ESP.getFreeHeap()));
HeapTime += 5000;
}
*/
Expand Down
2 changes: 2 additions & 0 deletions ESPixelStick/src/ConstNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const CN_PROGMEM char CN_advancedView [] = "advancedView";
const CN_PROGMEM char CN_allleds [] = "allleds";
const CN_PROGMEM char CN_ap_channel [] = "ap_channel";
const CN_PROGMEM char CN_ap_fallback [] = "ap_fallback";
const CN_PROGMEM char CN_ap_passphrase [] = "ap_passphrase";
const CN_PROGMEM char CN_ap_ssid [] = "ap_ssid";
const CN_PROGMEM char CN_ap_timeout [] = "ap_timeout";
const CN_PROGMEM char CN_ap_reboot [] = "ap_reboot";
const CN_PROGMEM char CN_appendnullcount [] = "appendnullcount";
Expand Down
2 changes: 2 additions & 0 deletions ESPixelStick/src/ConstNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ extern const CN_PROGMEM char CN_advancedView [];
extern const CN_PROGMEM char CN_allleds [];
extern const CN_PROGMEM char CN_ap_channel [];
extern const CN_PROGMEM char CN_ap_fallback [];
extern const CN_PROGMEM char CN_ap_passphrase [];
extern const CN_PROGMEM char CN_ap_ssid [];
extern const CN_PROGMEM char CN_ap_timeout [];
extern const CN_PROGMEM char CN_ap_reboot [];
extern const CN_PROGMEM char CN_appendnullcount [];
Expand Down
2 changes: 2 additions & 0 deletions ESPixelStick/src/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ bool setFromJSON (T& OutValue, J& Json, N Name)

extern config_t config;
extern bool ConfigSaveNeeded;
extern bool RestoredConfig;

extern const uint8_t CurrentConfigVersion;
#define LOAD_CONFIG_DELAY 4
// #define DEBUG_GPIO gpio_num_t::GPIO_NUM_25
Expand Down
29 changes: 18 additions & 11 deletions ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void c_FileMgr::ResetSdCard()
} // ResetSdCard

//-----------------------------------------------------------------------------
void c_FileMgr::DeleteConfigFile (const String& FileName)
void c_FileMgr::DeleteFlashFile (const String& FileName)
{
// DEBUG_START;

Expand Down Expand Up @@ -309,7 +309,7 @@ void c_FileMgr::listDir (fs::FS& fs, String dirname, uint8_t levels)
} // listDir

//-----------------------------------------------------------------------------
bool c_FileMgr::LoadConfigFile (const String& FileName, DeserializationHandler Handler)
bool c_FileMgr::LoadFlashFile (const String& FileName, DeserializationHandler Handler)
{
// DEBUG_START;

Expand Down Expand Up @@ -399,18 +399,18 @@ bool c_FileMgr::LoadConfigFile (const String& FileName, DeserializationHandler H
} // LoadConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::SaveConfigFile (const String& FileName, String& FileData)
bool c_FileMgr::SaveFlashFile (const String& FileName, String& FileData)
{
// DEBUG_START;

bool Response = SaveConfigFile (FileName, FileData.c_str ());
bool Response = SaveFlashFile (FileName, FileData.c_str ());

// DEBUG_END;
return Response;
} // SaveConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::SaveConfigFile (const String& FileName, const char * FileData)
bool c_FileMgr::SaveFlashFile (const String& FileName, const char * FileData)
{
// DEBUG_START;

Expand Down Expand Up @@ -445,7 +445,7 @@ bool c_FileMgr::SaveConfigFile (const String& FileName, const char * FileData)
} // SaveConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::SaveConfigFile(const String &FileName, JsonDocument &FileData)
bool c_FileMgr::SaveFlashFile(const String &FileName, JsonDocument &FileData)
{
// DEBUG_START;
bool Response = false;
Expand Down Expand Up @@ -488,7 +488,7 @@ bool c_FileMgr::SaveConfigFile(const String &FileName, JsonDocument &FileData)
} // SaveConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::SaveConfigFile(const String FileName, uint32_t index, uint8_t *data, uint32_t len, bool final)
bool c_FileMgr::SaveFlashFile(const String FileName, uint32_t index, uint8_t *data, uint32_t len, bool final)
{
// DEBUG_START;
bool Response = false;
Expand Down Expand Up @@ -538,7 +538,7 @@ bool c_FileMgr::SaveConfigFile(const String FileName, uint32_t index, uint8_t *d
} // SaveConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::ReadConfigFile (const String& FileName, String& FileData)
bool c_FileMgr::ReadFlashFile (const String& FileName, String& FileData)
{
// DEBUG_START;

Expand Down Expand Up @@ -572,15 +572,15 @@ bool c_FileMgr::ReadConfigFile (const String& FileName, String& FileData)
} // ReadConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::ReadConfigFile (const String& FileName, JsonDocument & FileData)
bool c_FileMgr::ReadFlashFile (const String& FileName, JsonDocument & FileData)
{
// DEBUG_START;
bool GotFileData = false;

do // once
{
String RawFileData;
if (false == ReadConfigFile (FileName, RawFileData))
if (false == ReadFlashFile (FileName, RawFileData))
{
// DEBUG_V ("Failed to read file");
break;
Expand Down Expand Up @@ -619,7 +619,7 @@ bool c_FileMgr::ReadConfigFile (const String& FileName, JsonDocument & FileData)
} // ReadConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::ReadConfigFile (const String & FileName, byte * FileData, size_t maxlen)
bool c_FileMgr::ReadFlashFile (const String & FileName, byte * FileData, size_t maxlen)
{
// DEBUG_START;
bool GotFileData = false;
Expand Down Expand Up @@ -666,6 +666,13 @@ bool c_FileMgr::ReadConfigFile (const String & FileName, byte * FileData, size_t

} // ReadConfigFile

//-----------------------------------------------------------------------------
bool c_FileMgr::FlashFileExists (const String & FileName)
{
return LittleFS.exists (FileName.c_str ());

} // FlashFileExists

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Expand Down
21 changes: 11 additions & 10 deletions ESPixelStick/src/FileMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ class c_FileMgr
FileAppend,
} FileMode;

void DeleteConfigFile (const String & FileName);
bool SaveConfigFile (const String & FileName, String & FileData);
bool SaveConfigFile (const String & FileName, const char * FileData);
bool SaveConfigFile (const String & FileName, JsonDocument & FileData);
bool SaveConfigFile (const String filename, uint32_t index, uint8_t *data, uint32_t len, bool final);

bool ReadConfigFile (const String & FileName, String & FileData);
bool ReadConfigFile (const String & FileName, JsonDocument & FileData);
bool ReadConfigFile (const String & FileName, byte * FileData, size_t maxlen);
bool LoadConfigFile (const String & FileName, DeserializationHandler Handler);
void DeleteFlashFile (const String & FileName);
bool SaveFlashFile (const String & FileName, String & FileData);
bool SaveFlashFile (const String & FileName, const char * FileData);
bool SaveFlashFile (const String & FileName, JsonDocument & FileData);
bool SaveFlashFile (const String filename, uint32_t index, uint8_t *data, uint32_t len, bool final);

bool ReadFlashFile (const String & FileName, String & FileData);
bool ReadFlashFile (const String & FileName, JsonDocument & FileData);
bool ReadFlashFile (const String & FileName, byte * FileData, size_t maxlen);
bool LoadFlashFile (const String & FileName, DeserializationHandler Handler);
bool FlashFileExists (const String & FileName);

bool SdCardIsInstalled () { return SdCardInstalled; }
FileId CreateSdFileHandle ();
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/GPIO_Defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ typedef enum
# include "platformDefinitions/GPIO_Defs_ESP32_TWILIGHTLORD.hpp"
#elif defined (BOARD_ESP32_TWILIGHTLORD_ETH)
# include "platformDefinitions/GPIO_Defs_ESP32_TWILIGHTLORD_ETH.hpp"
#elif defined (BOARD_ESP32_TWILIGHTLORD_ETH)
#elif defined (BOARD_ESP32_DEVKITC)
# include "platformDefinitions/GPIO_Defs_ESP32_DevkitC.hpp"
#elif defined (BOARD_ESP01S)
# include "platformDefinitions/GPIO_Defs_ESP8266_ESP01S.hpp"
Expand Down
12 changes: 9 additions & 3 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ void c_WebMgr::init ()
OutputMgr.ScheduleLoadConfig();
request->send (200, CN_textSLASHplain, String(F("XFER Complete")));
}
else if(UploadFileName.equals(F("RestoredConfig.json")))
{
DEBUG_V("Received RestoredConfig message");
request->send (200, CN_textSLASHplain, String(F("XFER Complete")));
RequestReboot(700000);
}
else
{
logcon(String(F("Unexpected Config File Name: ")) + UploadFileName);
Expand All @@ -347,7 +353,7 @@ void c_WebMgr::init ()
// DEBUG_V(String(" file: ") + filename);
// DEBUG_V(String("final: ") + String(final));

if(FileMgr.SaveConfigFile(filename, index, data, len, final))
if(FileMgr.SaveFlashFile(filename, index, data, len, final))
{
// DEBUG_V("Save Chunk - Success");
}
Expand All @@ -371,7 +377,7 @@ void c_WebMgr::init ()
// DEBUG_V(String(" file: ") + UploadFileName);
// DEBUG_V(String("final: ") + String(total <= (index+len)));

if(FileMgr.SaveConfigFile(UploadFileName, index, data, len, total <= (index+len)))
if(FileMgr.SaveFlashFile(UploadFileName, index, data, len, total <= (index+len)))
{
// DEBUG_V("Save Chunk - Success");
}
Expand Down Expand Up @@ -619,7 +625,7 @@ void c_WebMgr::CreateAdminInfoFile ()
#endif

// write to json file
if (true == FileMgr.SaveConfigFile (F("/admininfo.json"), AdminJsonDoc))
if (true == FileMgr.SaveFlashFile (F("/admininfo.json"), AdminJsonDoc))
{
} // end we saved a config and it was good
else
Expand Down
30 changes: 23 additions & 7 deletions ESPixelStick/src/input/InputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ void c_InputMgr::Begin (uint32_t BufferSize)
}
HasBeenInitialized = true;

if(RestoredConfig)
{
logcon("Merging Restored Input Config File");
CreateNewConfig();
}

// load up the configuration from the saved file. This also starts the drivers
LoadConfig ();

// CreateNewConfig ();

// DEBUG_END;

} // begin
Expand Down Expand Up @@ -258,7 +262,19 @@ void c_InputMgr::CreateNewConfig ()
DynamicJsonDocument JsonConfigDoc(IM_JSON_SIZE);
// DEBUG_V("");

JsonObject JsonConfig = JsonConfigDoc.createNestedObject(CN_input_config);
// do we create a clean config or do we merge from a restored config?
if(RestoredConfig)
{
// DEBUG_V("Merge a Restored Config");
// read the existing file and add to it as needed
FileMgr.ReadFlashFile(ConfigFileName, JsonConfigDoc);
}

if(!JsonConfigDoc.containsKey(CN_input_config))
{
JsonConfigDoc.createNestedObject(CN_input_config);
}
JsonObject JsonConfig = JsonConfigDoc[CN_input_config];
// DEBUG_V("");

JsonConfig[CN_cfgver] = CurrentConfigVersion;
Expand Down Expand Up @@ -306,7 +322,7 @@ void c_InputMgr::GetConfig (byte * Response, uint32_t maxlen)
{
// DEBUGSTART;

FileMgr.ReadConfigFile (ConfigFileName, Response, maxlen);
FileMgr.ReadFlashFile (ConfigFileName, Response, maxlen);
// DEBUGV (String ("TempConfigData: ") + TempConfigData);

// DEBUGEND;
Expand Down Expand Up @@ -616,7 +632,7 @@ void c_InputMgr::LoadConfig ()
ConfigLoadNeeded = NO_CONFIG_NEEDED;
configInProgress = true;
// try to load and process the config file
if (!FileMgr.LoadConfigFile (ConfigFileName, [this](DynamicJsonDocument & JsonConfigDoc)
if (!FileMgr.LoadFlashFile (ConfigFileName, [this](DynamicJsonDocument & JsonConfigDoc)
{
// DEBUG_V ("");
JsonObject JsonConfig = JsonConfigDoc.as<JsonObject> ();
Expand Down Expand Up @@ -873,7 +889,7 @@ void c_InputMgr::SetConfig (const char * NewConfigData)
{
// DEBUG_START;

if (true == FileMgr.SaveConfigFile (ConfigFileName, NewConfigData))
if (true == FileMgr.SaveFlashFile (ConfigFileName, NewConfigData))
{
// DEBUG_V (String("NewConfigData: ") + NewConfigData);
// FileMgr logs for us
Expand All @@ -899,7 +915,7 @@ void c_InputMgr::SetConfig(JsonDocument & NewConfigData)
{
// DEBUG_START;

if (true == FileMgr.SaveConfigFile(ConfigFileName, NewConfigData))
if (true == FileMgr.SaveFlashFile(ConfigFileName, NewConfigData))
{
// FileMgr logs for us
// logcon (CN_stars + String (F (" Saved Input Manager Config File. ")) + CN_stars);
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class c_InputMgr
void SetBufferInfo (uint32_t BufferSize);
void SetOperationalState (bool Active);
void NetworkStateChanged (bool IsConnected);
void DeleteConfig () { FileMgr.DeleteConfigFile (ConfigFileName); }
void DeleteConfig () { FileMgr.DeleteFlashFile (ConfigFileName); }
bool GetNetworkState () { return IsConnected; }
void GetDriverName (String & Name) { Name = "InputMgr"; }
void RestartBlankTimer (e_InputChannelIds Selector) { BlankEndTime[int(Selector)].StartTimer(config.BlankDelay * 1000); }
Expand Down
Loading