Compare commits
No commits in common. "9247d261cf78dfe452bccab97874b739d0671c0e" and "f96ccfd8a1f6770c63bbb31f2bd5d04b9dff72fc" have entirely different histories.
9247d261cf
...
f96ccfd8a1
@ -23,7 +23,7 @@ void *CFGFileParser::parseFile()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_state = LINE_BREAK;
|
_state = LINE_BREAK;
|
||||||
while(file.available())
|
while(file.available())
|
||||||
{
|
{
|
||||||
readChar = (char)file.read();
|
readChar = (char)file.read();
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include "ConnectivityManager.h"
|
#include "ConnectivityManager.h"
|
||||||
|
|
||||||
//#define DEBUG_CONMAN
|
|
||||||
|
|
||||||
ConnectivityManager::ConnectivityManager(bool persistent)
|
ConnectivityManager::ConnectivityManager(bool persistent)
|
||||||
{
|
{
|
||||||
ConnectivityManager::persistent(persistent);
|
ConnectivityManager::persistent(persistent);
|
||||||
@ -18,7 +16,7 @@ boolean ConnectivityManager::connect()
|
|||||||
{
|
{
|
||||||
if(!WiFi.disconnect(true))_error |= STA_ENABLED_DISABLE_ERR;
|
if(!WiFi.disconnect(true))_error |= STA_ENABLED_DISABLE_ERR;
|
||||||
if(!WiFi.softAPdisconnect(true))_error |= AP_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;
|
return _error == NO_ERROR;
|
||||||
}
|
}
|
||||||
@ -34,30 +32,30 @@ boolean ConnectivityManager::connectToSTA()
|
|||||||
CFGFileParser cfgFileParserSTA(*_sdCardManager, STA_CFG_FILE);
|
CFGFileParser cfgFileParserSTA(*_sdCardManager, STA_CFG_FILE);
|
||||||
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParserSTA.parseFile();
|
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParserSTA.parseFile();
|
||||||
|
|
||||||
const char *PSK(nullptr);
|
|
||||||
uint8_t channel(0);
|
|
||||||
boolean toBeReturned(true);
|
boolean toBeReturned(true);
|
||||||
if(!WiFi.disconnect(true))_error |= STA_ENABLED_DISABLE_ERR;
|
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)("ENABLED")->booleanValue())
|
||||||
{
|
{
|
||||||
if((*cfgDictionary)("PASSWORD") != nullptr)
|
if(!begin((*cfgDictionary)("SSID")->stringValue(), (*cfgDictionary)("PASSWORD")->stringValue()))
|
||||||
PSK = (*cfgDictionary)("PASSWORD")->stringValue();
|
|
||||||
if((*cfgDictionary)("CHANNEL") != nullptr)
|
|
||||||
channel = (*cfgDictionary)("CHANNEL")->intValue();
|
|
||||||
if(!begin((*cfgDictionary)("SSID")->stringValue(), PSK, channel))
|
|
||||||
{
|
{
|
||||||
_error |= STA_SETUP_ERR;
|
_error |= STA_SETUP_ERR;
|
||||||
toBeReturned = false;
|
toBeReturned = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
toBeReturned = false;
|
||||||
|
|
||||||
delete cfgDictionary;
|
delete cfgDictionary;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
toBeReturned = false;
|
||||||
|
|
||||||
return toBeReturned;
|
return toBeReturned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,76 +63,35 @@ boolean ConnectivityManager::startAP()
|
|||||||
{
|
{
|
||||||
CFGFileParser cfgFileParser(*_sdCardManager, AP_CFG_FILE);
|
CFGFileParser cfgFileParser(*_sdCardManager, AP_CFG_FILE);
|
||||||
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile();
|
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);
|
boolean toBeReturned(true);
|
||||||
if(!WiFi.softAPdisconnect(true))_error |= AP_ENABLED_DISABLE_ERR;
|
if(!WiFi.softAPdisconnect(true))_error |= AP_ENABLED_DISABLE_ERR;
|
||||||
|
|
||||||
if(cfgDictionary == nullptr)
|
if(cfgDictionary == NULL)
|
||||||
{
|
{
|
||||||
if(!softAP(defaultSSID))
|
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
|
||||||
{
|
|
||||||
_error |= AP_SETUP_ERR;
|
return false;
|
||||||
toBeReturned = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
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") != nullptr)
|
if((*cfgDictionary)("ENABLED")->booleanValue())
|
||||||
{
|
{
|
||||||
if((*cfgDictionary)("ENABLED")->booleanValue())
|
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()))
|
||||||
{
|
|
||||||
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))
|
|
||||||
{
|
|
||||||
_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;
|
_error |= AP_SETUP_ERR;
|
||||||
toBeReturned = false;
|
toBeReturned = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete cfgDictionary;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error |= AP_SETUP_ERR;
|
||||||
|
toBeReturned = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete cfgDictionary;
|
||||||
|
|
||||||
return toBeReturned;
|
return toBeReturned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class FTPServer : public TCPServer<T>
|
|||||||
{
|
{
|
||||||
if (login != NULL)
|
if (login != NULL)
|
||||||
{
|
{
|
||||||
if (strlen(login))
|
if (strlen(login) > 0)
|
||||||
{
|
{
|
||||||
_login = (char *)malloc((sizeof(char) * strlen(login)) + 1);
|
_login = (char *)malloc((sizeof(char) * strlen(login)) + 1);
|
||||||
strcpy(_login, login);
|
strcpy(_login, login);
|
||||||
@ -36,7 +36,7 @@ class FTPServer : public TCPServer<T>
|
|||||||
|
|
||||||
if (password != NULL)
|
if (password != NULL)
|
||||||
{
|
{
|
||||||
if (strlen(password))
|
if (strlen(password) > 0)
|
||||||
{
|
{
|
||||||
_password = (char *)malloc((sizeof(char) * strlen(password)) + 1);
|
_password = (char *)malloc((sizeof(char) * strlen(password)) + 1);
|
||||||
strcpy(_password, password);
|
strcpy(_password, password);
|
||||||
@ -53,7 +53,7 @@ class FTPServer : public TCPServer<T>
|
|||||||
virtual ~FTPServer()
|
virtual ~FTPServer()
|
||||||
{
|
{
|
||||||
_dataServer.stop();
|
_dataServer.stop();
|
||||||
free(_login); free(_password); free(_FTPDir);
|
free(_login); free(_password);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void stop()
|
virtual void stop()
|
||||||
@ -67,12 +67,7 @@ class FTPServer : public TCPServer<T>
|
|||||||
|
|
||||||
virtual void setFTPDir(const char *FTPDir)
|
virtual void setFTPDir(const char *FTPDir)
|
||||||
{
|
{
|
||||||
if(FTPDir)
|
_FTPDir = FTPDir;
|
||||||
{
|
|
||||||
free(_FTPDir);
|
|
||||||
_FTPDir = (char *)malloc((strlen(FTPDir) * sizeof(char)) + 1);
|
|
||||||
strcpy(_FTPDir, FTPDir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -1033,7 +1028,7 @@ class FTPServer : public TCPServer<T>
|
|||||||
|
|
||||||
char *_login;
|
char *_login;
|
||||||
char *_password;
|
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;
|
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)
|
WiFiServer _dataServer; //In passive mode, the FTP server opens two different ports (one for the commands and the other for the data stream)
|
||||||
|
@ -174,7 +174,9 @@ class TCPServer
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_clientList.addFirst(_currentClient);
|
_clientList.addFirst(_currentClient);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void processClientData(T *client)
|
virtual void processClientData(T *client)
|
||||||
|
@ -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) {}
|
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)
|
boolean addApiRoutine(const char *uri, boolean (*apiRoutine)(HttpRequestData&, WiFiClient*, void*), void *pData, HttpRequestMethod HRM = UNDEFINED)
|
||||||
{
|
{
|
||||||
return _apiDictionary.add(uri, new ApiRoutine({apiRoutine, pData, HRM}));
|
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)
|
void setWWWDir(const char *WWWDir)
|
||||||
{
|
{
|
||||||
if(WWWDir != nullptr)
|
_WWWDir = WWWDir;
|
||||||
{
|
|
||||||
free(_WWWDir);
|
|
||||||
_WWWDir = (char *)malloc((strlen(WWWDir) * sizeof(char)) + 1);
|
|
||||||
strcpy(_WWWDir, WWWDir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
@ -175,14 +165,11 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
case HttpParserStatus::PARSE_HTTP_RESOURCE:
|
case HttpParserStatus::PARSE_HTTP_RESOURCE:
|
||||||
{
|
{
|
||||||
char *pRsrc(strchr((char *)client->_data, ' ')), *pRsrcQuery(strchr((char *)client->_data, '?'));
|
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¶m2 HTTP/1.1
|
//The case where we have the resource complete or not complete with query parameters like : GET /some/path/resource.rsrc?param1=one¶m2 HTTP/1.1
|
||||||
if(pRsrc || pRsrcQuery)
|
if(pRsrc || pRsrcQuery)
|
||||||
{
|
{
|
||||||
uint16_t rawLengthOfResource(0);
|
uint16_t rawLengthOfResource(0);
|
||||||
if(pRsrcQuery )
|
if(pRsrcQuery)
|
||||||
{
|
{
|
||||||
*pRsrcQuery = '\0'; // The ? is the end of the resource string
|
*pRsrcQuery = '\0'; // The ? is the end of the resource string
|
||||||
rawLengthOfResource = pRsrcQuery - (char *)client->_data;
|
rawLengthOfResource = pRsrcQuery - (char *)client->_data;
|
||||||
@ -195,7 +182,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
*pRsrc = '\0';
|
*pRsrc = '\0';
|
||||||
rawLengthOfResource = pRsrc - (char *)client->_data;
|
rawLengthOfResource = pRsrc - (char *)client->_data;
|
||||||
#ifdef DEBUG_WEBS
|
#ifdef DEBUG_WEBS
|
||||||
Serial.printf("Resource w/o query\nRaw length : %u\n",rawLengthOfResource);
|
Serial.printf("Resource w/o query\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,7 +937,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
|
|
||||||
Dictionary<ApiRoutine> _apiDictionary;
|
Dictionary<ApiRoutine> _apiDictionary;
|
||||||
SDClass *_sdClass;
|
SDClass *_sdClass;
|
||||||
char *_WWWDir = nullptr; //Website root folder
|
const char *_WWWDir = NULL; //Website root folder
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //WEBSERVER_H
|
#endif //WEBSERVER_H
|
||||||
|
@ -42,8 +42,7 @@ void setup()
|
|||||||
|
|
||||||
if(cfgDictionary != NULL)
|
if(cfgDictionary != NULL)
|
||||||
{
|
{
|
||||||
Serial.printf("AP PASSWORD : %s\n",
|
Serial.print("AP PASSWORD : ");if((*cfgDictionary)("PASSWORD") != NULL)Serial.println((*cfgDictionary)("PASSWORD")->stringValue());
|
||||||
(*cfgDictionary)("PASSWORD") ? (*cfgDictionary)("PASSWORD")->stringValue() : "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#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/set/level", &(ioSetLevelApi), &sab, WEBServer<WEBClient>::GET);
|
||||||
sab.getWebServer().addApiRoutine("/sab/io/get/mode", &(ioGetModeApi), &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/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);
|
sab.getIoManager().setISROnIOChange(&(ioISR), GPIO_3_RX);
|
||||||
|
|
||||||
|
@ -557,26 +557,3 @@ boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
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;
|
|
||||||
}
|
|
||||||
|
@ -30,6 +30,5 @@ boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*
|
|||||||
boolean ioSetLevelApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
boolean ioSetLevelApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||||
boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||||
boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||||
boolean otaUpdateApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user