HomeWaterLeaksDetection
|
#include <WebServer.h>
Public Member Functions | |
void | setup (LeaksController *leaksController) |
Sets the pointer to an instance of LeaksController. More... | |
void | update () override |
Updates the class. More... | |
void | addHTMLSource (HTMLDataSource *source) |
Adds another source of data for the HTML content. More... | |
Static Public Member Functions | |
static WebServer * | getInstance () |
Returns the instance of the class. More... | |
Private Member Functions | |
WebServer () | |
Constructor of the class. More... | |
WebServer (WebServer const &) | |
Copy constructor of the class. More... | |
WebServer & | operator= (WebServer const &) |
Assignment operator of the class. More... | |
const String | replaceHTMLWithData (String html) const |
Inserts a piece of data into a line of the HTML content. More... | |
int | setEthernet () |
Sets up the ethernet shield. More... | |
void | saveSettings () |
Saves settings on the SD card. More... | |
int | processHTTPRequest (String &httpRequest) |
Processes an HTTP request. More... | |
int | processHTTPRequestSettings (int startPos, String &httpRequest, int numberOfValues) |
Processes an HTTP request for changing settings of the water leak detection algorithms. More... | |
Private Attributes | |
std::vector< HTMLDataSource * > | htmlDataSources |
collection of classing providing data for the HTML content More... | |
byte | mac [6] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 } |
MAC address of the Ethernet shield. More... | |
EthernetServer | server = 80 |
instance of EthernetServer listening on port 80 More... | |
File | webFile |
file More... | |
String | buff |
buffer for parsing an HTTP request More... | |
LeaksController * | leaksController |
instance of LeaksController so it can be updated with each line read off the file More... | |
bool | online |
flag if the server is up and running More... | |
Static Private Attributes | |
static WebServer * | instance = NULL |
the instance of the class More... | |
This class implements the functionality of the webserver. This includes loading the content of the website off the SD card, accepting and validating HTTP requests, etc.
Definition at line 34 of file WebServer.h.
|
private |
Constructor of the class.
Definition at line 5 of file WebServer.cpp.
References online.
Referenced by getInstance().
|
inlineprivate |
void WebServer::addHTMLSource | ( | HTMLDataSource * | source | ) |
Adds another source of data for the HTML content.
source | another class to be added to the collection |
Definition at line 90 of file WebServer.cpp.
References htmlDataSources.
Referenced by setup().
|
static |
Returns the instance of the class.
If the instance has not been created, it will create it and then return it.
Definition at line 9 of file WebServer.cpp.
References instance, and WebServer().
Referenced by setup().
|
private |
Processes an HTTP request.
It will determinate what kind of HTTP request has been sent and validates it afterwards. It the HTTP request does not have the right syntax, it will ber discarded.
httpRequest | the HTTP request |
Definition at line 197 of file WebServer.cpp.
References LeaksController::getNumberOfLeakDetections(), HTTP_RQ_NOTIFICATION, HTTP_RQ_SETTINGS, leaksController, processHTTPRequestSettings(), and saveSettings().
Referenced by update().
|
private |
Processes an HTTP request for changing settings of the water leak detection algorithms.
startPos | start position (index) of the data within the HTTP request |
httpRequest | the HTTP request itself |
numberOfValues | number of expected parameters in the HTTP request |
Definition at line 309 of file WebServer.cpp.
References LeaksController::changeSettings(), ALeakDetectable::High, HTTP_RQ_SEPARATOR, HTTP_RQ_SETTINGS, leaksController, LITER_TO_PULSE, ALeakDetectable::Low, OUT_OF_RANGE_ERR, and ALeakDetectable::Total.
Referenced by processHTTPRequest().
|
private |
Inserts a piece of data into a line of the HTML content.
If the line contains a sequence begining with "%*" and ending with "*%". For example, "%*150*%". It will replace it with the appropriate data according to the id, 150.
html | the current line being read off the SD card |
Definition at line 359 of file WebServer.cpp.
References DATA_POST, DATA_PREF, htmlDataSources, and HTMLDataSource::UNDEFINED_DATA.
Referenced by update().
|
private |
Saves settings on the SD card.
This method is called when new settings are applied or when the user changes the receiver's e-mail address.
Definition at line 236 of file WebServer.cpp.
References BACKUP_SETTINGS_FILE_NAME, EmailSender::getFormatOfSettingsToSave(), LeaksController::getFormatOfSettingsToSave(), EmailSender::getInstance(), leaksController, and SETTINGS_FILE_NAME.
Referenced by processHTTPRequest().
|
private |
Sets up the ethernet shield.
Definition at line 15 of file WebServer.cpp.
References mac, SS_ETHERNET, and SS_SD_CARD.
Referenced by setup().
void WebServer::setup | ( | LeaksController * | leaksController | ) |
Sets the pointer to an instance of LeaksController.
The purpose of this to keep updating the "low-level" part of the system as frequently as possible regardless of the webpage being loaded off the SD card.
leaksController | instance of LeaksController |
Definition at line 41 of file WebServer.cpp.
References INDEX_FILE_NAME, leaksController, online, server, setEthernet(), and SS_SD_CARD.
Referenced by setup().
|
overridevirtual |
Updates the class.
Implements IControllable.
Definition at line 94 of file WebServer.cpp.
References buff, HTTP_RQ_GET_START, INDEX_FILE_NAME, leaksController, MAX_HTTP_RQ_LENGTH, online, processHTTPRequest(), replaceHTMLWithData(), server, SS_ETHERNET, SS_SD_CARD, LeaksController::update(), and webFile.
|
private |
buffer for parsing an HTTP request
Definition at line 43 of file WebServer.h.
Referenced by update().
|
private |
collection of classing providing data for the HTML content
Definition at line 39 of file WebServer.h.
Referenced by addHTMLSource(), and replaceHTMLWithData().
|
staticprivate |
|
private |
instance of LeaksController so it can be updated with each line read off the file
Definition at line 44 of file WebServer.h.
Referenced by processHTTPRequest(), processHTTPRequestSettings(), saveSettings(), setup(), and update().
|
private |
MAC address of the Ethernet shield.
Definition at line 40 of file WebServer.h.
Referenced by setEthernet().
|
private |
flag if the server is up and running
Definition at line 45 of file WebServer.h.
Referenced by setup(), update(), and WebServer().
|
private |
instance of EthernetServer listening on port 80
Definition at line 41 of file WebServer.h.
|
private |