From 60326f3abafde092546f0c209e2e1a0fdce9cfec Mon Sep 17 00:00:00 2001 From: Luc Date: Tue, 19 Jan 2016 16:37:49 +0800 Subject: [PATCH] Code refactoring + indentation Thanks @treepleks --- esp8266/webinterface.h | 2 +- esp8266/wifi.cpp | 21 +++++++++++++++++---- esp8266/wifi.h | 1 - 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/esp8266/webinterface.h b/esp8266/webinterface.h index 93da1b9b..763afde5 100644 --- a/esp8266/webinterface.h +++ b/esp8266/webinterface.h @@ -64,10 +64,10 @@ class WEBINTERFACE_CLASS bool AddAuthIP(auth_ip * item); bool ResetAuthIP(IPAddress ip,const char * sessionID); uint8_t _upload_status; + private: auth_ip * _head; uint8_t _nb_ip; - }; extern WEBINTERFACE_CLASS * web_interface; diff --git a/esp8266/wifi.cpp b/esp8266/wifi.cpp index 9e64222c..da08a180 100644 --- a/esp8266/wifi.cpp +++ b/esp8266/wifi.cpp @@ -72,6 +72,7 @@ byte WIFI_CONFIG::split_ip (const char * ptr,byte * part) part[3]=0; return 0; } + char pstart [16]; char * ptr2; strcpy(pstart,ptr); @@ -122,6 +123,7 @@ void WIFI_CONFIG::Safe_Setup() dnsServer.stop(); delay(100); #endif + WiFi.disconnect(); //setup Soft AP WiFi.mode(WIFI_AP); @@ -146,6 +148,7 @@ bool WIFI_CONFIG::Setup() int wstatus; IPAddress currentIP; byte bflag=0; + //set the sleep mode if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) { @@ -208,11 +211,19 @@ bool WIFI_CONFIG::Setup() while (WiFi.status() != WL_CONNECTED && i<40) { switch(WiFi.status()) { - case 1:Serial.println(F("M117 No SSID found!")); + case 1: + Serial.print(FPSTR(M117_)); + Serial.println(F("No SSID found!")); break; - case 4:Serial.println(F("M117 No Connection!")); + + case 4: + Serial.print(FPSTR(M117_)); + Serial.println(F("No Connection!")); break; - default: Serial.println(F("M117 Connecting...")); + + default: + Serial.print(FPSTR(M117_)); + Serial.println(F("Connecting...")); break; } delay(500); @@ -221,6 +232,7 @@ bool WIFI_CONFIG::Setup() if (WiFi.status() != WL_CONNECTED) return false; WiFi.hostname(hostname); } + //DHCP or Static IP ? if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) return false; if (bflag==STATIC_IP_MODE) @@ -242,7 +254,8 @@ bool WIFI_CONFIG::Setup() #ifdef MDNS_FEATURE // Set up mDNS responder: if (!mdns.begin(hostname)) { - Serial.println(F("M117 Error with mDNS!")); + Serial.print(FPSTR(M117_)); + Serial.println(F("Error with mDNS!")); delay(1000); } #endif diff --git a/esp8266/wifi.h b/esp8266/wifi.h index 02275cd7..86635501 100644 --- a/esp8266/wifi.h +++ b/esp8266/wifi.h @@ -50,7 +50,6 @@ class WIFI_CONFIG const char * get_hostname(); private: char _hostname[33]; - }; extern WIFI_CONFIG wifi_config;