adds setCountry, default US

accepts US JP CN, codes must be added to strings and WiFiSetCountry atm
This commit is contained in:
Shawn A
2018-07-19 10:02:53 -05:00
parent a51298ea54
commit d140ccff84
3 changed files with 35 additions and 1 deletions
+27 -1
View File
@@ -218,6 +218,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!");
return false;
}
WiFiSetCountry();
#ifdef ESP32
if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work
@@ -484,6 +486,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
// start access point
DEBUG_WM(DEBUG_VERBOSE,F("Enabling AP"));
startAP();
WiFiSetCountry();
// init configportal
DEBUG_WM(DEBUG_DEV,F("setupConfigPortal"));
@@ -2129,6 +2132,14 @@ bool WiFiManager::getWiFiIsSaved(){
return WiFi_hasAutoConnect();
}
/**
* setCountry
* @since $dev
* @param String cc country code, must be defined in WiFiSetCountry, US, JP, CN
*/
void WiFiManager::setCountry(String cc){
_wificountry = cc;
}
// HELPERS
@@ -2167,7 +2178,6 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) {
_debugPort.println();
}
/**
* [debugSoftAPConfig description]
* @access public
@@ -2303,6 +2313,22 @@ String WiFiManager::getModeString(uint8_t mode){
return FPSTR(S_NA);
}
bool WiFiManager::WiFiSetCountry(){
bool ret = false;
// @todo check if wifi is init, no idea how, doesnt seem to be exposed
if(_wificountry == "") return ret; // skip not set
else if(WiFi.getMode() == WIFI_MODE_NULL); // exception if wifi not init!
else if(_wificountry == "US") ret = esp_wifi_set_country(&WM_COUNTRY_US) == ESP_OK;
else if(_wificountry == "JP") ret = esp_wifi_set_country(&WM_COUNTRY_JP) == ESP_OK;
else if(_wificountry == "CN") ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK;
else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found");
if(ret) DEBUG_WM(DEBUG_VERBOSE,"esp_wifi_set_country: " + _wificountry);
else DEBUG_WM(DEBUG_ERROR,"[ERROR] esp_wifi_set_country failed");
return ret;
}
// set mode ignores WiFi.persistent
bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) {
bool ret;
+4
View File
@@ -235,6 +235,7 @@ class WiFiManager
// debug output platform info and versioning
void debugPlatformInfo();
String htmlEntities(String str);
void setCountry(String cc);
private:
std::unique_ptr<DNSServer> dnsServer;
@@ -314,6 +315,8 @@ class WiFiManager
boolean _preloadwifiscan = true; // preload wifiscan if true
boolean _disableIpFields = false; // edge case, if true, showxFields(false) forces ip fields off instead of default show when set
String _wificountry = "US"; // country code, @todo define in strings lang
// wrapper functions for handling setting and unsetting persistent for now.
bool esp32persistent = false;
bool _hasBegun = false;
@@ -372,6 +375,7 @@ class WiFiManager
bool WiFi_scanNetworks();
bool WiFi_scanNetworks(bool force);
bool WiFi_scanNetworks(unsigned int cachetime);
bool WiFiSetCountry();
#ifdef ESP32
static void WiFiEvent(WiFiEvent_t event, system_event_info_t info);
+4
View File
@@ -318,3 +318,7 @@ const char * const AUTH_MODE_NAMES[] PROGMEM
#endif
const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" };
const wifi_country_t WM_COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO};
const wifi_country_t WM_COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO};
const wifi_country_t WM_COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO};