Compare commits

..

No commits in common. "9247d261cf78dfe452bccab97874b739d0671c0e" and "f96ccfd8a1f6770c63bbb31f2bd5d04b9dff72fc" have entirely different histories.

8 changed files with 40 additions and 125 deletions

View File

@ -1,7 +1,5 @@
#include "ConnectivityManager.h"
//#define DEBUG_CONMAN
ConnectivityManager::ConnectivityManager(bool persistent)
{
ConnectivityManager::persistent(persistent);
@ -18,7 +16,7 @@ boolean ConnectivityManager::connect()
{
if(!WiFi.disconnect(true))_error |= STA_ENABLED_DISABLE_ERR;
if(!WiFi.softAPdisconnect(true))_error |= AP_ENABLED_DISABLE_ERR;
if(!softAP("ESP8266SwissArmyBoard"))_error |= AP_SETUP_ERR;
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
return _error == NO_ERROR;
}
@ -34,30 +32,30 @@ boolean ConnectivityManager::connectToSTA()
CFGFileParser cfgFileParserSTA(*_sdCardManager, STA_CFG_FILE);
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParserSTA.parseFile();
const char *PSK(nullptr);
uint8_t channel(0);
boolean toBeReturned(true);
if(!WiFi.disconnect(true))_error |= STA_ENABLED_DISABLE_ERR;
if(cfgDictionary != nullptr)
if(cfgDictionary != NULL)
{
if((*cfgDictionary)("ENABLED") != nullptr && (*cfgDictionary)("SSID") != nullptr)
if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL && (*cfgDictionary)("ENABLED") != NULL)
{
if((*cfgDictionary)("ENABLED")->booleanValue())
{
if((*cfgDictionary)("PASSWORD") != nullptr)
PSK = (*cfgDictionary)("PASSWORD")->stringValue();
if((*cfgDictionary)("CHANNEL") != nullptr)
channel = (*cfgDictionary)("CHANNEL")->intValue();
if(!begin((*cfgDictionary)("SSID")->stringValue(), PSK, channel))
if(!begin((*cfgDictionary)("SSID")->stringValue(), (*cfgDictionary)("PASSWORD")->stringValue()))
{
_error |= STA_SETUP_ERR;
toBeReturned = false;
}
}
}
else
toBeReturned = false;
delete cfgDictionary;
}
else
toBeReturned = false;
return toBeReturned;
}
@ -65,76 +63,35 @@ boolean ConnectivityManager::startAP()
{
CFGFileParser cfgFileParser(*_sdCardManager, AP_CFG_FILE);
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile();
const char defaultSSID[] = "ESP8266SwissArmyBoard";
const char *SSID(defaultSSID);
const char *PSK(nullptr);
uint8_t channel(1), maxConnection(4);
boolean hideSSID(false);
boolean toBeReturned(true);
if(!WiFi.softAPdisconnect(true))_error |= AP_ENABLED_DISABLE_ERR;
if(cfgDictionary == nullptr)
if(cfgDictionary == NULL)
{
if(!softAP(defaultSSID))
{
_error |= AP_SETUP_ERR;
toBeReturned = false;
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
return false;
}
}
else
{
if((*cfgDictionary)("ENABLED") != nullptr)
else if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL && (*cfgDictionary)("CHANNEL") != NULL && (*cfgDictionary)("HIDE_SSID") != NULL && (*cfgDictionary)("AP_MAX_CONNECTION") != NULL && (*cfgDictionary)("ENABLED") != NULL)
{
if((*cfgDictionary)("ENABLED")->booleanValue())
{
if((*cfgDictionary)("SSID") != nullptr)
SSID = (*cfgDictionary)("SSID")->stringValue();
if((*cfgDictionary)("PASSWORD") != nullptr)
PSK = (*cfgDictionary)("PASSWORD")->stringValue();
if((*cfgDictionary)("CHANNEL") != nullptr)
channel = (*cfgDictionary)("CHANNEL")->intValue();
if((*cfgDictionary)("HIDE_SSID") != nullptr)
hideSSID = (*cfgDictionary)("HIDE_SSID")->booleanValue();
if((*cfgDictionary)("AP_MAX_CONNECTION") != nullptr)
maxConnection = (*cfgDictionary)("AP_MAX_CONNECTION")->intValue();
#ifdef DEBUG_CONMAN
Serial.printf("AP is enabled, params are :\nSSID : %s\nPSK : %s\nCHAN : %u\nHIDE_SSID : %u\nMAX_CON : %u\n",
SSID,
PSK ? PSK : "",
channel,
hideSSID,
maxConnection);
#endif
if(!softAP(SSID, PSK, channel, hideSSID, maxConnection))
if(!softAP((*cfgDictionary)("SSID")->stringValue(), strcmp((*cfgDictionary)("PASSWORD")->stringValue(),"") == 0 ? NULL:(*cfgDictionary)("PASSWORD")->stringValue(), (*cfgDictionary)("CHANNEL")->intValue(), (*cfgDictionary)("HIDE_SSID")->booleanValue(), (*cfgDictionary)("AP_MAX_CONNECTION")->intValue()))
{
_error |= AP_SETUP_ERR;
toBeReturned = false;
}
}
}
else
{
#ifdef DEBUG_CONMAN
Serial.printf("AP is disabled, nothing to be done\n");
#endif
}
}
else //If the enable parameter is not specified we start the AP by default.
{
#ifdef DEBUG_CONMAN
Serial.printf("ENABLED param missing, enabling AP\n");
#endif
if(!softAP(SSID, PSK, channel, hideSSID, maxConnection))
{
_error |= AP_SETUP_ERR;
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
toBeReturned = false;
}
}
delete cfgDictionary;
}
return toBeReturned;
}

