Compare commits

..

7 Commits

Author SHA1 Message Date
anschrammh
a01a151943 Added new classes to develop the FTP server 2019-10-11 12:39:33 +02:00
anschrammh
1317644b3d Updated version history 2019-10-11 12:38:03 +02:00
anschrammh
f632ace6ed Updated the views data structure to display the wifi modes 2019-10-11 12:33:19 +02:00
anschrammh
18e47f22d1 Switched method parameters for the sdCard begin statement 2019-10-11 12:28:15 +02:00
anschrammh
e36fca5326 Displayed state of the AP and/or STA (is it enabled or not) 2019-10-11 12:23:07 +02:00
anschrammh
49a37a34f3 Removed useless include 2019-10-11 09:52:15 +02:00
anschrammh
a824610fb6 Added two new methods to know if the STA and/or AP are enabled or not 2019-10-11 09:36:39 +02:00
13 changed files with 99 additions and 22 deletions

View File

@ -19,15 +19,20 @@ ConnectivityManager::ConnectivityManager(SDCardManager &sdCardManager) : _error(
if(!enableSTAAndAP(false))_error &= AP_AND_STA_ENABLED_ERR;
else
{
//SOFT AP PART
CFGFileParser cfgFileParser(sdCardManager, AP_CFG_FILE);
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile();
if(cfgDictionary == NULL)
{
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error &= AP_SETUP_ERR;
}
else if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL && (*cfgDictionary)("CHANNEL") != NULL && (*cfgDictionary)("SSID_HIDDEN") != NULL && (*cfgDictionary)("AP_MAX_CONNECTION") != NULL)
{
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;
else if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL && (*cfgDictionary)("CHANNEL") != NULL && (*cfgDictionary)("SSID_HIDDEN") != NULL && (*cfgDictionary)("AP_MAX_CONNECTION") != NULL && (*cfgDictionary)("ENABLED") != NULL)
{
if((*cfgDictionary)("ENABLED")->booleanValue())
{
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;
}
delete cfgDictionary;
}
else
@ -35,17 +40,20 @@ ConnectivityManager::ConnectivityManager(SDCardManager &sdCardManager) : _error(
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error &= AP_SETUP_ERR;
delete cfgDictionary;
}
//STATION PART
CFGFileParser cfgFileParserSTA(sdCardManager, STA_CFG_FILE);
cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParserSTA.parseFile();
if(cfgDictionary != NULL)
{
if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL)
if((*cfgDictionary)("SSID") != NULL && (*cfgDictionary)("PASSWORD") != NULL && (*cfgDictionary)("ENABLED") != NULL)
{
if(!begin((*cfgDictionary)("SSID")->stringValue(), (*cfgDictionary)("PASSWORD")->stringValue()))
_error &= AP_SETUP_ERR;
if((*cfgDictionary)("ENABLED")->booleanValue())
{
if(!begin((*cfgDictionary)("SSID")->stringValue(), (*cfgDictionary)("PASSWORD")->stringValue()))
_error &= AP_SETUP_ERR;
}
}
delete cfgDictionary;
}
}
@ -56,6 +64,16 @@ boolean ConnectivityManager::enableSTAAndAP(boolean enabled)
return enableSTA(enabled) && enableAP(enabled);
}
boolean ConnectivityManager::isSTAEnabled()
{
return (getMode() == WIFI_AP_STA || getMode() == WIFI_STA);
}
boolean ConnectivityManager::isAPEnabled()
{
return (getMode() == WIFI_AP_STA || getMode() == WIFI_AP);
}
unsigned char ConnectivityManager::RSSIPercent()
{
int RSSIdBm = RSSI();

View File

@ -16,7 +16,9 @@ class ConnectivityManager : public ESP8266WiFiClass
friend class SAB;
public:
boolean enableSTAAndAP(boolean enable);
boolean isSTAEnabled();
boolean isAPEnabled();
unsigned char RSSIPercent();
unsigned char getError() const;
protected:

View File

@ -3,7 +3,6 @@
#include "WEBServer.h"
#include "TCPClient.h"
#include "Dictionary.h"
class WEBClient : public TCPClient
{

View File

@ -13,8 +13,8 @@ SAB sab;
unsigned long currentMs = 0, buttonMs = 0;
volatile boolean ioStateChange(false);
View1Packet v1p = {sab.getRtcManager().getDateTime(), sab.getSdCardManager().getSize(GBYTE), sab.getPowerManager().getPowerInfo(),0, sab.getSoftVersion(), &sab};
ViewAPPacket vap = {sab.getConnectivityManager().softAPmacAddress(), sab.getConnectivityManager().softAPSSID(), sab.getConnectivityManager().softAPIP(), sab.getConnectivityManager().softAPgetStationNum()};
ViewSTAPacket vstap = {sab.getConnectivityManager().macAddress(), sab.getConnectivityManager().localIP(), sab.getConnectivityManager().RSSI()};
ViewAPPacket vap = {sab.getConnectivityManager().softAPmacAddress(), sab.getConnectivityManager().softAPSSID(), sab.getConnectivityManager().softAPIP(), sab.getConnectivityManager().softAPgetStationNum(), sab.getConnectivityManager().isAPEnabled()};
ViewSTAPacket vstap = {sab.getConnectivityManager().macAddress(), sab.getConnectivityManager().localIP(), sab.getConnectivityManager().RSSI(), sab.getConnectivityManager().isSTAEnabled()};
ViewIoInfoPacket vio = {{0},{0}};
SdCardApiPacket sdCardApiPacket = {NULL, NULL};

View File

@ -16,5 +16,6 @@
#define SOFT_VERSION "1.2.0" //Added new PowerManager class
#define SOFT_VERSION "1.2.1" //Corrected a bug in the TaskSchedulerManager class
#define SOFT_VERSION "1.3.0" //Implemented multi-client non blocking webserver
#define SOFT_VERSION "1.3.1" //Fixed sdCardUnmount api call
#endif //VERSIONS_H

View File

@ -39,8 +39,12 @@ boolean view_2(Adafruit_SSD1306 &display, void *pData)
char conn_str[300];
ViewAPPacket *p = (ViewAPPacket *) pData;
if(p->enabled)
sprintf(conn_str,"Ip addr : %u.%u.%u.%u\nMac addr : \n%s\nConns : %u\nSSID : %s\n" ,p->ipAddr[0], p->ipAddr[1], p->ipAddr[2], p->ipAddr[3], p->macAddr.c_str(), p->nbOfCon, p->ssid.c_str());
else
sprintf(conn_str,"AP connectivity\nis not enabled\nCheck the cfg file\n");
sprintf(conn_str,"Ip addr : %u.%u.%u.%u\nMac addr : \n%s\nConns : %u\nSSID : %s\n" ,p->ipAddr[0], p->ipAddr[1], p->ipAddr[2], p->ipAddr[3], p->macAddr.c_str(), p->nbOfCon, p->ssid.c_str());
display.println(conn_str);
display.setCursor(0,56);
@ -54,8 +58,12 @@ boolean view_3(Adafruit_SSD1306 &display, void *pData)
char conn_str[300];
ViewSTAPacket *p = (ViewSTAPacket *) pData;
if(p->enabled)
sprintf(conn_str,"Ip addr : %u.%u.%u.%u\nMac addr : \n%s\nSignal : %d dBm\n", p->ipAddr[0], p->ipAddr[1], p->ipAddr[2], p->ipAddr[3], p->macAddr.c_str(), p->sigStrength);
else
sprintf(conn_str,"STA connectivity\nis not enabled\nCheck the cfg file\n");
sprintf(conn_str,"Ip addr : %u.%u.%u.%u\nMac addr : \n%s\nSignal : %d dBm\n", p->ipAddr[0], p->ipAddr[1], p->ipAddr[2], p->ipAddr[3], p->macAddr.c_str(), p->sigStrength);
display.println(conn_str);
display.setCursor(0,56);

View File

@ -22,6 +22,7 @@ typedef struct viewAPPacket
String ssid;
IPAddress ipAddr;
uint8_t nbOfCon;
boolean enabled;
} ViewAPPacket;
//AP info
@ -32,6 +33,7 @@ typedef struct viewSTAPacket
String macAddr;
IPAddress ipAddr;
int sigStrength;
boolean enabled;
} ViewSTAPacket;
//STA info

View File

@ -121,7 +121,7 @@ boolean sdCardMountApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *w
float *sdCardSize = (float *) &pV->pView->sdCardSize;
char buffer[200];
if(p->getSdCardManager().begin(p->getSdCardConfig().getSPISpeed(), p->getPinConfig().getSPI_sdCard_cs()))
if(p->getSdCardManager().begin(p->getPinConfig().getSPI_sdCard_cs(), p->getSdCardConfig().getSPISpeed()))
{
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"card\" : \"mounted\" }");
*sdCardSize = p->getSdCardManager().getSize(GBYTE);

View File

@ -0,0 +1 @@
#include "FTPClient.h"

View File

@ -0,0 +1,13 @@
#ifndef FTPCLIENT_H
#define FTPCLIENT_H
#include "TCPClient.h"
class FTPClient
{
public:
protected:
private:
};
#endif //FTPCLIENT_H

View File

@ -0,0 +1,32 @@
#ifndef FTPSERVER_H
#define FTPSERVER_H
#include "TCPServer.h"
template <typename T>
class FTPServer : public TCPServer<T>
{
public:
FTPServer(unsigned int port = 22, const char login = "", const char password = "", uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer<T>(port, maxClient, clientCommandDataBufferSize), _login(NULL), _password(NULL)
{
_login = (char *)malloc((sizeof(char) * strlen(login)) + 1);
if(_login != NULL)
strcpy(_login, login);
_password = (char *)malloc((sizeof(char) * strlen(password)) + 1);
if(_password != NULL)
strcpy(_password, password);
}
virtual ~FTPServer()
{
free(_login);free(_password);
}
protected:
private:
char *_login;
char *_password;
};
#endif //FTPSERVER_H

View File

@ -3,7 +3,6 @@
#include "WEBServer.h"
#include "TCPClient.h"
#include "Dictionary.h"
class WEBClient : public TCPClient
{

View File

@ -7,12 +7,14 @@
#include "TCPServer.h"
#include "WEBServer.h"
#include "WEBClient.h"
#include "FTPServer.h"
#include "FTPClient.h"
uint32_t lastFreeMem(0);
uint16_t lastClientCount(0);
TCPServer<TCPClient> server(80, MAX_CLIENT, 5);
WEBServer<WEBClient> webServer(8080);
//TCPServer<TCPClient> server(80, MAX_CLIENT, 5);
//WEBServer<WEBClient> webServer(8080);
WiFiEventHandler gotIpEventHandler, disconnectedEventHandler;
@ -39,17 +41,17 @@ void debugInfo()
Serial.print("Heap Frag : ");Serial.println(frag);
lastFreeMem = freeMem;
}
if(lastClientCount != server.getConnectedClientsCount())
/*if(lastClientCount != server.getConnectedClientsCount())
{
lastClientCount = server.getConnectedClientsCount();
Serial.print("Connected client(s) : ");Serial.println(lastClientCount);
}
}*/
}
void loop() {
// put your main code here, to run repeatedly:
server.runServer();
webServer.runServer();
//server.runServer();
//webServer.runServer();
debugInfo();
}