diff --git a/ESPixelStick/ESPixelStick.ino b/ESPixelStick/ESPixelStick.ino index a603c7a2f..c6dee0267 100644 --- a/ESPixelStick/ESPixelStick.ino +++ b/ESPixelStick/ESPixelStick.ino @@ -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"; ///////////////////////////////////////////////////////// // @@ -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())); @@ -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 @@ -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; @@ -388,7 +408,7 @@ void SaveConfig() GetConfig(JsonConfig); - FileMgr.SaveConfigFile(ConfigFileName, jsonConfigDoc); + FileMgr.SaveFlashFile(ConfigFileName, jsonConfigDoc); // DEBUG_END; } // SaveConfig @@ -405,7 +425,7 @@ void LoadConfig() String temp; // DEBUG_V (""); - FileMgr.LoadConfigFile (ConfigFileName, &deserializeCoreHandler); + FileMgr.LoadFlashFile (ConfigFileName, &deserializeCoreHandler); ConfigSaveNeeded |= !validateConfig (); @@ -415,7 +435,7 @@ void LoadConfig() void DeleteConfig () { // DEBUG_START; - FileMgr.DeleteConfigFile (ConfigFileName); + FileMgr.DeleteFlashFile (ConfigFileName); // DEBUG_END; @@ -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; } */ diff --git a/ESPixelStick/src/ConstNames.cpp b/ESPixelStick/src/ConstNames.cpp index 4b4ae9fe8..c12034774 100644 --- a/ESPixelStick/src/ConstNames.cpp +++ b/ESPixelStick/src/ConstNames.cpp @@ -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"; diff --git a/ESPixelStick/src/ConstNames.hpp b/ESPixelStick/src/ConstNames.hpp index 7f425b004..ba9ddff8c 100644 --- a/ESPixelStick/src/ConstNames.hpp +++ b/ESPixelStick/src/ConstNames.hpp @@ -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 []; diff --git a/ESPixelStick/src/ESPixelStick.h b/ESPixelStick/src/ESPixelStick.h index 96e32fb1b..fec9b7f78 100644 --- a/ESPixelStick/src/ESPixelStick.h +++ b/ESPixelStick/src/ESPixelStick.h @@ -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 diff --git a/ESPixelStick/src/FileMgr.cpp b/ESPixelStick/src/FileMgr.cpp index cd8547264..b94b9f01d 100644 --- a/ESPixelStick/src/FileMgr.cpp +++ b/ESPixelStick/src/FileMgr.cpp @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -572,7 +572,7 @@ 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; @@ -580,7 +580,7 @@ bool c_FileMgr::ReadConfigFile (const String& FileName, JsonDocument & FileData) do // once { String RawFileData; - if (false == ReadConfigFile (FileName, RawFileData)) + if (false == ReadFlashFile (FileName, RawFileData)) { // DEBUG_V ("Failed to read file"); break; @@ -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; @@ -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 + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/ESPixelStick/src/FileMgr.hpp b/ESPixelStick/src/FileMgr.hpp index e2e7cf8a8..2a8368b56 100644 --- a/ESPixelStick/src/FileMgr.hpp +++ b/ESPixelStick/src/FileMgr.hpp @@ -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 (); diff --git a/ESPixelStick/src/GPIO_Defs.hpp b/ESPixelStick/src/GPIO_Defs.hpp index 5240ace3e..b37892719 100644 --- a/ESPixelStick/src/GPIO_Defs.hpp +++ b/ESPixelStick/src/GPIO_Defs.hpp @@ -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" diff --git a/ESPixelStick/src/WebMgr.cpp b/ESPixelStick/src/WebMgr.cpp index 689f07f59..3e9a8c721 100644 --- a/ESPixelStick/src/WebMgr.cpp +++ b/ESPixelStick/src/WebMgr.cpp @@ -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); @@ -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"); } @@ -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"); } @@ -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 diff --git a/ESPixelStick/src/input/InputMgr.cpp b/ESPixelStick/src/input/InputMgr.cpp index 3f1fdcf60..c71591456 100644 --- a/ESPixelStick/src/input/InputMgr.cpp +++ b/ESPixelStick/src/input/InputMgr.cpp @@ -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 @@ -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; @@ -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; @@ -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 (); @@ -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 @@ -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); diff --git a/ESPixelStick/src/input/InputMgr.hpp b/ESPixelStick/src/input/InputMgr.hpp index 7ddbac765..8f1a18eaf 100644 --- a/ESPixelStick/src/input/InputMgr.hpp +++ b/ESPixelStick/src/input/InputMgr.hpp @@ -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); } diff --git a/ESPixelStick/src/network/EthernetDriver.cpp b/ESPixelStick/src/network/EthernetDriver.cpp index 9534f4129..cb6b18d51 100644 --- a/ESPixelStick/src/network/EthernetDriver.cpp +++ b/ESPixelStick/src/network/EthernetDriver.cpp @@ -84,6 +84,8 @@ void c_EthernetDriver::Begin () { logcon(String("Failed IP ") + GetIpAddress().toString()); } + // https://github.com/espressif/arduino-esp32/issues/5733 - add delay + delay(100); while(!GetIpAddress()) {} logcon(String("After IP ") + GetIpAddress().toString()); #endif // def testEth @@ -113,8 +115,6 @@ void c_EthernetDriver::SetEthHostname () if (0 != Hostname.length ()) { // DEBUG_V (String ("Setting ETH hostname: ") + Hostname); - - // ETH.config (INADDR_NONE, INADDR_NONE, INADDR_NONE); ETH.setHostname (Hostname.c_str ()); } @@ -374,8 +374,6 @@ void c_EthernetDriver::SetUpIp () if (true == UseDhcp) { logcon (F ("Connecting to Ethernet using DHCP")); - // ETH.config (temp, temp, temp, temp); - break; } @@ -400,6 +398,8 @@ void c_EthernetDriver::SetUpIp () // DEBUG_V ("gateway: " + gateway.toString ()); // We didn't use DNS, so just set it to our configured gateway + // https://github.com/espressif/arduino-esp32/issues/5733 - add delay + delay(100); ETH.config (ip, gateway, netmask, gateway); logcon (F ("Connecting to Ethernet with Static IP")); @@ -419,10 +419,11 @@ void c_EthernetDriver::StartEth () // esp_eth_disable(); logcon(String("ETH IP Before Start: ") + ETH.localIP().toString()); if (false == ETH.begin (phy_addr, power_pin /*gpio_num_t(-1)*/, mdc_pin, mdio_pin, phy_type, clk_mode)) - // if (false == ETH.begin(phy_addr, power_pin, mdc_pin, mdio_pin, phy_type, clk_mode)) { fsm_Eth_state_DeviceInitFailed_imp.Init (); } + // https://github.com/espressif/arduino-esp32/issues/5733 - Add delay + delay(100); // DEBUG_END; } // StartEth diff --git a/ESPixelStick/src/network/WiFiDriver.cpp b/ESPixelStick/src/network/WiFiDriver.cpp index 4dbd90cf9..231c875b5 100644 --- a/ESPixelStick/src/network/WiFiDriver.cpp +++ b/ESPixelStick/src/network/WiFiDriver.cpp @@ -140,8 +140,10 @@ void c_WiFiDriver::Begin () JsonObject jsonConfig = jsonConfigDoc.as (); // copy the fields of interest into the local structure - setFromJSON (ssid, jsonConfig, CN_ssid); - setFromJSON (passphrase, jsonConfig, CN_passphrase); + setFromJSON (ssid, jsonConfig, CN_ssid); + setFromJSON (passphrase, jsonConfig, CN_passphrase); + setFromJSON (ap_ssid, jsonConfig, CN_ap_ssid); + setFromJSON (ap_passphrase, jsonConfig, CN_ap_passphrase); ConfigSaveNeeded = true; @@ -157,6 +159,13 @@ void c_WiFiDriver::Begin () // Disable persistant credential storage and configure SDK params WiFi.persistent (false); + if(ap_ssid.equals(emptyString)) + { + String Hostname; + NetworkMgr.GetHostname (Hostname); + ap_ssid = "ESPixelStick-AP-" + String (Hostname); + } + #ifdef ARDUINO_ARCH_ESP8266 wifi_set_sleep_type (NONE_SLEEP_T); // https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html#setoutputpower @@ -308,6 +317,8 @@ void c_WiFiDriver::GetConfig (JsonObject& json) json[CN_ssid] = ssid; json[CN_passphrase] = passphrase; + json[CN_ap_ssid] = ap_ssid; + json[CN_ap_passphrase] = ap_passphrase; #ifdef ARDUINO_ARCH_ESP8266 IPAddress Temp = ip; @@ -476,6 +487,8 @@ bool c_WiFiDriver::SetConfig (JsonObject & json) ConfigChanged |= setFromJSON (sNetmask, json, CN_netmask); ConfigChanged |= setFromJSON (sGateway, json, CN_gateway); ConfigChanged |= setFromJSON (UseDhcp, json, CN_dhcp); + ConfigChanged |= setFromJSON (ap_ssid, json, CN_ap_ssid); + ConfigChanged |= setFromJSON (ap_passphrase, json, CN_ap_passphrase); ConfigChanged |= setFromJSON (ap_channelNumber, json, CN_ap_channel); ConfigChanged |= setFromJSON (sta_timeout, json, CN_sta_timeout); ConfigChanged |= setFromJSON (ap_fallbackIsEnabled, json, CN_ap_fallback); @@ -824,20 +837,19 @@ void fsm_WiFi_state_ConnectingAsAP::Init () { WiFi.enableSTA(false); WiFi.enableAP(true); - String ssid = pWiFiDriver->ssid; - if(ssid.equals(emptyString)) + if(pWiFiDriver->ap_ssid.equals(emptyString)) { String Hostname; NetworkMgr.GetHostname (Hostname); - ssid = "ESPixelStick-" + String (Hostname); + pWiFiDriver->ap_ssid = "ESPixelStick-" + String (Hostname); } // DEBUG_V(String("ap_channelNumber: ") + String(pWiFiDriver->ap_channelNumber)); - WiFi.softAP (ssid.c_str (), pWiFiDriver->passphrase.c_str (), int(pWiFiDriver->ap_channelNumber)); + WiFi.softAP (pWiFiDriver->ap_ssid.c_str (), pWiFiDriver->ap_passphrase.c_str (), int(pWiFiDriver->ap_channelNumber)); pWiFiDriver->setIpAddress (WiFi.localIP ()); pWiFiDriver->setIpSubNetMask (WiFi.subnetMask ()); - logcon (String (F ("WiFi SOFTAP: ssid: '")) + ssid); + logcon (String (F ("WiFi SOFTAP: ssid: '")) + pWiFiDriver->ap_ssid); logcon (String (F ("WiFi SOFTAP: IP Address: '")) + pWiFiDriver->getIpAddress ().toString ()); } else diff --git a/ESPixelStick/src/network/WiFiDriver.hpp b/ESPixelStick/src/network/WiFiDriver.hpp index a3772cd21..31bab0825 100644 --- a/ESPixelStick/src/network/WiFiDriver.hpp +++ b/ESPixelStick/src/network/WiFiDriver.hpp @@ -79,6 +79,7 @@ class c_WiFiDriver bool Get_ap_StayInApMode () { return StayInApMode; } bool Get_RebootOnWiFiFailureToConnect () { return RebootOnWiFiFailureToConnect; } String GetConfig_ssid () { return ssid; } + String GetConfig_apssid () { return ap_ssid; } String GetConfig_passphrase () { return passphrase; } void GetHostname (String& name); void SetHostname (String & name); @@ -102,6 +103,8 @@ class c_WiFiDriver String ssid; String passphrase; + String ap_ssid; + String ap_passphrase; IPAddress ip = IPAddress ((uint32_t)0); IPAddress netmask = IPAddress ((uint32_t)0); IPAddress gateway = IPAddress ((uint32_t)0); diff --git a/ESPixelStick/src/output/OutputMgr.cpp b/ESPixelStick/src/output/OutputMgr.cpp index c02f7501b..4a6371d5a 100644 --- a/ESPixelStick/src/output/OutputMgr.cpp +++ b/ESPixelStick/src/output/OutputMgr.cpp @@ -267,13 +267,15 @@ void c_OutputMgr::Begin () // DEBUG_V(String("init index: ") + String(index) + " Done"); } - // CreateNewConfig (); + if(RestoredConfig) + { + // DEBUG_V("create a merged config"); + CreateNewConfig(); + } // DEBUG_V("load up the configuration from the saved file. This also starts the drivers"); LoadConfig(); - // CreateNewConfig (); - // Preset the output memory memset((void*)&OutputBuffer[0], 0x00, sizeof(OutputBuffer)); @@ -301,17 +303,12 @@ void c_OutputMgr::CreateJsonConfig (JsonObject& jsonConfig) // add the channels header JsonObject OutputMgrChannelsData; - if (true == jsonConfig.containsKey (CN_channels)) - { - // DEBUG_V (); - OutputMgrChannelsData = jsonConfig[CN_channels]; - } - else + if (!jsonConfig.containsKey (CN_channels)) { - // add our section header // DEBUG_V (); - OutputMgrChannelsData = jsonConfig.createNestedObject (CN_channels); + jsonConfig.createNestedObject (CN_channels); } + OutputMgrChannelsData = jsonConfig[CN_channels]; // add the channel configurations // DEBUG_V ("For Each Output Channel"); @@ -401,7 +398,19 @@ void c_OutputMgr::CreateNewConfig () DynamicJsonDocument JsonConfigDoc (OM_MAX_CONFIG_SIZE); // DEBUG_V (); - JsonObject JsonConfig = JsonConfigDoc.createNestedObject (CN_output_config); + // do we create a clean config or do we merge from a restored config? + if(RestoredConfig) + { + logcon("Merging Restored Output Config File"); + FileMgr.ReadFlashFile(ConfigFileName, JsonConfigDoc); + } + + if(!JsonConfigDoc.containsKey(CN_output_config)) + { + // DEBUG_V("Create a new output config area."); + JsonConfigDoc.createNestedObject (CN_output_config); + } + JsonObject JsonConfig = JsonConfigDoc[CN_output_config]; // DEBUG_V (); JsonConfig[CN_cfgver] = CurrentConfigVersion; @@ -471,7 +480,7 @@ void c_OutputMgr::GetConfig (String & Response) { // DEBUG_START; - FileMgr.ReadConfigFile (ConfigFileName, Response); + FileMgr.ReadFlashFile (ConfigFileName, Response); // DEBUG_END; @@ -482,7 +491,7 @@ void c_OutputMgr::GetConfig (byte * Response, uint32_t maxlen ) { // DEBUG_START; - FileMgr.ReadConfigFile (ConfigFileName, Response, maxlen); + FileMgr.ReadFlashFile (ConfigFileName, Response, maxlen); // DEBUG_END; @@ -1007,7 +1016,7 @@ void c_OutputMgr::LoadConfig () ConfigInProgress = true; // try to load and process the config file - if (!FileMgr.LoadConfigFile(ConfigFileName, [this](DynamicJsonDocument &JsonConfigDoc) + if (!FileMgr.LoadFlashFile(ConfigFileName, [this](DynamicJsonDocument &JsonConfigDoc) { // extern void PrettyPrint(DynamicJsonDocument & jsonStuff, String Name); // PrettyPrint(JsonConfigDoc, "OM Load Config"); @@ -1195,7 +1204,7 @@ void c_OutputMgr::SetConfig (const char * ConfigData) // DEBUG_V (String ("ConfigData: ") + ConfigData); - if (true == FileMgr.SaveConfigFile (ConfigFileName, ConfigData)) + if (true == FileMgr.SaveFlashFile (ConfigFileName, ConfigData)) { ScheduleLoadConfig(); } // end we got a config and it was good @@ -1224,7 +1233,7 @@ void c_OutputMgr::SetConfig(ArduinoJson::JsonDocument & ConfigData) // serializeJson(ConfigData, LOG_PORT); // DEBUG_V (); - if (true == FileMgr.SaveConfigFile(ConfigFileName, ConfigData)) + if (true == FileMgr.SaveFlashFile(ConfigFileName, ConfigData)) { ScheduleLoadConfig(); } // end we got a config and it was good diff --git a/ESPixelStick/src/output/OutputMgr.hpp b/ESPixelStick/src/output/OutputMgr.hpp index bfd180cc8..d583ba04a 100644 --- a/ESPixelStick/src/output/OutputMgr.hpp +++ b/ESPixelStick/src/output/OutputMgr.hpp @@ -55,7 +55,7 @@ class c_OutputMgr uint8_t* GetBufferAddress () { return OutputBuffer; } ///< Get the address of the buffer into which the E1.31 handler will stuff data uint32_t GetBufferUsedSize () { return UsedBufferSize; } ///< Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data uint32_t GetBufferSize () { return sizeof(OutputBuffer); } ///< Get the size (in intensities) of the buffer into which the E1.31 handler will stuff data - void DeleteConfig () { FileMgr.DeleteConfigFile (ConfigFileName); } + void DeleteConfig () { FileMgr.DeleteFlashFile (ConfigFileName); } void PauseOutputs (bool NewState); void GetDriverName (String & Name) { Name = "OutputMgr"; } void WriteChannelData (uint32_t StartChannelId, uint32_t ChannelCount, uint8_t * pData); diff --git a/html/NodeJsServer.cjs b/html/NodeJsServer.cjs new file mode 100644 index 000000000..a2ca066f0 --- /dev/null +++ b/html/NodeJsServer.cjs @@ -0,0 +1,12 @@ +const express = require("express"); +const app = express(); + +app.listen(8000, () => { + console.log("Application started and Listening on port 8000"); +}); + +app.use(express.static(__dirname)); + +app.get("/", (req, res) => { + res.sendFile(__dirname + "/index.html"); +}); diff --git a/html/index.html b/html/index.html index 426a17750..ff023c63e 100644 --- a/html/index.html +++ b/html/index.html @@ -408,6 +408,20 @@ title="When connecting as a client, this is the timeout in seconds."> +
+ +
+ +
+
+
+ +
+ +
+
@@ -538,8 +552,8 @@
- +
@@ -552,9 +566,9 @@
- -
- Power Control Pin +
+
diff --git a/html/script.js b/html/script.js index dc355b868..7f0c5756c 100644 --- a/html/script.js +++ b/html/script.js @@ -73,7 +73,7 @@ class Semaphore { }); } } -} // Semaphore +} // callFunction const ServerAccess = new Semaphore(1); @@ -200,11 +200,6 @@ $(function () { //TODO: This should pull a configuration from the stick and not the web interface as web data could be invalid $('#backupconfig').on("click", (function () { - ExtractNetworkConfigFromHtmlPage(); - ExtractChannelConfigFromHtmlPage(Input_Config.channels, "input"); - ExtractChannelConfigFromHtmlPage(Output_Config.channels, "output"); - System_Config.device.id = $('#config #device #id').val(); - System_Config.device.blanktime = $('#config #device #blanktime').val(); let TotalConfig = JSON.stringify({ 'system': System_Config, 'input': Input_Config, 'output': Output_Config }); @@ -339,9 +334,10 @@ function ProcessLocalConfig(data) { // console.info(data); let ParsedLocalConfig = JSON.parse(data); - ServerAccess.callFunction(SendConfigFileToServer, "config", {'system': ParsedLocalConfig}); + ServerAccess.callFunction(SendConfigFileToServer, "config", {'system': ParsedLocalConfig.system}); ServerAccess.callFunction(SendConfigFileToServer, "output_config", {'output_config': ParsedLocalConfig.output}); ServerAccess.callFunction(SendConfigFileToServer, "input_config", {'input_config': ParsedLocalConfig.input}); + ServerAccess.callFunction(SendConfigFileToServer, "RestoredConfig", {'RestoredConfig': true}); } // ProcessLocalConfig @@ -405,6 +401,7 @@ function ProcessWindowChange(NextWindow) { } else if (NextWindow === "#admin") { + RcfResponse = RequestConfigFile("config.json"); RcfResponse = RequestConfigFile("output_config.json"); RcfResponse = RequestConfigFile("input_config.json"); } @@ -1366,6 +1363,8 @@ function ExtractNetworkWiFiConfigFromHtmlPage() { wifi.netmask = $('#network #wifi #netmask').val(); wifi.gateway = $('#network #wifi #gateway').val(); wifi.dhcp = $('#network #wifi #dhcp').prop('checked'); + wifi.ap_ssid = $('#network #wifi #ap_ssid').val(); + wifi.ap_passphrase = $('#network #wifi #ap_passphrase').val(); wifi.ap_channel = $('#network #wifi #ap_channel').val(); wifi.ap_fallback = $('#network #wifi #ap_fallback').prop('checked'); wifi.ap_reboot = $('#network #wifi #ap_reboot').prop('checked'); diff --git a/html/server.bat b/html/server.bat index c00229075..7d2869489 100644 --- a/html/server.bat +++ b/html/server.bat @@ -1,2 +1,2 @@ rem http-server -p8000 -node NodeJsServer +node NodeJsServer.cjs