Merge branch 'development' into ota

This commit is contained in:
tablatronix
2020-02-19 12:54:04 -06:00
4 changed files with 53 additions and 28 deletions
+1
View File
@@ -309,6 +309,7 @@ wifiManager.addParameter(&custom_text);
Just add the bit you want added as the last parameter to the custom parameter constructor.
```cpp
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "iot.eclipse", 40, " readonly");
wifiManager.addParameter(&custom_mqtt_server);
```
#### Theming
+20 -10
View File
@@ -729,6 +729,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
//@todo catch failures in set_config
// make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !)
if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect
// @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status
@@ -816,7 +817,7 @@ bool WiFiManager::wifiConnectDefault(){
* @return bool success
*/
bool WiFiManager::setSTAConfig(){
DEBUG_WM(F("STA static IP:"),_sta_static_ip);
DEBUG_WM(DEBUG_DEV,F("STA static IP:"),_sta_static_ip);
bool ret = true;
if (_sta_static_ip) {
DEBUG_WM(DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS"));
@@ -832,7 +833,7 @@ bool WiFiManager::setSTAConfig(){
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi config failed");
else DEBUG_WM(F("STA IP set:"),WiFi.localIP());
} else {
DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set"));
DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping"));
}
return ret;
}
@@ -1370,7 +1371,7 @@ void WiFiManager::handleWifiSave() {
page += FPSTR(HTTP_PARAMSAVED);
}
else {
String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
page += FPSTR(HTTP_SAVED);
}
page += FPSTR(HTTP_END);
@@ -1412,8 +1413,10 @@ void WiFiManager::doParamSave(){
if(_paramsCount > 0){
DEBUG_WM(DEBUG_VERBOSE,F("Parameters"));
DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR));
for (int i = 0; i < _paramsCount; i++) {
if (_params[i] == NULL) {
if (_params[i] == NULL || _params[i]->_length == 0) {
DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope");
break; // @todo might not be needed anymore
}
//read parameter from server
@@ -1450,6 +1453,7 @@ void WiFiManager::handleInfo() {
uint16_t infos = 0;
//@todo convert to enum or refactor to strings
//@todo wrap in build flag to remove all info code for memory saving
#ifdef ESP8266
infos = 27;
String infoids[] = {
@@ -1528,7 +1532,7 @@ void WiFiManager::handleInfo() {
String WiFiManager::getInfoData(String id){
String p;
// @todo add versioning
// @todo add WM versioning
if(id==F("esphead"))p = FPSTR(HTTP_INFO_esphead);
else if(id==F("wifihead"))p = FPSTR(HTTP_INFO_wifihead);
else if(id==F("uptime")){
@@ -2010,6 +2014,13 @@ void WiFiManager::setConfigPortalTimeout(unsigned long seconds) {
void WiFiManager::setConnectTimeout(unsigned long seconds) {
_connectTimeout = seconds * 1000;
}
/**
* toggle _cleanconnect, always disconnect before connecting
* @param {[type]} bool enable [description]
*/
void WiFiManager::setCleanConnect(bool enable){
_cleanConnect = enable;
}
/**
* [setConnectTimeout description
@@ -2354,7 +2365,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){
}
}
}
// DEBUG_WM(getMenuOut());
DEBUG_WM(getMenuOut());
}
/**
@@ -2377,7 +2388,7 @@ void WiFiManager::setMenu(std::vector<const char *>& menu){
}
}
}
// DEBUG_WM(getMenuOut());
DEBUG_WM(getMenuOut());
}
@@ -2388,9 +2399,8 @@ void WiFiManager::setMenu(std::vector<const char *>& menu){
* @since $dev
*/
void WiFiManager::setParamsPage(bool enable){
_paramsInWifi= false;
_menuIdsDefault = {"wifi","param","info","exit"};
setMenu(_menuIdsDefault);
_paramsInWifi = !enable;
setMenu(enable ? _menuIdsParams : _menuIdsDefault);
}
// GETTERS
+5 -2
View File
@@ -262,8 +262,10 @@ class WiFiManager
void setWiFiAPChannel(int32_t channel);
// set ap hidden
void setWiFiAPHidden(bool hidden); // default false
// set custom menu
// clean connect, always disconnect before connecting
void setCleanConnect(bool enable); // default false
// set custom menu
// set custom menu items and order
void setMenu(std::vector<const char*>& menu);
void setMenu(const char* menu[], uint8_t size);
@@ -308,6 +310,7 @@ class WiFiManager
private:
std::vector<uint8_t> _menuIds;
std::vector<const char *> _menuIdsParams = {"wifi","param","info","exit"};
std::vector<const char *> _menuIdsDefault = {"wifi","info","exit"};
// ip configs @todo struct ?
@@ -340,7 +343,7 @@ class WiFiManager
unsigned long _lastscan = 0; // ms for timing wifi scans
unsigned long _startscan = 0; // ms for timing wifi scans
int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast.
bool _cleanConnect = true; // disconnect before connect in connectwifi, increases stability on connects
bool _cleanConnect = false; // disconnect before connect in connectwifi, increases stability on connects
bool _disableSTA = false; // disable sta when starting ap, always
bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability )
@@ -73,6 +73,7 @@ WiFiManager wm;
bool TEST_CP = false; // always start the configportal, even if ap found
bool TEST_NET = true; // do a network test after connect, (gets ntp time)
bool AUTOSTARTCP = false; // automatically start config portal is no wifi found
bool ALLOWONDEMAND = true;
// char ssid[] = "*************"; // your network SSID (name)
// char pass[] = "********"; // your network password
@@ -134,13 +135,6 @@ void setup() {
wm.setClass("invert");
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
// wm.setConfigPortalTimeout(600);
// wm.setConnectTimeout(5);
// wm.setShowStaticFields(true);
WiFiManagerParameter custom_html("<p>This Is Custom HTML</p>"); // only custom html
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6);
@@ -173,10 +167,10 @@ void setup() {
// const char* menu[] = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
// wm.setMenu(menu,9); // custom menu array must provide length
std::vector<const char *> menu = {"wifi","info","param","update","close","sep","erase","restart","exit"};
wm.setMenu(menu); // custom menu, pass vector
std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
// wm.setMenu(menu); // custom menu, pass vector
// wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu!
wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu!
// set static sta ip
// wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
@@ -199,17 +193,24 @@ void setup() {
// show password publicly!
// wm.setShowPassword(true);
// set configrportal timeout
wm.setConfigPortalTimeout(40);
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep in seconds
wm.setConfigPortalTimeout(120);
// wm.setConnectTimeout(20);
// wm.setShowStaticFields(true);
// wm.startConfigPortal("AutoConnectAP", "password");
// wm.setCleanConnect(true); // disconenct before connect, clean connect
// wm.setBreakAfterConfig(true);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
wifiInfo();
print_oled(F("Connecting..."),2);
if(!AUTOSTARTCP || !wm.autoConnect("WM_AutoConnectAP")) {
Serial.println("failed to connect and hit timeout");
@@ -227,13 +228,22 @@ void setup() {
Serial.println("connected...yeey :)");
print_oled("Connected\nIP: " + WiFi.localIP().toString() + "\nSSID: " + WiFi.SSID(),1);
}
pinMode(TRIGGER_PIN, INPUT);
wifiInfo();
pinMode(TRIGGER_PIN, INPUT_PULLUP);
#ifdef USEOTA
ArduinoOTA.begin();
#endif
}
void wifiInfo(){
WiFi.printDiag(Serial);
Serial.println("SAVED: " + (String)wm.getWiFiIsSaved() ? "YES" : "NO");
Serial.println("SSID: " + (String)wm.getWiFiSSID());
Serial.println("PASS: " + (String)wm.getWiFiPass());
}
void loop() {
Serial.println((String)analogRead(A0));
@@ -242,11 +252,12 @@ void loop() {
ArduinoOTA.handle();
#endif
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW ) {
if (ALLOWONDEMAND && digitalRead(TRIGGER_PIN) == LOW ) {
delay(100);
if ( digitalRead(TRIGGER_PIN) == LOW ){
Serial.println("BUTTON PRESSED");
wm.setConfigPortalTimeout(140);
wm.setParamsPage(false); // move params to seperate page, not wifi, do not combine with setmenu!
// disable captive portal redirection
// wm.setCaptivePortalEnable(false);