Corrected some code and improved logic
This commit is contained in:
parent
df1816ca44
commit
aa544d307e
@ -3,28 +3,18 @@
|
|||||||
ConnectivityManager::ConnectivityManager() : _error(0), _sdCardManager(NULL)
|
ConnectivityManager::ConnectivityManager() : _error(0), _sdCardManager(NULL)
|
||||||
{
|
{
|
||||||
persistent(false);
|
persistent(false);
|
||||||
WiFi.disconnect();
|
|
||||||
WiFi.softAPdisconnect();
|
|
||||||
|
|
||||||
if(!enableSTAAndAP(false))_error &= AP_AND_STA_ENABLED_ERR;
|
if(!WiFi.disconnect(true))_error |= STA_ENABLED_DISABLE_ERR;
|
||||||
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error &= AP_SETUP_ERR;
|
if(!WiFi.softAPdisconnect(true))_error |= AP_ENABLED_DISABLE_ERR;
|
||||||
|
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectivityManager::ConnectivityManager(SDCardManager &sdCardManager) : _error(0), _sdCardManager(&sdCardManager)
|
ConnectivityManager::ConnectivityManager(SDCardManager &sdCardManager) : _error(0), _sdCardManager(&sdCardManager)
|
||||||
{
|
{
|
||||||
persistent(false);
|
persistent(false);
|
||||||
WiFi.disconnect();
|
|
||||||
WiFi.softAPdisconnect();
|
|
||||||
|
|
||||||
if(!enableSTAAndAP(false))_error &= AP_AND_STA_ENABLED_ERR;
|
startAP();
|
||||||
else
|
connectToSTA();
|
||||||
{
|
|
||||||
//SOFT AP PART
|
|
||||||
startAP();
|
|
||||||
|
|
||||||
//STATION PART
|
|
||||||
connectToSTA();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ConnectivityManager::connectToSTA()
|
boolean ConnectivityManager::connectToSTA()
|
||||||
@ -34,6 +24,7 @@ boolean ConnectivityManager::connectToSTA()
|
|||||||
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParserSTA.parseFile();
|
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParserSTA.parseFile();
|
||||||
|
|
||||||
boolean toBeReturned(true);
|
boolean toBeReturned(true);
|
||||||
|
if(!WiFi.disconnect(true))_error |= STA_ENABLED_DISABLE_ERR;
|
||||||
|
|
||||||
if(cfgDictionary != NULL)
|
if(cfgDictionary != NULL)
|
||||||
{
|
{
|
||||||
@ -43,12 +34,10 @@ boolean ConnectivityManager::connectToSTA()
|
|||||||
{
|
{
|
||||||
if(!begin((*cfgDictionary)("SSID")->stringValue(), (*cfgDictionary)("PASSWORD")->stringValue()))
|
if(!begin((*cfgDictionary)("SSID")->stringValue(), (*cfgDictionary)("PASSWORD")->stringValue()))
|
||||||
{
|
{
|
||||||
_error &= AP_SETUP_ERR;
|
_error |= STA_SETUP_ERR;
|
||||||
toBeReturned = false;
|
toBeReturned = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
enableSTA(false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
toBeReturned = false;
|
toBeReturned = false;
|
||||||
@ -67,12 +56,13 @@ boolean ConnectivityManager::startAP()
|
|||||||
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile();
|
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile();
|
||||||
|
|
||||||
boolean toBeReturned(true);
|
boolean toBeReturned(true);
|
||||||
|
if(!WiFi.softAPdisconnect(true))_error |= AP_ENABLED_DISABLE_ERR;
|
||||||
|
|
||||||
if(cfgDictionary == NULL)
|
if(cfgDictionary == NULL)
|
||||||
{
|
{
|
||||||
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error &= AP_SETUP_ERR;
|
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
|
||||||
|
|
||||||
toBeReturned = false;
|
return false;
|
||||||
}
|
}
|
||||||
else if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL && (*cfgDictionary)("CHANNEL") != NULL && (*cfgDictionary)("SSID_HIDDEN") != NULL && (*cfgDictionary)("AP_MAX_CONNECTION") != NULL && (*cfgDictionary)("ENABLED") != NULL)
|
else if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL && (*cfgDictionary)("CHANNEL") != NULL && (*cfgDictionary)("SSID_HIDDEN") != NULL && (*cfgDictionary)("AP_MAX_CONNECTION") != NULL && (*cfgDictionary)("ENABLED") != NULL)
|
||||||
{
|
{
|
||||||
@ -80,21 +70,19 @@ boolean ConnectivityManager::startAP()
|
|||||||
{
|
{
|
||||||
if(!softAP((*cfgDictionary)("SSID")->stringValue(), strcmp((*cfgDictionary)("PASSWORD")->stringValue(),"") == 0 ? NULL:(*cfgDictionary)("PASSWORD")->stringValue(), (*cfgDictionary)("CHANNEL")->intValue(), (*cfgDictionary)("SSID_HIDDEN")->booleanValue(), (*cfgDictionary)("AP_MAX_CONNECTION")->intValue()))
|
if(!softAP((*cfgDictionary)("SSID")->stringValue(), strcmp((*cfgDictionary)("PASSWORD")->stringValue(),"") == 0 ? NULL:(*cfgDictionary)("PASSWORD")->stringValue(), (*cfgDictionary)("CHANNEL")->intValue(), (*cfgDictionary)("SSID_HIDDEN")->booleanValue(), (*cfgDictionary)("AP_MAX_CONNECTION")->intValue()))
|
||||||
{
|
{
|
||||||
_error &= AP_SETUP_ERR;
|
_error |= AP_SETUP_ERR;
|
||||||
toBeReturned = false;
|
toBeReturned = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
enableAP(false);
|
|
||||||
delete cfgDictionary;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error &= AP_SETUP_ERR;
|
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
|
||||||
delete cfgDictionary;
|
|
||||||
toBeReturned = false;
|
toBeReturned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete cfgDictionary;
|
||||||
|
|
||||||
return toBeReturned;
|
return toBeReturned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
#define MAX_RSSI -50
|
#define MAX_RSSI -50
|
||||||
#define COEF_RSSI 3.225806452
|
#define COEF_RSSI 3.225806452
|
||||||
|
|
||||||
|
#define STA_ENABLED_DISABLE_ERR B00001000
|
||||||
|
#define AP_ENABLED_DISABLE_ERR B00000001
|
||||||
|
#define AP_SETUP_ERR B00000010
|
||||||
|
#define STA_SETUP_ERR B00000100
|
||||||
|
|
||||||
class ConnectivityManager : public ESP8266WiFiClass
|
class ConnectivityManager : public ESP8266WiFiClass
|
||||||
{
|
{
|
||||||
friend class SAB;
|
friend class SAB;
|
||||||
@ -18,14 +23,15 @@ class ConnectivityManager : public ESP8266WiFiClass
|
|||||||
boolean enableSTAAndAP(boolean enable);
|
boolean enableSTAAndAP(boolean enable);
|
||||||
boolean isSTAEnabled();
|
boolean isSTAEnabled();
|
||||||
boolean isAPEnabled();
|
boolean isAPEnabled();
|
||||||
boolean connectToSTA();
|
|
||||||
boolean startAP();
|
|
||||||
|
|
||||||
unsigned char RSSIPercent();
|
unsigned char RSSIPercent();
|
||||||
unsigned char getError() const;
|
unsigned char getError() const;
|
||||||
protected:
|
protected:
|
||||||
ConnectivityManager();
|
ConnectivityManager();
|
||||||
ConnectivityManager(SDCardManager &sdCardManager);
|
ConnectivityManager(SDCardManager &sdCardManager);
|
||||||
|
|
||||||
|
boolean connectToSTA();
|
||||||
|
boolean startAP();
|
||||||
private:
|
private:
|
||||||
unsigned char _error;
|
unsigned char _error;
|
||||||
SDCardManager *_sdCardManager;
|
SDCardManager *_sdCardManager;
|
||||||
|
Loading…
Reference in New Issue
Block a user