/*
General Purpose Webserver adjusted for Olimex ESP32-PoE board.
It can control Olimex module MOD-IO.
This sketch requires Arduino for ESP32 - how to install it read here: https://github.com/espressif/arduino-esp32
This project is based on the one created by David Bird. The original can be found and downloaded here: https://github.com/G6EJD/ESP32-General-Purpose-Webserver
The MIT License (MIT) Copyright (c) 2017 by David Bird.
### The formulation and calculation method of an IAQ - Internal Air Quality index ###
### The provision of a general purpose webserver ###
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, but not to use it commercially for profit making or to sub-license and/or to sell copies of the Software or to
permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
See more at http://dsbird.org.uk
*/
//################# LIBRARIES ################
#include
"; append_HTML_footer(); server.send(200, "text/html", webpage); // Send a response to the client to enter their inputs, if needed, Enter=defaults if (server.args() > 0 ) { // Arguments were received for ( uint8_t i = 0; i < server.args(); i++ ) { static int Temp=0, RelayValue = 0; String Argument_Name = server.argName(i); String client_response = server.arg(i); if (Argument_Name == "MOD_IO_CheckBox") { MOD_IO_CheckBoxChoice = client_response; // Checking for more than one check-box being selected too, 'a' if more than one Temp = MOD_IO_CheckBoxChoice.toInt () - 1; // SPP RelayValue = RelayValue | (1 << Temp); Serial.println (RelayValue); MOD_IO_SetRelay (RelayValue); } if (Argument_Name == "MOD_IO_Relay") { Serial.print ("Value: "); Serial.println (RelayValue); MOD_IO_SetRelay (RelayValue); RelayValue = 0; } } } } void StartWiFi(const char* ssid, const char* password) { int connAttempts = 0; Serial.print(F("\r\nConnecting to: ")); Serial.println(String(ssid)); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED ) { delay(500); Serial.print("."); if (connAttempts > 20) { Serial.println("Failed to connect to WiFi"); } connAttempts++; } Serial.print(F("WiFi connected at: ")); Serial.println(WiFi.localIP()); } void StartTime() { configTime(0, 0, "0.uk.pool.ntp.org", "time.nist.gov"); setenv("TZ", "GMT0BST,M3.5.0/01,M10.5.0/02", 1); // Set for your locale delay(200); GetTime(); } String GetTime() { struct tm timeinfo; while (!getLocalTime(&timeinfo)) { Serial.println("Failed to obtain time"); StartTime(); } //See http://www.cplusplus.com/reference/ctime/strftime/ //Serial.println(&timeinfo, "%a %b %d %Y %H:%M:%S"); // Displays: Saturday, June 24 2017 14:05:49 char output[50]; strftime(output, 50, "%d/%m/%y %H:%M:%S", &timeinfo); // Format needed for Google Charts is "11/12/17 22:01:00"; //dd/mm/yy hh:hh:ss return output; } void append_HTML_header() { webpage = ""; webpage += "
"; webpage += ""; // 5-min refresh time, test needed to prevent auto updates repeating some commands webpage += ""; webpage += "