diff --git a/src/app/Provisioning2.cpp b/src/app/Provisioning2.cpp index 646ef6c..4e225bb 100644 --- a/src/app/Provisioning2.cpp +++ b/src/app/Provisioning2.cpp @@ -72,7 +72,7 @@ const int16_t QRSize = 240; #define PROV_QR_VERSION "v1" //extern bool wifiOverride; -bool provisioned=false; +//bool provisioned=false; extern TTGOClass *ttgo; Provisioning2Application *lastProvisioning2Instance = nullptr; @@ -85,11 +85,10 @@ void Provisioning2DestroyNVS() { WiFi.mode(WIFI_OFF); if ( ESP_OK == erased ) { lLog("Provisioning: NVS: Provisioning data destroyed\n"); - NVS.setInt("provisioned",0,false); - NVS.setInt("WiFiCredNo",0,false); + //NVS.setInt("provisioned",0,false); + //NVS.setInt("WiFiCredNo",0,false); LoT().GetSettings()->SetInt(SystemSettings::SettingKey::WiFiCredentialsNumber,0); - - provisioned=false; + //provisioned=false; LaunchApplication(new ShutdownApplication(true,true)); } } @@ -127,36 +126,36 @@ void Provisioning2_SysProvEvent(arduino_event_t *sys_event) { char passwd[BuffrSize+1]; snprintf(ssid,BuffrSize,"%s",sys_event->event_info.prov_cred_recv.ssid); snprintf(passwd,BuffrSize,"%s",sys_event->event_info.prov_cred_recv.password); - lLog("Provisioning: Added '%s' pwd: '%s' offset: %u\n", ssid, passwd, LoT().GetWiFi()->GetConnections() ); + lNetLog("WiFi: Provisioning: Added '%s' pwd: '%s' offset: %u\n", ssid, passwd, LoT().GetWiFi()->GetConnections() ); LoT().GetWiFi()->AddConnection(ssid,passwd); //NVS.setString("provSSID",buffr,false); //NVS.setString("provPWD",buffr,false); break; } case ARDUINO_EVENT_PROV_CRED_FAIL: { - lLog("Provisioning: Failed, reason:\n"); + lNetLog("WiFi: Provisioning: Failed, reason:\n"); if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR) { - lLog("Wi-Fi AP password incorrect\n"); + lNetLog("WiFi: AP password incorrect\n"); } else { - lLog("Wi-Fi AP not found\n"); + lNetLog("WiFi: AP not found\n"); } Provisioning2DestroyNVS(); - NVS.setInt("provisioned",0,false); - provisioned = false; + //NVS.setInt("provisioned",0,false); + //provisioned = false; Provisioning2Deinit(); break; } case ARDUINO_EVENT_PROV_CRED_SUCCESS: - lLog("Provisioning Successful\n"); + lNetLog("WiFi: Provisioning Successful\n"); if ( nullptr != lastProvisioning2Instance ) { lastProvisioning2Instance->provisioningStarted = false; - NVS.setInt("provisioned",1, false); - provisioned = true; + //NVS.setInt("provisioned",1, false); + //provisioned = true; //LaunchApplication(new ShutdownApplication(true,true)); } break; case ARDUINO_EVENT_PROV_END: - lLog("Provisioning Ends\n"); + lNetLog("WiFi: Provisioning Ends\n"); LaunchWatchface(); break; default: diff --git a/src/system/Network/WiFi.cpp b/src/system/Network/WiFi.cpp index 0cd2d5f..5b7bce4 100644 --- a/src/system/Network/WiFi.cpp +++ b/src/system/Network/WiFi.cpp @@ -34,7 +34,7 @@ //void LoTWiFi::SuspendTasks() { xSemaphoreTake( taskLock, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS); disabled=true; } //void LoTWiFi::ResumeTasks() { xSemaphoreGive( taskLock ); disabled=false; } -extern bool provisioned; +//extern bool provisioned; void LoTWiFi::Enable() { xSemaphoreTake( taskLock, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS); @@ -120,15 +120,18 @@ void LoTWiFi::AddConnection(const char *SSID,const char *password) { cred->Password=nPwd; xSemaphoreTake( taskLock, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS); credentials.push_back(cred); - LoT().GetSettings()->SetInt(SystemSettings::SettingKey::WiFiCredentialsNumber,int(GetConnections())); - lNetLog("WiFi: %p Added connection %u SSID: '%s' Password: '%s'\n", this, GetConnections()-1, nSSID, nPwd); + NVS.setInt(String(SystemSettings::KeysAsString[SystemSettings::SettingKey::WiFiCredentialsNumber]),int(GetConnections()),true); + //LoT().GetSettings()->SetInt(SystemSettings::SettingKey::WiFiCredentialsNumber,int(GetConnections())); + lNetLog("WiFi: %p Added connection %u SSID: '%s' Password: '%s'\n", this, GetConnections(), nSSID, nPwd); char labelName[255]; - sprintf(labelName,"SSID_%u",GetConnections()-1); - NVS.setString(String(labelName),String(nSSID),false); - sprintf(labelName,"WIFIPWD_%u",GetConnections()-1); - NVS.setString(String(labelName),String(nPwd),false); + sprintf(labelName,"SSID_%u",GetConnections()); + NVS.setString(String(labelName),String(nSSID)); + sprintf(labelName,"WIFIPWD_%u",GetConnections()); + NVS.setString(String(labelName),String(nPwd)); wifiMulti.addAP(nSSID,nPwd); - provisioned=true; + //provisioned=true; + int shit = LoT().GetSettings()->GetInt(SystemSettings::SettingKey::WiFiCredentialsNumber); + lLog("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: %d\n",shit); xSemaphoreGive( taskLock ); } @@ -277,15 +280,25 @@ LoTWiFi::LoTWiFi() { if ( canUse ) { Enable(); } else { Disable(); } int maxWifis = LoT().GetSettings()->GetInt(SystemSettings::SettingKey::WiFiCredentialsNumber); + /* + if ( -1 == maxWifis ) { + lNetLog("WiFi: not provisioned!\n"); + return; + }*/ + if ( 0 == maxWifis ) { + lNetLog("WiFi: not provisioned!\n"); + return; + } size_t currentWiFiOffset=0; - while ( currentWiFiOffset < maxWifis ) { + while ( currentWiFiOffset <= maxWifis ) { char labelName[255]; sprintf(labelName,"SSID_%u",currentWiFiOffset); String nSSID = NVS.getString(String(labelName)); sprintf(labelName,"WIFIPWD_%u",currentWiFiOffset); String nPwd = NVS.getString(String(labelName)); - //lNetLog("WiFi: %p Add connection: %u SSID: '%s' Pwd: '%s'\n", this, currentWiFiOffset,nSSID.c_str(),nPwd.c_str()); - AddConnection(nSSID.c_str(),nPwd.c_str()); + lNetLog("WiFi: %p Add connection: %u SSID: '%s' Pwd: '%s'\n", this, currentWiFiOffset,nSSID.c_str(),nPwd.c_str()); + wifiMulti.addAP(nSSID.c_str(),nPwd.c_str()); + //AddConnection(nSSID.c_str(),nPwd.c_str()); currentWiFiOffset++; } InstallTimer(); diff --git a/src/system/Storage/Settings.cpp b/src/system/Storage/Settings.cpp index 59023c9..a14edf7 100644 --- a/src/system/Storage/Settings.cpp +++ b/src/system/Storage/Settings.cpp @@ -44,11 +44,12 @@ SystemSettings::~SystemSettings() { int64_t SystemSettings::GetInt(SettingKey what) { int64_t result = NVS.getInt(KeysAsString[what]); - //lSysLog("SystemSettings %p: Get '%s' as: (signed: %d) (unsigned: %u)\n", this,KeysAsString[what],result,result); + lSysLog("SystemSettings %p: Get '%s' as: (signed: %d) (unsigned: %u)\n", this,KeysAsString[what],result,result); return result; } bool SystemSettings::SetInt(SettingKey what, int32_t value) { + lLog("SystemSettings: DEBUG INT32\n"); bool result = NVS.setInt(String(KeysAsString[what]),value,false); if (false == result) { lSysLog("SystemSettings %p: ERROR: Unable to set key '%s'\n", this,KeysAsString[what]); @@ -57,6 +58,7 @@ bool SystemSettings::SetInt(SettingKey what, int32_t value) { } bool SystemSettings::SetInt(SettingKey what, uint8_t value) { + lLog("SystemSettings: DEBUG UINT8\n"); bool result = NVS.setInt(String(KeysAsString[what]),value,false); if (false == result) { lSysLog("SystemSettings %p: ERROR: Unable to set key '%s'\n", this,KeysAsString[what]); diff --git a/src/system/SystemEvents.cpp b/src/system/SystemEvents.cpp index 5615092..1b087d4 100644 --- a/src/system/SystemEvents.cpp +++ b/src/system/SystemEvents.cpp @@ -660,7 +660,7 @@ extern bool provisioned; extern void StopDatabase(); void SaveDataBeforeShutdown() { - NVS.setInt("provisioned", provisioned, false); + //NVS.setInt("provisioned", provisioned, false); NVS.setInt("accXMax", accXMax, false); NVS.setInt("accXMin", accXMin, false); diff --git a/tool/.buildCount.txt b/tool/.buildCount.txt index bea6c69..a69cec1 100644 --- a/tool/.buildCount.txt +++ b/tool/.buildCount.txt @@ -1 +1 @@ -26416 \ No newline at end of file +26477 \ No newline at end of file