View File

@ -27,7 +27,7 @@ class FTPServer : public TCPServer<T>
{
if (login != NULL)
{
if (strlen(login))
if (strlen(login) > 0)
{
_login = (char *)malloc((sizeof(char) * strlen(login)) + 1);
strcpy(_login, login);
@ -36,7 +36,7 @@ class FTPServer : public TCPServer<T>
if (password != NULL)
{
if (strlen(password))
if (strlen(password) > 0)
{
_password = (char *)malloc((sizeof(char) * strlen(password)) + 1);
strcpy(_password, password);
@ -53,7 +53,7 @@ class FTPServer : public TCPServer<T>
virtual ~FTPServer()
{
_dataServer.stop();
free(_login); free(_password); free(_FTPDir);
free(_login); free(_password);
}
virtual void stop()
@ -67,12 +67,7 @@ class FTPServer : public TCPServer<T>
virtual void setFTPDir(const char *FTPDir)
{
if(FTPDir)
{
free(_FTPDir);
_FTPDir = (char *)malloc((strlen(FTPDir) * sizeof(char)) + 1);
strcpy(_FTPDir, FTPDir);
}
_FTPDir = FTPDir;
}
protected:
@ -1033,7 +1028,7 @@ class FTPServer : public TCPServer<T>
char *_login;
char *_password;
char *_FTPDir = nullptr;
const char *_FTPDir = NULL; //Pointer to constant string and char * const is a constant pointer to string
uint16_t _dataPort;
WiFiServer _dataServer; //In passive mode, the FTP server opens two different ports (one for the commands and the other for the data stream)

View File

@ -174,7 +174,9 @@ class TCPServer
return;
}
_clientList.addFirst(_currentClient);
}
virtual void processClientData(T *client)

View File

@ -42,11 +42,6 @@ class WEBServer : public TCPServer<T>, public HttpConstants
WEBServer(uint16_t port = 80, SDClass *sdClass = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientDataBufferSize = 256) : TCPServer<T>(port, maxClient, clientDataBufferSize), _sdClass(sdClass) {}
virtual ~WEBServer()
{
free(_WWWDir);
}
boolean addApiRoutine(const char *uri, boolean (*apiRoutine)(HttpRequestData&, WiFiClient*, void*), void *pData, HttpRequestMethod HRM = UNDEFINED)
{
return _apiDictionary.add(uri, new ApiRoutine({apiRoutine, pData, HRM}));
@ -77,12 +72,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
void setWWWDir(const char *WWWDir)
{
if(WWWDir != nullptr)
{
free(_WWWDir);
_WWWDir = (char *)malloc((strlen(WWWDir) * sizeof(char)) + 1);
strcpy(_WWWDir, WWWDir);
}
_WWWDir = WWWDir;
}
protected:
private:
@ -175,14 +165,11 @@ class WEBServer : public TCPServer<T>, public HttpConstants
case HttpParserStatus::PARSE_HTTP_RESOURCE:
{
char *pRsrc(strchr((char *)client->_data, ' ')), *pRsrcQuery(strchr((char *)client->_data, '?'));
//!\ the ? should be present before ' ' if ' ' is found !!!!
if(pRsrc && pRsrcQuery)
if(pRsrcQuery > pRsrc)pRsrcQuery = nullptr;
//The case where we have the resource complete or not complete with query parameters like : GET /some/path/resource.rsrc?param1=one&param2 HTTP/1.1
if(pRsrc || pRsrcQuery)
{
uint16_t rawLengthOfResource(0);
if(pRsrcQuery )
if(pRsrcQuery)
{
*pRsrcQuery = '\0'; // The ? is the end of the resource string
rawLengthOfResource = pRsrcQuery - (char *)client->_data;
@ -195,7 +182,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
*pRsrc = '\0';
rawLengthOfResource = pRsrc - (char *)client->_data;
#ifdef DEBUG_WEBS
Serial.printf("Resource w/o query\nRaw length : %u\n",rawLengthOfResource);
Serial.printf("Resource w/o query\n");
#endif
}
@ -950,7 +937,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
Dictionary<ApiRoutine> _apiDictionary;
SDClass *_sdClass;
char *_WWWDir = nullptr; //Website root folder
const char *_WWWDir = NULL; //Website root folder
};
#endif //WEBSERVER_H

View File

@ -42,8 +42,7 @@ void setup()
if(cfgDictionary != NULL)
{
Serial.printf("AP PASSWORD : %s\n",
(*cfgDictionary)("PASSWORD") ? (*cfgDictionary)("PASSWORD")->stringValue() : "");
Serial.print("AP PASSWORD : ");if((*cfgDictionary)("PASSWORD") != NULL)Serial.println((*cfgDictionary)("PASSWORD")->stringValue());
}
#if 0
@ -93,7 +92,6 @@ void setup()
sab.getWebServer().addApiRoutine("/sab/io/set/level", &(ioSetLevelApi), &sab, WEBServer<WEBClient>::GET);
sab.getWebServer().addApiRoutine("/sab/io/get/mode", &(ioGetModeApi), &sab, WEBServer<WEBClient>::GET);
sab.getWebServer().addApiRoutine("/sab/io/set/mode", &(ioSetModeApi), &sab, WEBServer<WEBClient>::GET);
sab.getWebServer().addApiRoutine("/sab/ota/update", &(otaUpdateApi), NULL, WEBServer<WEBClient>::POST);
sab.getIoManager().setISROnIOChange(&(ioISR), GPIO_3_RX);

View File

@ -557,26 +557,3 @@ boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
wc->print(buffer);
return true;
}
boolean otaUpdateApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{
Serial.printf("OTA Update resquest\n");
char buffer[500];
size_t read(0);
while(wc->available())
{
read = wc->read(buffer, 500);
for(uint8_t i(0); i < read; i++)
Serial.printf("%02X %s",buffer[i], i % 30 == 0 ? "\n" : "");
yield();
}
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::TEXT_PLAIN), 2);
wc->print("OK");
//wc->peekBuffer
return true;
}

View File

@ -30,6 +30,5 @@ boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*
boolean ioSetLevelApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean otaUpdateApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
#endif