diff --git a/esp3d/bridge.cpp b/esp3d/bridge.cpp
deleted file mode 100644
index 58d6d34d..00000000
--- a/esp3d/bridge.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- bridge.cpp - esp3d bridge serial/tcp class
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include "config.h"
-#include "bridge.h"
-#include "command.h"
-#include "webinterface.h"
-
-#ifdef TCP_IP_DATA_FEATURE
-WiFiServer * data_server;
-WiFiClient serverClients[MAX_SRV_CLIENTS];
-#endif
-
-bool BRIDGE::header_sent = false;
-String BRIDGE::buffer_web = "";
-void BRIDGE::print (const __FlashStringHelper *data, tpipe output)
-{
- String tmp = data;
- BRIDGE::print(tmp.c_str(), output);
-}
-void BRIDGE::print (String & data, tpipe output)
-{
- BRIDGE::print(data.c_str(), output);
-}
-void BRIDGE::print (const char * data, tpipe output)
-{
- switch(output) {
- case SERIAL_PIPE:
- header_sent = false;
- ESP_SERIAL_OUT.print(data);
- break;
-#ifdef TCP_IP_DATA_FEATURE
- case TCP_PIPE:
- header_sent = false;
- BRIDGE::send2TCP(data);
- break;
-#endif
- case WEB_PIPE:
- if (!header_sent) {
- web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
- web_interface->web_server.sendHeader("Content-Type","text/html");
- web_interface->web_server.sendHeader("Cache-Control","no-cache");
- web_interface->web_server.send(200);
- header_sent = true;
- }
- buffer_web+=data;
- if (buffer_web.length() > 1200) {
- //send data
- web_interface->web_server.sendContent(buffer_web);
- //reset buffer
- buffer_web="";
- }
- break;
- default:
- break;
- }
-}
-void BRIDGE::println (const __FlashStringHelper *data, tpipe output)
-{
- BRIDGE::print(data,output);
-#ifdef TCP_IP_DATA_FEATURE
- BRIDGE::print("\r",output);
-#endif
- BRIDGE::print("\n",output);
-}
-void BRIDGE::println (String & data, tpipe output)
-{
- BRIDGE::print(data,output);
-#ifdef TCP_IP_DATA_FEATURE
- BRIDGE::print("\r",output);
-#endif
- BRIDGE::print("\n",output);
-}
-void BRIDGE::println (const char * data, tpipe output)
-{
- BRIDGE::print(data,output);
-#ifdef TCP_IP_DATA_FEATURE
- BRIDGE::print("\r",output);
-#endif
- BRIDGE::print("\n",output);
-}
-void BRIDGE::flush (tpipe output)
-{
- switch(output) {
- case SERIAL_PIPE:
- ESP_SERIAL_OUT.flush();
- break;
-#ifdef TCP_IP_DATA_FEATURE
- case TCP_PIPE:
- break;
-#endif
- case WEB_PIPE:
- if(header_sent) {
- //send data
- web_interface->web_server.sendContent(buffer_web);
- //close line
- web_interface->web_server.sendContent("");
- }
- break;
- default:
- break;
- }
- header_sent = false;
- buffer_web = String();
-}
-
-
-#ifdef TCP_IP_DATA_FEATURE
-void BRIDGE::send2TCP(const __FlashStringHelper *data)
-{
- String tmp = data;
- BRIDGE::send2TCP(tmp.c_str());
-}
-void BRIDGE::send2TCP(String data)
-{
- BRIDGE::send2TCP(data.c_str());
-}
-void BRIDGE::send2TCP(const char * data)
-{
- for(uint8_t i = 0; i < MAX_SRV_CLIENTS; i++) {
- if (serverClients[i] && serverClients[i].connected()) {
- serverClients[i].write(data, strlen(data));
- delay(0);
- }
- }
-}
-#endif
-
-bool BRIDGE::processFromSerial2TCP()
-{
- uint8_t i;
- //check UART for data
- if(ESP_SERIAL_OUT.available()) {
- size_t len = ESP_SERIAL_OUT.available();
- uint8_t sbuf[len];
- ESP_SERIAL_OUT.readBytes(sbuf, len);
-#ifdef TCP_IP_DATA_FEATURE
- if (WiFi.getMode()!=WIFI_OFF ) {
- //push UART data to all connected tcp clients
- for(i = 0; i < MAX_SRV_CLIENTS; i++) {
- if (serverClients[i] && serverClients[i].connected()) {
- serverClients[i].write(sbuf, len);
- delay(0);
- }
- }
- }
-#endif
- //process data if any
- COMMAND::read_buffer_serial(sbuf, len);
- return true;
- } else {
- return false;
- }
-}
-#ifdef TCP_IP_DATA_FEATURE
-void BRIDGE::processFromTCP2Serial()
-{
- uint8_t i,data;
- //check if there are any new clients
- if (data_server->hasClient()) {
- for(i = 0; i < MAX_SRV_CLIENTS; i++) {
- //find free/disconnected spot
- if (!serverClients[i] || !serverClients[i].connected()) {
- if(serverClients[i]) {
- serverClients[i].stop();
- }
- serverClients[i] = data_server->available();
- continue;
- }
- }
- //no free/disconnected spot so reject
- WiFiClient serverClient = data_server->available();
- serverClient.stop();
- }
- //check clients for data
- //to avoid any pollution if Uploading file to SDCard
- if ((web_interface->blockserial) == false) {
- for(i = 0; i < MAX_SRV_CLIENTS; i++) {
- if (serverClients[i] && serverClients[i].connected()) {
- if(serverClients[i].available()) {
- //get data from the tcp client and push it to the UART
- while(serverClients[i].available()) {
- data = serverClients[i].read();
- ESP_SERIAL_OUT.write(data);
- COMMAND::read_buffer_tcp(data);
- }
- }
- }
- }
- }
-}
-#endif
diff --git a/esp3d/bridge.h b/esp3d/bridge.h
deleted file mode 100644
index 6bff0f8f..00000000
--- a/esp3d/bridge.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- bridge.h - esp3d bridge serial/tcp class
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#ifndef BRIDGE_H
-#define BRIDGE_H
-#include
-#include "config.h"
-#ifdef TCP_IP_DATA_FEATURE
-extern WiFiServer * data_server;
-#endif
-
-class BRIDGE
-{
-public:
- static bool header_sent;
- static String buffer_web;
- static bool processFromSerial2TCP();
- static void print (const __FlashStringHelper *data, tpipe output);
- static void print (String & data, tpipe output);
- static void print (const char * data, tpipe output);
- static void println (const __FlashStringHelper *data, tpipe output);
- static void println (String & data, tpipe output);
- static void println (const char * data, tpipe output);
- static void flush (tpipe output);
-#ifdef TCP_IP_DATA_FEATURE
- static void processFromTCP2Serial();
- static void send2TCP(const __FlashStringHelper *data);
- static void send2TCP(String data);
- static void send2TCP(const char * data);
-#endif
-};
-#endif
diff --git a/esp3d/command.cpp b/esp3d/command.cpp
deleted file mode 100644
index 9b86fe72..00000000
--- a/esp3d/command.cpp
+++ /dev/null
@@ -1,1600 +0,0 @@
-/*
- command.cpp - ESP3D configuration class
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-#include "config.h"
-#include "command.h"
-#include "wificonf.h"
-#include "webinterface.h"
-#ifndef FS_NO_GLOBALS
-#define FS_NO_GLOBALS
-#endif
-#include
-#if defined(ARDUINO_ARCH_ESP32)
-#include "SPIFFS.h"
-#define MAX_GPIO 16
-#else
-#define MAX_GPIO 37
-#endif
-String COMMAND::buffer_serial;
-String COMMAND::buffer_tcp;
-
-#define ERROR_CMD_MSG (output == WEB_PIPE)?F("Error: Wrong Command"):F("M117 Cmd Error")
-#define INCORRECT_CMD_MSG (output == WEB_PIPE)?F("Error: Incorrect Command"):F("M117 Incorrect Cmd")
-#define OK_CMD_MSG (output == WEB_PIPE)?F("ok"):F("M117 Cmd Ok")
-
-String COMMAND::get_param(String & cmd_params, const char * id, bool withspace)
-{
- static String parameter;
- String sid=id;
- int start;
- int end = -1;
- parameter = "";
- //if no id it means it is first part of cmd
- if (strlen(id) == 0) {
- start = 0;
- }
- //else find id position
- else {
- start = cmd_params.indexOf(id);
- }
- //if no id found and not first part leave
- if (start == -1 ) {
- return parameter;
- }
- //password and SSID can have space so handle it
- //if no space expected use space as delimiter
- if (!withspace) {
- end = cmd_params.indexOf(" ",start);
- }
-#ifdef AUTHENTICATION_FEATURE
- //if space expected only one parameter but additional password may be present
- else if (sid != " pwd=") {
- end = cmd_params.indexOf(" pwd=",start);
- }
-#endif
- //if no end found - take all
- if (end == -1) {
- end = cmd_params.length();
- }
- //extract parameter
- parameter = cmd_params.substring(start+strlen(id),end);
- //be sure no extra space
- parameter.trim();
- return parameter;
-}
-#ifdef AUTHENTICATION_FEATURE
-//check admin password
-bool COMMAND::isadmin(String & cmd_params)
-{
- String adminpassword;
- String sadminPassword;
- if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword, MAX_LOCAL_PASSWORD_LENGTH)) {
- LOG("ERROR getting admin\r\n")
- sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
- }
- adminpassword = get_param(cmd_params,"pwd=", true);
- if (!sadminPassword.equals(adminpassword)) {
- LOG("Not identified from command line\r\n")
- return false;
- } else {
- return true;
- }
-}
-//check user password - admin password is also valid
-bool COMMAND::isuser(String & cmd_params)
-{
- String userpassword;
- String suserPassword;
- if (!CONFIG::read_string(EP_USER_PWD, suserPassword, MAX_LOCAL_PASSWORD_LENGTH)) {
- LOG("ERROR getting user\r\n")
- suserPassword=FPSTR(DEFAULT_USER_PWD);
- }
- userpassword = get_param(cmd_params,"pwd=", true);
- //it is not user password
- if (!suserPassword.equals(userpassword)) {
- //check admin password
- return COMMAND::isadmin(cmd_params);
- } else {
- return true;
- }
-}
-#endif
-bool COMMAND::execute_command(int cmd,String cmd_params, tpipe output, level_authenticate_type auth_level)
-{
- bool response = true;
- level_authenticate_type auth_type = auth_level;
-#ifdef AUTHENTICATION_FEATURE
- if (isadmin(cmd_params)) {
- auth_type = LEVEL_ADMIN;
- LOG("admin identified\r\n");
- }
- if (isuser(cmd_params) && (auth_type != LEVEL_ADMIN)) {
- auth_type = LEVEL_USER;
- LOG("user identified\r\n");
- }
-#ifdef DEBUG_ESP3D
- if ( auth_type == LEVEL_ADMIN)
- {
- LOG("admin identified\r\n");
- }
- else {
- if( auth_type == LEVEL_USER)
- {
- LOG("user identified\r\n");
- }
- else
- {
- LOG("guest identified\r\n");
- }
- }
-#endif
-#endif
- //manage parameters
- byte mode = 254;
- String parameter;
- LOG("Execute Command\r\n")
- switch(cmd) {
- //STA SSID
- //[ESP100][pwd=]
- case 100:
- parameter = get_param(cmd_params,"", true);
- if (!CONFIG::isSSIDValid(parameter.c_str())) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- }
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- } else
-#endif
- if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- break;
- //STA Password
- //[ESP101][pwd=]
- case 101:
- parameter = get_param(cmd_params,"", true);
- if (!CONFIG::isPasswordValid(parameter.c_str())) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- break;
- //Hostname
- //[ESP102][pwd=]
- case 102:
- parameter = get_param(cmd_params,"", true);
- if (!CONFIG::isHostnameValid(parameter.c_str())) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- break;
- //Wifi mode (STA/AP)
- //[ESP103][pwd=]
- case 103:
- parameter = get_param(cmd_params,"", true);
- if (parameter == "STA") {
- mode = CLIENT_MODE;
- } else if (parameter == "AP") {
- mode = AP_MODE;
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- if ((mode == CLIENT_MODE) || (mode == AP_MODE)) {
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- }
- break;
- //STA IP mode (DHCP/STATIC)
- //[ESP104][pwd=]
- case 104:
- parameter = get_param(cmd_params,"", true);
- if (parameter == "STATIC") {
- mode = STATIC_IP_MODE;
- } else if (parameter == "DHCP") {
- mode = DHCP_MODE;
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) {
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- }
- break;
- //AP SSID
- //[ESP105][pwd=]
- case 105:
- parameter = get_param(cmd_params,"", true);
- if (!CONFIG::isSSIDValid(parameter.c_str())) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- if(!CONFIG::write_string(EP_AP_SSID,parameter.c_str())) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- break;
- //AP Password
- //[ESP106][pwd=]
- case 106:
- parameter = get_param(cmd_params,"", true);
- if (!CONFIG::isPasswordValid(parameter.c_str())) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- break;
- //AP IP mode (DHCP/STATIC)
- //[ESP107][pwd=]
- case 107:
- parameter = get_param(cmd_params,"", true);
- if (parameter == "STATIC") {
- mode = STATIC_IP_MODE;
- } else if (parameter == "DHCP") {
- mode = DHCP_MODE;
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) {
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- }
- break;
- // Set wifi on/off
- //[ESP110][pwd=]
- case 110:
- parameter = get_param(cmd_params,"", true);
- if (parameter == "on") {
- mode = 1;
- } else if (parameter == "off") {
- mode = 0;
- } else if (parameter == "restart") {
- mode = 2;
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- if (response) {
- #ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
- #endif
- if (mode == 0) {
- if (WiFi.getMode() !=WIFI_OFF) {
- //disable wifi
- ESP_SERIAL_OUT.println("M117 Disabling Wifi");
- WiFi.mode(WIFI_OFF);
- wifi_config.Disable_servers();
- return response;
- } else BRIDGE::println("M117 Wifi already off", output);
- }
- else if (mode == 1) { //restart device is the best way to start everything clean
- if (WiFi.getMode() == WIFI_OFF) {
- ESP_SERIAL_OUT.println("M117 Enabling Wifi");
- CONFIG::esp_restart();
- } else BRIDGE::println("M117 Wifi already on", output);
- } else { //restart wifi and restart is the best way to start everything clean
- ESP_SERIAL_OUT.println("M117 Enabling Wifi");
- CONFIG::esp_restart();
- }
- }
- break;
- //Get current IP
- //[ESP111]
- case 111: {
- String currentIP ;
- if (WiFi.getMode()==WIFI_STA) {
- currentIP=WiFi.localIP().toString();
- } else {
- currentIP=WiFi.softAPIP().toString();
- }
- BRIDGE::print(cmd_params, output);
- BRIDGE::println(currentIP, output);
- LOG(cmd_params)
- LOG(currentIP)
- LOG("\r\n")
- }
- break;
- //Get hostname
- //[ESP112]
- case 112: {
- String shost ;
- if (!CONFIG::read_string(EP_HOSTNAME, shost, MAX_HOSTNAME_LENGTH)) {
- shost=wifi_config.get_default_hostname();
- }
- BRIDGE::print(cmd_params, output);
- BRIDGE::println(shost, output);
- LOG(cmd_params)
- LOG(shost)
- LOG("\r\n")
- }
- break;
-#ifdef DIRECT_PIN_FEATURE
- //Get/Set pin value
- //[ESP201]P V [PULLUP=YES RAW=YES]pwd=
- case 201:
- parameter = get_param(cmd_params,"", true);
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type == LEVEL_GUEST) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- {
- //check if have pin
- parameter = get_param(cmd_params,"P", false);
- LOG("Pin:")
- LOG(parameter)
- LOG("\r\n")
- if (parameter == "") {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else {
- int pin = parameter.toInt();
- //check pin is valid and not serial used pins
- if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) {
- //check if is set or get
- parameter = get_param(cmd_params,"V", false);
- //it is a get
- if (parameter == "") {
- //this is to not set pin mode
- parameter = get_param(cmd_params,"RAW=", false);
- if (parameter !="YES") {
- parameter = get_param(cmd_params,"PULLUP=", false);
- if (parameter == "YES") {
- //GPIO16 is different than others
- if (pin < MAX_GPIO) {
- LOG("Set as input pull up\r\n")
- pinMode(pin, INPUT_PULLUP);
- }
-#ifdef ARDUINO_ARCH_ESP8266
- else {
- LOG("Set as input pull down 16\r\n")
- pinMode(pin, INPUT_PULLDOWN_16);
- }
-#endif
- } else {
- LOG("Set as input\r\n")
- pinMode(pin, INPUT);
- }
- delay(100);
- }
- int value = digitalRead(pin);
- LOG("Read:");
- LOG(String(value).c_str())
- LOG("\n");
- BRIDGE::println(String(value).c_str(), output);
- } else {
- //it is a set
- int value = parameter.toInt();
- //verify it is a 0 or a 1
- if ((value == 0) || (value == 1)) {
- pinMode(pin, OUTPUT);
- delay(10);
- LOG("Set:")
- LOG(String((value == 0)?LOW:HIGH))
- LOG("\r\n")
- digitalWrite(pin, (value == 0)?LOW:HIGH);
- BRIDGE::println(OK_CMD_MSG, output);
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- }
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- }
- }
- break;
-#endif
-
- //Save data string
- //[ESP300]pwd=
- case 300:
- parameter = get_param(cmd_params,"", true);
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type == LEVEL_GUEST) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- {
- if(!CONFIG::write_string(EP_DATA_STRING,parameter.c_str())) {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
- }
- break;
- //get data string
- //[ESP301] pwd=
- case 301:
- parameter = get_param(cmd_params,"", true);
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type == LEVEL_GUEST) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- {
- char sbuf[MAX_DATA_LENGTH+1];
- if (CONFIG::read_string(EP_DATA_STRING, sbuf, MAX_DATA_LENGTH)) {
- BRIDGE::println(sbuf, output);
- } else {
- BRIDGE::println(F("Error reading data"), output);
- }
- }
- break;
- //Get full EEPROM settings content
- //[ESP400]
- case 400: {
- char sbuf[MAX_DATA_LENGTH+1];
- uint8_t ipbuf[4];
- byte bbuf=0;
- int ibuf=0;
- parameter = get_param(cmd_params,"", true);
- delay(0);
- //Start JSON
- BRIDGE::println(F("{\"EEPROM\":["), output);
- if (cmd_params == "network" || cmd_params == "") {
-
- //1- Baud Rate
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_BAUD_RATE), output);
- BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf, INTEGER_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Baud Rate\",\"O\":[{\"9600\":\"9600\"},{\"19200\":\"19200\"},{\"38400\":\"38400\"},{\"57600\":\"57600\"},{\"115200\":\"115200\"},{\"230400\":\"230400\"},{\"250000\":\"250000\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //2-Sleep Mode
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_SLEEP_MODE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_SLEEP_MODE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Sleep Mode\",\"O\":[{\"None\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_NONE_SLEEP), output);
-#ifdef ARDUINO_ARCH_ESP8266
- BRIDGE::print(F("\"},{\"Light\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_LIGHT_SLEEP), output);
-#endif
- BRIDGE::print(F("\"},{\"Modem\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_MODEM_SLEEP), output);
- BRIDGE::print(F("\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //3-Web Port
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_WEB_PORT), output);
- BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&ibuf, INTEGER_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Web Port\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_WEB_PORT), output);
- BRIDGE::print(F("\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_WEB_PORT), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //4-Data Port
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_DATA_PORT), output);
- BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_DATA_PORT, (byte *)&ibuf, INTEGER_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Data Port\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_DATA_PORT), output);
- BRIDGE::print(F("\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_DATA_PORT), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-#ifdef AUTHENTICATION_FEATURE
- //5-Admin password
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_ADMIN_PWD), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_ADMIN_PWD, sbuf, MAX_LOCAL_PASSWORD_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print("********", output);
- }
- BRIDGE::print(F("\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_LOCAL_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\",\"H\":\"Admin Password\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_LOCAL_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //6-User password
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_USER_PWD), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_USER_PWD, sbuf, MAX_LOCAL_PASSWORD_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print("********", output);
- }
- BRIDGE::print(F("\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_LOCAL_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\",\"H\":\"User Password\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_LOCAL_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-#endif
- //7-Hostname
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_HOSTNAME), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_HOSTNAME, sbuf, MAX_HOSTNAME_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(sbuf, output);
- }
- BRIDGE::print(F("\",\"H\":\"Hostname\" ,\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_HOSTNAME_LENGTH), output);
- BRIDGE::print(F("\", \"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_HOSTNAME_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //8-wifi mode
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_WIFI_MODE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Wifi mode\",\"O\":[{\"AP\":\"1\"},{\"STA\":\"2\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //9-STA SSID
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_SSID), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_STA_SSID, sbuf, MAX_SSID_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(sbuf, output);
- }
- BRIDGE::print(F("\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_SSID_LENGTH), output);
- BRIDGE::print(F("\",\"H\":\"Station SSID\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_SSID_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //10-STA password
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_PASSWORD), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_STA_PASSWORD, sbuf, MAX_PASSWORD_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print("********", output);
- }
- BRIDGE::print(F("\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\",\"H\":\"Station Password\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //11-Station Network Mode
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_PHY_MODE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_STA_PHY_MODE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Station Network Mode\",\"O\":[{\"11b\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11B), output);
- BRIDGE::print(F("\"},{\"11g\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11G), output);
- BRIDGE::print(F("\"},{\"11n\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11N), output);
- BRIDGE::print(F("\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //12-STA IP mode
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_IP_MODE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Station IP Mode\",\"O\":[{\"DHCP\":\"1\"},{\"Static\":\"2\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //13-STA static IP
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_IP_VALUE), output);
- BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_STA_IP_VALUE,(byte *)ipbuf, IP_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output);
- }
- BRIDGE::print(F("\",\"H\":\"Station Static IP\"}"), output);
- BRIDGE::println(F(","), output);
-
- //14-STA static Mask
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_MASK_VALUE), output);
- BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_STA_MASK_VALUE,(byte *)ipbuf, IP_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output);
- }
- BRIDGE::print(F("\",\"H\":\"Station Static Mask\"}"), output);
- BRIDGE::println(F(","), output);
-
- //15-STA static Gateway
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_GATEWAY_VALUE), output);
- BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_STA_GATEWAY_VALUE,(byte *)ipbuf, IP_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output);
- }
- BRIDGE::print(F("\",\"H\":\"Station Static Gateway\"}"), output);
- BRIDGE::println(F(","), output);
-
- //16-AP SSID
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_SSID), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_AP_SSID, sbuf, MAX_SSID_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(sbuf, output);
- }
- BRIDGE::print(F("\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_SSID_LENGTH), output);
- BRIDGE::print(F("\",\"H\":\"AP SSID\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_SSID_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //17-AP password
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_PASSWORD), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_AP_PASSWORD, sbuf, MAX_PASSWORD_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print("********", output);
- }
- BRIDGE::print(F("\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\",\"H\":\"AP Password\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_PASSWORD_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //18 - AP Network Mode
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_PHY_MODE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_AP_PHY_MODE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"AP Network Mode\",\"O\":[{\"11b\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11B), output);
- BRIDGE::print(F("\"},{\"11g\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11G), output);
- BRIDGE::print(F("\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //19-AP SSID visibility
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_SSID_VISIBLE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_SSID_VISIBLE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"SSID Visible\",\"O\":[{\"No\":\"0\"},{\"Yes\":\"1\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //20-AP Channel
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_CHANNEL), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_CHANNEL, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"AP Channel\",\"O\":["), output);
- for (int i=1; i < 12 ; i++) {
- BRIDGE::print(F("{\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(i), output);
- BRIDGE::print(F("\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(i), output);
- BRIDGE::print(F("\"}"), output);
- if (i<11) {
- BRIDGE::print(F(","), output);
- }
- }
- BRIDGE::print(F("]}"), output);
- BRIDGE::println(F(","), output);
-
- //21-AP Authentication
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AUTH_TYPE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_AUTH_TYPE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Authentication\",\"O\":[{\"Open\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(AUTH_OPEN), output);
- BRIDGE::print(F("\"},{\"WPA\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(AUTH_WPA_PSK), output);
- BRIDGE::print(F("\"},{\"WPA2\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(AUTH_WPA2_PSK), output);
- BRIDGE::print(F("\"},{\"WPA/WPA2\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(AUTH_WPA_WPA2_PSK), output);
- BRIDGE::print(F("\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //22-AP IP mode
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_IP_MODE), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_AP_IP_MODE, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"AP IP Mode\",\"O\":[{\"DHCP\":\"1\"},{\"Static\":\"2\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //23-AP static IP
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_IP_VALUE), output);
- BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_AP_IP_VALUE,(byte *)ipbuf, IP_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output);
- }
- BRIDGE::print(F("\",\"H\":\"AP Static IP\"}"), output);
- BRIDGE::println(F(","), output);
-
- //24-AP static Mask
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_MASK_VALUE), output);
- BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,(byte *)ipbuf, IP_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output);
- }
- BRIDGE::print(F("\",\"H\":\"AP Static Mask\"}"), output);
- BRIDGE::println(F(","), output);
-
- //25-AP static Gateway
- BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_GATEWAY_VALUE), output);
- BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,(byte *)ipbuf, IP_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output);
- }
- BRIDGE::print(F("\",\"H\":\"AP Static Gateway\"}"), output);
- delay(0);
- }
-
- if (cmd_params == "printer" || cmd_params == "") {
- if (cmd_params == "") {
- BRIDGE::println(F(","), output);
- }
- //Target FW
- BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_TARGET_FW), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_TARGET_FW, &bbuf )) {
- BRIDGE::print("Unknown", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Target FW\",\"O\":[{\"Repetier\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(REPETIER), output);
- BRIDGE::print(F("\"},{\"Repetier for Davinci\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(REPETIER4DV), output);
- BRIDGE::print(F("\"},{\"Marlin\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MARLIN), output);
- BRIDGE::print(F("\"},{\"Marlin Kimbra\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MARLINKIMBRA), output);
- BRIDGE::print(F("\"},{\"Smoothieware\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(SMOOTHIEWARE), output);
- BRIDGE::print(F("\"},{\"Unknown\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(UNKNOWN_FW), output);
- BRIDGE::print(F("\"}]}"), output);
- BRIDGE::println(F(","), output);
-
- //Refresh time 1
- BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_REFRESH_PAGE_TIME), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_REFRESH_PAGE_TIME, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Temperature Refresh Time\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_REFRESH), output);
- BRIDGE::print(F("\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_REFRESH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //Refresh time 2
- BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_REFRESH_PAGE_TIME2), output);
- BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output);
- if (!CONFIG::read_byte(EP_REFRESH_PAGE_TIME2, &bbuf )) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Position Refresh Time\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_REFRESH), output);
- BRIDGE::print(F("\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_REFRESH), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //XY feedrate
- BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_XY_FEEDRATE), output);
- BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_XY_FEEDRATE, (byte *)&ibuf, INTEGER_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"XY feedrate\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_XY_FEEDRATE), output);
- BRIDGE::print(F("\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_XY_FEEDRATE), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //Z feedrate
- BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_Z_FEEDRATE), output);
- BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_Z_FEEDRATE, (byte *)&ibuf, INTEGER_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"Z feedrate\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_Z_FEEDRATE), output);
- BRIDGE::print(F("\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_Z_FEEDRATE), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //E feedrate
- BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_E_FEEDRATE), output);
- BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output);
- if (!CONFIG::read_buffer(EP_E_FEEDRATE, (byte *)&ibuf, INTEGER_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output);
- }
- BRIDGE::print(F("\",\"H\":\"E feedrate\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_E_FEEDRATE), output);
- BRIDGE::print(F("\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_E_FEEDRATE), output);
- BRIDGE::print(F("\"}"), output);
- BRIDGE::println(F(","), output);
-
- //Camera address, data string
- BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(EP_DATA_STRING), output);
- BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output);
- if (!CONFIG::read_string(EP_DATA_STRING, sbuf, MAX_DATA_LENGTH)) {
- BRIDGE::print("???", output);
- } else {
- BRIDGE::print(sbuf, output);
- }
- BRIDGE::print(F("\",\"S\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MAX_DATA_LENGTH), output);
- BRIDGE::print(F("\",\"H\":\"Camera address\",\"M\":\""), output);
- BRIDGE::print((const char *)CONFIG::intTostr(MIN_DATA_LENGTH), output);
- BRIDGE::print(F("\"}"), output);
- }
-
- //end JSON
- BRIDGE::println(F("\n]}"), output);
- delay(0);
- }
- break;
-
- //Set EEPROM setting
- //[ESP401]P= T= V= pwd=
- case 401: {
- //check validity of parameters
- String spos = get_param(cmd_params,"P=", false);
- String styp = get_param(cmd_params,"T=", false);
- String sval = get_param(cmd_params,"V=", true);
- sval.trim();
- int pos = spos.toInt();
- if ((pos == 0 && spos != "0") || (pos > LAST_EEPROM_ADDRESS || pos < 0)) {
- response = false;
- }
- if (!(styp == "B" || styp == "S" || styp == "A" || styp == "I")) {
- response = false;
- }
- if (sval.length() == 0) {
- response = false;
- }
-
-
-#ifdef AUTHENTICATION_FEATURE
- if (response) {
- //check authentication
- level_authenticate_type auth_need = LEVEL_ADMIN;
- for (int i = 0; i < AUTH_ENTRY_NB; i++) {
- if (Setting[i][0] == pos ) {
- auth_need = (level_authenticate_type)(Setting[i][1]);
- i = AUTH_ENTRY_NB;
- }
- }
- if ((auth_need == LEVEL_ADMIN && auth_type == LEVEL_USER) || (auth_type == LEVEL_GUEST)) {
- response = false;
- }
- }
-#endif
- if (response) {
- if (styp == "B") {
- byte bbuf = sval.toInt();
- if(!CONFIG::write_byte(pos,bbuf)) {
- response = false;
- } else {
- //dynamique refresh is better than restart the board
- if (pos == EP_TARGET_FW)CONFIG::InitFirmwareTarget();
- if (pos == EP_IS_DIRECT_SD){
- CONFIG::InitDirectSD();
- if (CONFIG::is_direct_sd) CONFIG::InitPins();
- }
- }
- }
- if (styp == "I") {
- int ibuf = sval.toInt();
- if(!CONFIG::write_buffer(pos,(const byte *)&ibuf,INTEGER_LENGTH)) {
- response = false;
- }
- }
- if (styp == "S") {
- if(!CONFIG::write_string(pos,sval.c_str())) {
- response = false;
- }
- }
- if (styp == "A") {
- byte ipbuf[4];
- if (CONFIG::split_ip(sval.c_str(),ipbuf) < 4) {
- response = false;
- } else if(!CONFIG::write_buffer(pos,ipbuf,IP_LENGTH)) {
- response = false;
- }
- }
- }
- if(!response) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- } else {
- BRIDGE::println(OK_CMD_MSG, output);
- }
-
- }
- break;
-
- //Get available AP list (limited to 30)
- //output is JSON or plain text according parameter
- //[ESP410]
- case 410: {
- parameter = get_param(cmd_params,"", true);
- int n = WiFi.scanNetworks();
- bool plain = parameter == "plain";
- if (!plain)BRIDGE::print(F("{\"AP_LIST\":["), output);
- for (int i = 0; i < n; ++i) {
- if (i>0) {
- if (!plain) BRIDGE::print(F(","), output);
- else BRIDGE::print(F("\n"), output);
- }
- if (!plain)BRIDGE::print(F("{\"SSID\":\""), output);
- BRIDGE::print(WiFi.SSID(i).c_str(), output);
- if (!plain)BRIDGE::print(F("\",\"SIGNAL\":\""), output);
- else BRIDGE::print(F("\t"), output);
- BRIDGE::print(CONFIG::intTostr(wifi_config.getSignal(WiFi.RSSI(i))), output);;
- //BRIDGE::print(F("%"), output);
- if (!plain)BRIDGE::print(F("\",\"IS_PROTECTED\":\""), output);
- if (WiFi.encryptionType(i) == ENC_TYPE_NONE) {
- if (!plain)BRIDGE::print(F("0"), output);
- else BRIDGE::print(F("\tOpen"), output);
- } else {
- if (!plain)BRIDGE::print(F("1"), output);
- else BRIDGE::print(F("\tSecure"), output);
- }
- if (!plain)BRIDGE::print(F("\"}"), output);
- }
- if (!plain)BRIDGE::print(F("]}"), output);
- else BRIDGE::print(F("\n"), output);
- WiFi.scanDelete();
- }
- break;
- //Get ESP current status in plain or JSON
- //[ESP420]
- case 420: {
- parameter = get_param(cmd_params,"", true);
- CONFIG::print_config(output, (parameter == "plain"));
- }
- break;
- //Set ESP mode
- //cmd is RESET, SAFEMODE, RESTART
- //[ESP444]pwd=
- case 444:
- parameter = get_param(cmd_params,"", true);
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- {
- if (parameter=="RESET") {
- CONFIG::reset_config();
- BRIDGE::println(F("Reset done - restart needed"), output);
- } else if (parameter=="SAFEMODE") {
- wifi_config.Safe_Setup();
- BRIDGE::println(F("Set Safe Mode - restart needed"), output);
- } else if (parameter=="RESTART") {
- BRIDGE::println(F("Restart started"), output);
- BRIDGE::flush( output);
- CONFIG::esp_restart();
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- }
- break;
-#ifdef AUTHENTICATION_FEATURE
- //Change / Reset user password
- //[ESP555]pwd=
- case 555: {
- if (auth_type == LEVEL_ADMIN) {
- parameter = get_param(cmd_params,"", true);
- if (parameter.length() == 0) {
- if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
- BRIDGE::println(OK_CMD_MSG, output);
- } else {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- }
- } else {
- if (CONFIG::isLocalPasswordValid(parameter.c_str())) {
- if(CONFIG::write_string(EP_USER_PWD,parameter.c_str())) {
- BRIDGE::println(OK_CMD_MSG, output);
- } else {
- BRIDGE::println(ERROR_CMD_MSG, output);
- response = false;
- }
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- }
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- break;
- }
-#endif
- //[ESP700]
- case 700: { //read local file
- //be sure serial is locked
- if ((web_interface->blockserial)) {
- break;
- }
- cmd_params.trim() ;
- if ((cmd_params.length() > 0) && (cmd_params[0] != '/')) {
- cmd_params = "/" + cmd_params;
- }
- FS_FILE currentfile = SPIFFS.open(cmd_params, SPIFFS_FILE_READ);
- if (currentfile) {//if file open success
- //flush to be sure send buffer is empty
- ESP_SERIAL_OUT.flush();
- //until no line in file
- while (currentfile.available()) {
- String currentline = currentfile.readStringUntil('\n');
- currentline.replace("\n","");
- currentline.replace("\r","");
- if (currentline.length() > 0) {
- int ESPpos = currentline.indexOf("[ESP");
- if (ESPpos>-1) {
- //is there the second part?
- int ESPpos2 = currentline.indexOf("]",ESPpos);
- if (ESPpos2>-1) {
- //Split in command and parameters
- String cmd_part1=currentline.substring(ESPpos+4,ESPpos2);
- String cmd_part2="";
- //is there space for parameters?
- if (ESPpos2
- case 710:
- parameter = get_param(cmd_params,"", true);
-#ifdef AUTHENTICATION_FEATURE
- if (auth_type != LEVEL_ADMIN) {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- } else
-#endif
- {
- if (parameter=="FORMAT") {
- BRIDGE::print(F("Formating"), output);
- //SPIFFS.end();
- delay(0);
- SPIFFS.format();
- //SPIFFS.begin();
- BRIDGE::println(F("...Done"), output);
- } else {
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- }
- break;
- //SPIFFS total size and used size
- //[ESP720]
- case 720:
- BRIDGE::print(cmd_params, output);
-#ifdef ARDUINO_ARCH_ESP8266
- fs::FSInfo info;
- SPIFFS.info(info);
- BRIDGE::print("SPIFFS Total:", output);
- BRIDGE::print(CONFIG::formatBytes(info.totalBytes).c_str(), output);
- BRIDGE::print(" Used:", output);
- BRIDGE::println(CONFIG::formatBytes(info.usedBytes).c_str(), output);
-#else
- BRIDGE::print("SPIFFS Total:", output);
- BRIDGE::print(CONFIG::formatBytes(SPIFFS.totalBytes()).c_str(), output);
- BRIDGE::print(" Used:", output);
- BRIDGE::println(CONFIG::formatBytes(SPIFFS.usedBytes()).c_str(), output);
-#endif
- break;
- //get fw version firmare target and fw version
- //[ESP800]
- case 800:
- {
- byte sd_dir = 0;
- BRIDGE::print(cmd_params, output);
- BRIDGE::print(F("FW version:"), output);
- BRIDGE::print(FW_VERSION, output);
- BRIDGE::print(F(" # FW target:"), output);
- BRIDGE::print(CONFIG::GetFirmwareTargetShortName(), output);
- BRIDGE::print(F(" # FW HW:"), output);
- if (CONFIG::is_direct_sd) BRIDGE::print(F("Direct SD"), output);
- else BRIDGE::print(F("Serial SD"), output);
- BRIDGE::print(F(" # primary sd:"), output);
- if (!CONFIG::read_byte(EP_PRIMARY_SD, &sd_dir )) sd_dir = DEFAULT_PRIMARY_SD;
- if (sd_dir == SD_DIRECTORY) BRIDGE::print(F("/sd/"), output);
- else if (sd_dir == EXT_DIRECTORY) BRIDGE::print(F("/ext/"), output);
- else BRIDGE::print(F("none"), output);
- BRIDGE::print(F(" # secondary sd:"), output);
- if (!CONFIG::read_byte(EP_SECONDARY_SD, &sd_dir )) sd_dir = DEFAULT_SECONDARY_SD;
- if (sd_dir == SD_DIRECTORY) BRIDGE::print(F("/sd/"), output);
- else if (sd_dir == EXT_DIRECTORY) BRIDGE::print(F("/ext/"), output);
- else BRIDGE::print(F("none"), output);
- BRIDGE::print(F(" # authentication:"), output);
-#ifdef AUTHENTICATION_FEATURE
- BRIDGE::print(F("yes"), output);
-#else
- BRIDGE::print(F("no"), output);
-#endif
- BRIDGE::println("", output);
- }
- break;
- //get fw target
- //[ESP801]
- case 801:
- BRIDGE::print(cmd_params, output);
- BRIDGE::println(CONFIG::GetFirmwareTargetShortName(), output);
- break;
- //clear status/error/info list
- case 802:
- if (CONFIG::check_update_presence( )) BRIDGE::println("yes", output);
- else BRIDGE::println("no", output);
- break;
- //[ESP999]
- case 999:
- cmd_params.trim();
-#ifdef ERROR_MSG_FEATURE
- if (cmd_params=="ERROR") {
- web_interface->error_msg.clear();
- BRIDGE::println(OK_CMD_MSG, output);
- break;
- }
-#endif
-#ifdef INFO_MSG_FEATURE
- if (cmd_params=="INFO") {
- web_interface->info_msg.clear();
- BRIDGE::println(OK_CMD_MSG, output);
- break;
- }
-#endif
-#ifdef STATUS_MSG_FEATURE
- if (cmd_params=="STATUS") {
- web_interface->status_msg.clear();
- BRIDGE::println(OK_CMD_MSG, output);
- break;
- }
-#endif
- if (cmd_params=="ALL") {
-#ifdef ERROR_MSG_FEATURE
- web_interface->error_msg.clear();
-#endif
-#ifdef STATUS_MSG_FEATURE
- web_interface->status_msg.clear();
-#endif
-#ifdef INFO_MSG_FEATURE
- web_interface->info_msg.clear();
-#endif
- BRIDGE::println(OK_CMD_MSG, output);
- break;
- }
- default:
- BRIDGE::println(INCORRECT_CMD_MSG, output);
- response = false;
- }
- return response;
-}
-
-bool COMMAND::check_command(String buffer, tpipe output, bool handlelockserial)
-{
- String buffer2;
- LOG("Check Command:")
- LOG(buffer)
- LOG("\r\n")
- bool is_temp = false;
- if ((buffer.indexOf("T:") > -1 ) || (buffer.indexOf("B:") > -1 )) is_temp = true;
- //feed the WD for safety
- delay(0);
- if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
- //save time no need to continue
- if ((buffer.indexOf("busy:") > -1) || (buffer.startsWith("wait"))) {
- return false;
- }
- if (buffer.startsWith("ok")) {
- return false;
- }
- }
-#ifdef ERROR_MSG_FEATURE
- int Errorpos = -1;
-#endif
-#ifdef INFO_MSG_FEATURE
- int Infopos = -1;
-#endif
-#ifdef STATUS_MSG_FEATURE
- int Statuspos = -1;
-#endif
-if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
-#ifdef ERROR_MSG_FEATURE
- Errorpos= buffer.indexOf("error:");
-#endif
-#ifdef INFO_MSG_FEATURE
- Infopos= buffer.indexOf("info:");
-#endif
-#ifdef STATUS_MSG_FEATURE
- Statuspos= buffer.indexOf("warning:");
-#endif
-} else {
-#ifdef ERROR_MSG_FEATURE
- Errorpos= buffer.indexOf("Error:");
-#endif
-#ifdef INFO_MSG_FEATURE
- Infopos= buffer.indexOf("Info:");
-#endif
-#ifdef STATUS_MSG_FEATURE
- Statuspos= -1;
- if (CONFIG::GetFirmwareTarget() == MARLIN){
- Statuspos= buffer.indexOf("echo:");
- }
- else {
- Statuspos= buffer.indexOf("Status:");
- }
-
-#endif
-}
-
-#ifdef SERIAL_COMMAND_FEATURE
- String ESP_Command;
- int ESPpos = buffer.indexOf("[ESP");
- if (ESPpos>-1) {
- //is there the second part?
- int ESPpos2 = buffer.indexOf("]",ESPpos);
- if (ESPpos2>-1) {
- //Split in command and parameters
- String cmd_part1=buffer.substring(ESPpos+4,ESPpos2);
- String cmd_part2="";
- //is there space for parameters?
- if (ESPpos2-1 && !(buffer.indexOf("Format error")!=-1 || buffer.indexOf("wait")==Errorpos+6) ) {
- String ss = buffer.substring(Errorpos+6);
- ss.replace("\"","");
- ss.replace("'","");
- (web_interface->error_msg).add(ss.c_str());
- }
-#endif
-#ifdef INFO_MSG_FEATURE
- //Info
- if (Infopos>-1) {
- String ss = buffer.substring(Errorpos+5);
- ss.replace("\"","");
- ss.replace("'","");
- (web_interface->info_msg).add(ss.c_str());
- }
-#endif
-#ifdef STATUS_MSG_FEATURE
- //Status
- if (Statuspos>-1) {
- String ss ;
- if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)ss = buffer.substring(Errorpos+8);
- else if (CONFIG::GetFirmwareTarget() == MARLIN) ss = buffer.substring(Errorpos+5);
- else ss = buffer.substring(Errorpos+7);
- ss.replace("\"","");
- ss.replace("'","");
- (web_interface->info_msg).add(ss.c_str());
- }
-#endif
-
- return is_temp;
-}
-
-//read a buffer in an array
-void COMMAND::read_buffer_serial(uint8_t *b, size_t len)
-{
- for (long i = 0; i< len; i++) {
- read_buffer_serial(b[i]);
- //*b++;
- }
-}
-
-#ifdef TCP_IP_DATA_FEATURE
-//read buffer as char
-void COMMAND::read_buffer_tcp(uint8_t b)
-{
- static bool previous_was_char=false;
- static bool iscomment=false;
-//to ensure it is continuous string, no char separated by binaries
- if (!previous_was_char) {
- buffer_tcp="";
- iscomment = false;
- }
-//is comment ?
- if (char(b) == ';') {
- iscomment = true;
- }
-//it is a char so add it to buffer
- if (isPrintable(b)) {
- previous_was_char=true;
- //add char if not a comment
- if (!iscomment) {
- buffer_tcp+=char(b);
- }
- } else {
- previous_was_char=false; //next call will reset the buffer
- }
-//this is not printable but end of command check if need to handle it
- if (b==13 || b==10) {
- //reset comment flag
- iscomment = false;
- //Minimum is something like M10 so 3 char
- if (buffer_tcp.length()>3) {
- check_command(buffer_tcp, TCP_PIPE);
- }
- }
-}
-#endif
-//read buffer as char
-void COMMAND::read_buffer_serial(uint8_t b)
-{
- static bool previous_was_char=false;
- static bool iscomment=false;
-//to ensure it is continuous string, no char separated by binaries
- if (!previous_was_char) {
- buffer_serial="";
- iscomment = false;
- }
-//is comment ?
- if (char(b) == ';') {
- iscomment = true;
- }
-//it is a char so add it to buffer
- if (isPrintable(b)) {
- previous_was_char=true;
- if (!iscomment) {
- buffer_serial+=char(b);
- }
- } else {
- previous_was_char=false; //next call will reset the buffer
- }
-//this is not printable but end of command check if need to handle it
- if (b==13 || b==10) {
- //reset comment flag
- iscomment = false;
- //Minimum is something like M10 so 3 char
- if (buffer_serial.length()>3) {
- check_command(buffer_serial, SERIAL_PIPE);
- }
- }
-}
diff --git a/esp3d/config.cpp b/esp3d/config.cpp
deleted file mode 100644
index 9b55b265..00000000
--- a/esp3d/config.cpp
+++ /dev/null
@@ -1,1865 +0,0 @@
-/*
- config.cpp- ESP3D configuration class
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-#include "config.h"
-#include
-#ifndef FS_NO_GLOBALS
-#define FS_NO_GLOBALS
-#endif
-#include
-#include
-#include "wificonf.h"
-#ifdef ARDUINO_ARCH_ESP8266
-extern "C" {
-#include "user_interface.h"
-}
-#else
-#include "Update.h"
-#include "esp_wifi.h"
-#endif
-#include "bridge.h"
-
-
-uint8_t CONFIG::FirmwareTarget = UNKNOWN_FW;
-
-bool CONFIG::SetFirmwareTarget(uint8_t fw){
- if ( fw <= MAX_FW_ID) {
- FirmwareTarget = fw;
- return true;
- } else return false;
-}
-uint8_t CONFIG::GetFirmwareTarget() {
- return FirmwareTarget;
-}
-const char* CONFIG::GetFirmwareTargetName() {
- static String response;
- if ( CONFIG::FirmwareTarget == REPETIER4DV)response = F("Repetier for Davinci");
- else if ( CONFIG::FirmwareTarget == REPETIER)response = F("Repetier");
- else if ( CONFIG::FirmwareTarget == MARLIN) response = F("Marlin");
- else if ( CONFIG::FirmwareTarget == MARLINKIMBRA) response = F("MarlinKimbra");
- else if ( CONFIG::FirmwareTarget == SMOOTHIEWARE) response = F("Smoothieware");
- else response = F("???");
- return response.c_str();
-}
-
-const char* CONFIG::GetFirmwareTargetShortName() {
- static String response;
- if ( CONFIG::FirmwareTarget == REPETIER4DV)response = F("repetier4davinci");
- else if ( CONFIG::FirmwareTarget == REPETIER)response = F("repetier");
- else if ( CONFIG::FirmwareTarget == MARLIN) response = F("marlin");
- else if ( CONFIG::FirmwareTarget == MARLINKIMBRA) response = F("marlinkimbra");
- else if ( CONFIG::FirmwareTarget == SMOOTHIEWARE) response = F("smoothieware");
- else response = F("???");
- return response.c_str();
-}
-
-void CONFIG::InitFirmwareTarget(){
- uint8_t b = UNKNOWN_FW;
- if (!CONFIG::read_byte(EP_TARGET_FW, &b )) {
- b = UNKNOWN_FW;
- }
- if (!SetFirmwareTarget(b))SetFirmwareTarget(UNKNOWN_FW) ;
-}
-
-void CONFIG::InitDirectSD(){
- CONFIG::is_direct_sd = false;
-
-}
-
-bool CONFIG::InitBaudrate(){
- long baud_rate=0;
- if ( !CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate, INTEGER_LENGTH)) return false;
- if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400 ||baud_rate==250000) ) return false;
- //setup serial
- if (ESP_SERIAL_OUT.baudRate() != baud_rate)ESP_SERIAL_OUT.begin(baud_rate);
-#ifdef ARDUINO_ARCH_ESP8266
- ESP_SERIAL_OUT.setRxBufferSize(SERIAL_RX_BUFFER_SIZE);
-#endif
- wifi_config.baud_rate=baud_rate;
- delay(1000);
- return true;
-}
-
-bool CONFIG::InitExternalPorts(){
- if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port), INTEGER_LENGTH) || !CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port), INTEGER_LENGTH)) return false;
- if (wifi_config.iweb_port < DEFAULT_MIN_WEB_PORT ||wifi_config.iweb_port > DEFAULT_MAX_WEB_PORT || wifi_config.idata_port < DEFAULT_MIN_DATA_PORT || wifi_config.idata_port > DEFAULT_MAX_DATA_PORT) return false;
- return true;
-}
-
-#ifdef SDCARD_CONFIG_FEATURE
-bool CONFIG::update_settings(){
- String filename = SDCARD_CONFIG_FILENAME;
- filename.toLowerCase();
- //there is a config file
- LOG("Check ")
- LOG(filename)
- LOG("\r\n")
- bool answer = true;
- if(SD.exists((const char *)filename.c_str())) {
- bool success = true;
- bool localerror = false;
- const size_t bufferLen = 250;
- char buffer[bufferLen];
- byte ip_sav[4];
- String stmp;
- int itmp;
- long baud_rate=0;
- byte bflag;
- LOG("Found config file\r\n")
- String newfilename = filename;
- IniFile espconfig((char *)filename.c_str());
- //validate file is correct
- if (espconfig.open()) {
- if (!espconfig.validate(buffer, bufferLen)) {
- success = false;
- LOG("Invalid config file\r\n")
- } else { //file format is correct - let parse the settings
- //Section [wifi]
- //Hostname
- //hostname = myesp
- if (espconfig.getValue("network", "hostname", buffer, bufferLen)) {
- if (!CONFIG::isHostnameValid(buffer)) {
- success = false;
- } else if(!CONFIG::write_string(EP_HOSTNAME,buffer)) {
- success = false;
- }
- }
- //baudrate = 115200
- if (espconfig.getValue("network", "baudrate", buffer, bufferLen, baud_rate)) {
- if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&baud_rate,INTEGER_LENGTH)) {
- success = false;
- }
- }
- //webport = 80
- if (espconfig.getValue("network", "webport", buffer, bufferLen, itmp)) {
- if(!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&itmp,INTEGER_LENGTH)) {
- success = false;
- }
- }
- //dataport = 8888
- if (espconfig.getValue("network", "dataport", buffer, bufferLen, itmp)) {
- if(!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&itmp,INTEGER_LENGTH)) {
- success = false;
- }
- }
- //adminpwd = admin
- if (espconfig.getValue("network", "adminpwd", buffer, bufferLen)) {
- if (!CONFIG::isLocalPasswordValid(buffer)) {
- success = false;
- } else if(!CONFIG::write_string(EP_ADMIN_PWD,buffer)) {
- success = false;
- }
- }
- //userpwd = user
- if (espconfig.getValue("network", "userpwd", buffer, bufferLen)) {
- if (!CONFIG::isLocalPasswordValid(buffer)) {
- success = false;
- } else if(!CONFIG::write_string(EP_USER_PWD,buffer)) {
- success = false;
- }
- }
- //sleep = none
- if (espconfig.getValue("network", "sleep", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="none") {
- bflag = WIFI_NONE_SLEEP;
-#ifdef ARDUINO_ARCH_ESP8266
- } else if (stmp =="light") {
- bflag = WIFI_LIGHT_SLEEP;
-#endif
- } else if (stmp =="modem") {
- bflag = WIFI_MODEM_SLEEP;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_SLEEP_MODE,bflag)) {
- success = false;
- }
- }
- }
- //wifimode = STA
- if (espconfig.getValue("network", "wifimode", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="sta") {
- bflag = CLIENT_MODE;
- } else if (stmp =="ap") {
- bflag = AP_MODE;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_WIFI_MODE,bflag)) {
- success = false;
- }
- }
- }
- //STAssid = NETGEAR_2GEXT_OFFICE2
- if (espconfig.getValue("network", "STAssid", buffer, bufferLen)) {
- if (!CONFIG::isSSIDValid(buffer)) {
- success = false;
- } else if(!CONFIG::write_string(EP_STA_SSID,buffer)) {
- success = false;
- }
- }
- //STApassword = mypassword
- if (espconfig.getValue("network", "STApassword", buffer, bufferLen)) {
- if (!CONFIG::isPasswordValid(buffer)) {
- success = false;
- } else if(!CONFIG::write_string(EP_STA_PASSWORD,buffer)) {
- success = false;
- }
- }
- //STAipmode = DHCP
- if (espconfig.getValue("network", "STAipmode", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="dhcp") {
- bflag = DHCP_MODE;
- } else if (stmp =="static") {
- bflag = STATIC_IP_MODE;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_STA_IP_MODE,bflag)) {
- success = false;
- }
- }
- }
- //STAstatic_ip = 192.168.0.1
- if (espconfig.getValue("network", "STAstatic_ip", buffer, bufferLen)) {
- if (!CONFIG::isIPValid(buffer)) {
- success = false;
- } else {
- CONFIG::split_ip(buffer,ip_sav);
- if(!CONFIG::write_buffer(EP_STA_IP_VALUE,ip_sav,IP_LENGTH)) {
- success = false;
- }
- }
- }
- //STAstatic_mask = 255.255.255.0
- if (espconfig.getValue("network", "STAstatic_mask", buffer, bufferLen)) {
- if (!CONFIG::isIPValid(buffer)) {
- success = false;
- } else {
- CONFIG::split_ip(buffer,ip_sav);
- if(!CONFIG::write_buffer(EP_STA_MASK_VALUE,ip_sav,IP_LENGTH)) {
- success = false;
- }
- }
- }
- //STAstatic_gateway = 192.168.0.1
- if (espconfig.getValue("network", "STAstatic_gateway", buffer, bufferLen)) {
- if (!CONFIG::isIPValid(buffer)) {
- success = false;
- } else {
- CONFIG::split_ip(buffer,ip_sav);
- if(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,ip_sav,IP_LENGTH)) {
- success = false;
- }
- }
- }
- //STANetwork_mode = 11g
- if (espconfig.getValue("network", "STANetwork_mode", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="11b") {
- bflag = WIFI_PHY_MODE_11B;
- } else if (stmp =="11g") {
- bflag = WIFI_PHY_MODE_11G;
- } else if (stmp =="11n") {
- bflag = WIFI_PHY_MODE_11N;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_STA_PHY_MODE,bflag)) {
- success = false;
- }
- }
- }
- //APssid = NETGEAR_2GEXT_OFFICE2
- if (espconfig.getValue("network", "APssid", buffer, bufferLen)) {
- if (!CONFIG::isSSIDValid(buffer)) {
- success = false;
- } else if(!CONFIG::write_string(EP_AP_SSID,buffer)) {
- success = false;
- }
- }
- //APpassword = 12345678
- if (espconfig.getValue("network", "APpassword", buffer, bufferLen)) {
- if (!CONFIG::isPasswordValid(buffer)) {
- success = false;
- } else if(!CONFIG::write_string(EP_AP_PASSWORD,buffer)) {
- success = false;
- }
- }
- //APipmode = STATIC
- if (espconfig.getValue("network", "APipmode", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="dhcp") {
- bflag = DHCP_MODE;
- } else if (stmp =="static") {
- bflag = STATIC_IP_MODE;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_AP_IP_MODE,bflag)) {
- success = false;
- }
- }
- }
- //APstatic_ip = 192.168.0.1
- if (espconfig.getValue("network", "APstatic_ip", buffer, bufferLen)) {
- if (!CONFIG::isIPValid(buffer)) {
- success = false;
- } else {
- CONFIG::split_ip(buffer,ip_sav);
- if(!CONFIG::write_buffer(EP_AP_IP_VALUE,ip_sav,IP_LENGTH)) {
- success = false;
- }
- }
- }
- //APstatic_mask = 255.255.255.0
- if (espconfig.getValue("network", "APstatic_mask", buffer, bufferLen)) {
- if (!CONFIG::isIPValid(buffer)) {
- success = false;
- } else {
- CONFIG::split_ip(buffer,ip_sav);
- if(!CONFIG::write_buffer(EP_AP_MASK_VALUE,ip_sav,IP_LENGTH)) {
- success = false;
- }
- }
- }
- //APstatic_gateway = 192.168.0.1
- if (espconfig.getValue("network", "APstatic_gateway", buffer, bufferLen)) {
- if (!CONFIG::isIPValid(buffer)) {
- success = false;
- } else {
- CONFIG::split_ip(buffer,ip_sav);
- if(!CONFIG::write_buffer(EP_AP_GATEWAY_VALUE,ip_sav,IP_LENGTH)) {
- success = false;
- }
- }
- }
- //AP_channel = 1
- if (espconfig.getValue("network", "AP_channel", buffer, bufferLen, itmp)) {
- bflag = itmp;
- if(!CONFIG::write_byte(EP_CHANNEL,bflag)) {
- success = false;
- }
- }
- //AP_visible = yes
- if (espconfig.getValue("network", "AP_visible", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="yes") {
- bflag = 1;
- } else if (stmp =="no") {
- bflag = 0;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_SSID_VISIBLE,bflag)) {
- success = false;
- }
- }
- }
- //AP_auth = WPA
- if (espconfig.getValue("network", "AP_auth", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="open") {
- bflag = AUTH_OPEN;
- } else if (stmp =="wpa") {
- bflag = AUTH_WPA_PSK;
- } else if (stmp =="wpa2") {
- bflag = AUTH_WPA2_PSK;
- } else if (stmp =="wpa_wpa2") {
- bflag = AUTH_WPA_WPA2_PSK;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_AUTH_TYPE,bflag)) {
- success = false;
- }
- }
- }
- //APNetwork_mode = 11g
- if (espconfig.getValue("network", "APNetwork_mode", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="11b") {
- bflag = WIFI_PHY_MODE_11B;
- } else if (stmp =="11g") {
- bflag = WIFI_PHY_MODE_11G;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_AP_PHY_MODE,bflag)) {
- success = false;
- }
- }
- }
-
- //Timezone
- if (espconfig.getValue("network", "time_zone", buffer, bufferLen, itmp)) {
- bflag = itmp;
- if(!CONFIG::write_byte(EP_TIMEZONE,bflag)) {
- success = false;
- }
- }
-
- //day saving time
- if (espconfig.getValue("network", "day_st", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="yes") {
- bflag = 1;
- } else if (stmp =="no") {
- bflag = 0;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_TIME_ISDST,bflag)) {
- success = false;
- }
- }
- }
- //time server 1
- if (espconfig.getValue("network", "time_server_1", buffer, bufferLen)) {
- if (strlen(buffer) > 128) {
- success = false;
- } else if(!CONFIG::write_string(EP_TIME_SERVER1,buffer)) {
- success = false;
- }
- }
-
- //time server 2
- if (espconfig.getValue("network", "time_server_2", buffer, bufferLen)) {
- if (strlen(buffer) > 128) {
- success = false;
- } else if(!CONFIG::write_string(EP_TIME_SERVER2,buffer)) {
- success = false;
- }
- }
-
- //time server 3
- if (espconfig.getValue("network", "time_server_3", buffer, bufferLen)) {
- if (strlen(buffer) > 128) {
- success = false;
- } else if(!CONFIG::write_string(EP_TIME_SERVER3,buffer)) {
- success = false;
- }
- }
-
- //Section [printer]
- //data = 192.168.1.1/video.cgi?user=luc&pwd=mypassword
- if (espconfig.getValue("printer", "data", buffer, bufferLen)) {
- if (strlen(buffer) > 128) {
- success = false;
- } else if(!CONFIG::write_string(EP_DATA_STRING,buffer)) {
- success = false;
- }
- }
- //refreshrate = 3
- if (espconfig.getValue("printer", "refreshrate", buffer, bufferLen, itmp)) {
- bflag = itmp;
- if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME,bflag)) {
- success = false;
- }
- }
- //refreshrate2 = 3
- if (espconfig.getValue("printer", "refreshrate2", buffer, bufferLen, itmp)) {
- bflag = itmp;
- if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME2,bflag)) {
- success = false;
- }
- }
- //XY_feedrate = 1000
- if (espconfig.getValue("printer", "XY_feedrate", buffer, bufferLen, itmp)) {
- if(!CONFIG::write_buffer(EP_XY_FEEDRATE,(const byte *)&itmp,INTEGER_LENGTH)) {
- success = false;
- }
- }
- //Z_feedrate = 100
- if (espconfig.getValue("printer", "Z_feedrate", buffer, bufferLen, itmp)) {
- if(!CONFIG::write_buffer(EP_Z_FEEDRATE,(const byte *)&itmp,INTEGER_LENGTH)) {
- success = false;
- }
- }
- //E_feedrate = 400
- if (espconfig.getValue("printer", "E_feedrate", buffer, bufferLen, itmp)) {
- if(!CONFIG::write_buffer(EP_E_FEEDRATE,(const byte *)&itmp,INTEGER_LENGTH)) {
- success = false;
- }
- }
-
- //target_printer= smoothieware
- if (espconfig.getValue("printer", "target_printer", buffer, bufferLen)) {
- stmp = buffer;
- bflag = UNKNOWN_FW;
- if ( stmp.equalsIgnoreCase(String(F("repetier"))))bflag = REPETIER;
- else if ( stmp.equalsIgnoreCase(String(F("repetier4davinci"))))bflag = REPETIER4DV;
- else if ( stmp.equalsIgnoreCase(String(F("marlin"))))bflag = MARLIN;
- else if ( stmp.equalsIgnoreCase(String(F("marlinkimbra"))))bflag = MARLINKIMBRA;
- else if ( stmp.equalsIgnoreCase(String(F("smoothieware"))))bflag = SMOOTHIEWARE;
- else success = false;
- if(!(success && CONFIG::write_byte(EP_TARGET_FW,bflag))) {
- success = false;
- }
- }
-
- //direct sd connection
- if (espconfig.getValue("printer", "direct_sd", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="yes") {
- bflag = 1;
- } else if (stmp =="no") {
- bflag = 0;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_IS_DIRECT_SD,bflag)) {
- success = false;
- }
- }
- }
- //sd check update at boot
- if (espconfig.getValue("printer", "sd_check_update", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="yes") {
- bflag = 1;
- } else if (stmp =="no") {
- bflag = 0;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_SD_CHECK_UPDATE_AT_BOOT,bflag)) {
- success = false;
- }
- }
- }
- //direct sd boot check
- if (espconfig.getValue("printer", "direct_sd_boot_check", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="yes") {
- bflag = 1;
- } else if (stmp =="no") {
- bflag = 0;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_DIRECT_SD_CHECK,bflag)) {
- success = false;
- }
- }
- }
-
- //primary sd directory
- if (espconfig.getValue("printer", "primary_sd ", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="none") {
- bflag = 0;
- } else if (stmp =="sd") {
- bflag = 1;
- } else if (stmp =="ext") {
- bflag = 2;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_PRIMARY_SD,bflag)) {
- success = false;
- }
- }
- }
-
- //secondary sd directory
- if (espconfig.getValue("printer", "secondary_sd ", buffer, bufferLen)) {
- stmp = buffer;
- localerror = false;
- stmp.toLowerCase();
- bflag = 0;
- if (stmp =="none") {
- bflag = 0;
- } else if (stmp =="sd") {
- bflag = 1;
- } else if (stmp =="ext") {
- bflag = 2;
- } else {
- localerror = true;
- success = false;
- }
- if (!localerror) {
- if(!CONFIG::write_byte(EP_SECONDARY_SD,bflag)) {
- success = false;
- }
- }
- }
-
- }
- espconfig.close();
- if(success) {
- newfilename.replace(String(".txt"), String(".ok"));
- } else {
- newfilename.replace(String(".txt"), String(".bad"));
- answer = false;
- }
- //rename if name is already used
- if (!CONFIG::renameFile (newfilename)) {
- LOG("Failed to rename previous file\r\n")
- }
- if (SD.rename((const char *)filename.c_str(),(const char *)newfilename.c_str())) {
- LOG("File renamed, restarted file\r\n")
- } else {
- return false;
- LOG("Failed to rename file\r\n")
- }
- } else {
- return false;
- LOG("Failed to open config file\r\n")
- }
- } else {
- return false;
- LOG("No config file\r\n")
- }
- return answer;
-}
-#endif
-void CONFIG::esp_restart()
-{
- LOG("Restarting\r\n")
- ESP_SERIAL_OUT.flush();
- delay(500);
-#ifdef ARDUINO_ARCH_ESP8266
- ESP_SERIAL_OUT.swap();
-#endif
- delay(100);
- ESP.restart();
- while (1) {
- delay(1);
- };
-}
-
-void CONFIG::InitPins(){
-#ifdef RECOVERY_FEATURE
- pinMode(RESET_CONFIG_PIN, INPUT);
-#endif
-}
-
-bool CONFIG::is_direct_sd = false;
-
-bool CONFIG::isHostnameValid(const char * hostname)
-{
- //limited size
- char c;
- if (strlen(hostname)>MAX_HOSTNAME_LENGTH || strlen(hostname) < MIN_HOSTNAME_LENGTH) {
- return false;
- }
- //only letter and digit
- for (int i=0; i < strlen(hostname); i++) {
- c = hostname[i];
- if (!(isdigit(c) || isalpha(c) || c=='_')) {
- return false;
- }
- if (c==' ') {
- return false;
- }
- }
- return true;
-}
-
-bool CONFIG::isSSIDValid(const char * ssid)
-{
- //limited size
- //char c;
- if (strlen(ssid)>MAX_SSID_LENGTH || strlen(ssid)MAX_PASSWORD_LENGTH) {
- return false;
- }
- #if MIN_PASSWORD_LENGTH > 0
- if (strlen(password)MAX_LOCAL_PASSWORD_LENGTH)|| (strlen(password)15 || strlen(IP)==0) {
- return false;
- }
- //cannot start with .
- if (IP[0]=='.') {
- return false;
- }
- //only letter and digit
- for (int i=0; i < strlen(IP); i++) {
- c = IP[i];
- if (isdigit(c)) {
- //only 3 digit at once
- internalcount++;
- previouswasdot=false;
- if (internalcount>3) {
- return false;
- }
- } else if(c=='.') {
- //cannot have 2 dots side by side
- if (previouswasdot) {
- return false;
- }
- previouswasdot=true;
- internalcount=0;
- dotcount++;
- }//if not a dot neither a digit it is wrong
- else {
- return false;
- }
- }
- //if not 3 dots then it is wrong
- if (dotcount!=3) {
- return false;
- }
- //cannot have the last dot as last char
- if (IP[strlen(IP)-1]=='.') {
- return false;
- }
- return true;
-}
-
-char * CONFIG::intTostr(int value)
-{
- static char result [12];
- sprintf(result,"%d",value);
- return result;
-}
-
-String CONFIG::formatBytes(uint32_t bytes)
-{
- if (bytes < 1024) {
- return String(bytes)+" B";
- } else if(bytes < (1024 * 1024)) {
- return String(bytes/1024.0)+" KB";
- } else if(bytes < (1024 * 1024 * 1024)) {
- return String(bytes/1024.0/1024.0)+" MB";
- } else {
- return String(bytes/1024.0/1024.0/1024.0)+" GB";
- }
-}
-
-//helper to convert string to IP
-//do not use IPAddress.fromString() because lack of check point and error result
-//return number of parts
-byte CONFIG::split_ip (const char * ptr,byte * part)
-{
- if (strlen(ptr)>15 || strlen(ptr)< 7) {
- part[0]=0;
- part[1]=0;
- part[2]=0;
- part[3]=0;
- return 0;
- }
-
- char pstart [16];
- char * ptr2;
- strcpy(pstart,ptr);
- ptr2 = pstart;
- byte i = strlen(pstart);
- byte pos = 0;
- for (byte j=0; jsprintf(macstr,"%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5])) {
- strcpy (macstr, "00:00:00:00:00:00");
- }
- return macstr;
-}
-
-
-//read a string
-//a string is multibyte + \0, this is won't work if 1 char is multibyte like chinese char
-bool CONFIG::read_string(int pos, char byte_buffer[], int size_max)
-{
- //check if parameters are acceptable
- if (size_max==0 || pos+size_max+1 > EEPROM_SIZE || byte_buffer== NULL) {
- LOG("Error read string\r\n")
- return false;
- }
- EEPROM.begin(EEPROM_SIZE);
- byte b = 13; // non zero for the while loop below
- int i=0;
-
- //read until max size is reached or \0 is found
- while (i < size_max && b != 0) {
- b = EEPROM.read(pos+i);
- byte_buffer[i]=b;
- i++;
- }
-
- // Be sure there is a 0 at the end.
- if (b!=0) {
- byte_buffer[i-1]=0x00;
- }
- EEPROM.end();
-
- return true;
-}
-
-bool CONFIG::read_string(int pos, String & sbuffer, int size_max)
-{
- //check if parameters are acceptable
- if (size_max==0 || pos+size_max+1 > EEPROM_SIZE ) {
- LOG("Error read string\r\n")
- return false;
- }
- byte b = 13; // non zero for the while loop below
- int i=0;
- sbuffer="";
-
- EEPROM.begin(EEPROM_SIZE);
- //read until max size is reached or \0 is found
- while (i < size_max && b != 0) {
- b = EEPROM.read(pos+i);
- if (b!=0) {
- sbuffer+=char(b);
- }
- i++;
- }
- EEPROM.end();
-
- return true;
-}
-
-//read a buffer of size_buffer
-bool CONFIG::read_buffer(int pos, byte byte_buffer[], int size_buffer)
-{
- //check if parameters are acceptable
- if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
- LOG("Error read buffer\r\n")
- return false;
- }
- int i=0;
- EEPROM.begin(EEPROM_SIZE);
- //read until max size is reached
- while (i EEPROM_SIZE) {
- LOG("Error read byte\r\n")
- return false;
- }
- EEPROM.begin(EEPROM_SIZE);
- value[0] = EEPROM.read(pos);
- EEPROM.end();
- return true;
-}
-
-bool CONFIG::write_string(int pos, const __FlashStringHelper *str)
-{
- String stmp = str;
- return write_string(pos,stmp.c_str());
-}
-
-bool CONFIG::check_update_presence( ){
- bool result = false;
- if (CONFIG::is_direct_sd) {
- long baud_rate=0;
- if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate, INTEGER_LENGTH)) return false;
- if (ESP_SERIAL_OUT.baudRate() != baud_rate)ESP_SERIAL_OUT.begin(baud_rate);
- CONFIG::InitFirmwareTarget();
- delay(500);
- String cmd = "M20";
- //By default M20 should be applied
- //if (CONFIG::FirmwareTarget == UNKNOWN_FW) return false;
- if (CONFIG::FirmwareTarget == SMOOTHIEWARE) {
- byte sd_dir = 0;
- if (!CONFIG::read_byte(EP_PRIMARY_SD, &sd_dir )) sd_dir = DEFAULT_PRIMARY_SD;
- if (sd_dir == SD_DIRECTORY) cmd = "ls /sd";
- else if (sd_dir == EXT_DIRECTORY) cmd = "ls /ext";
- else return false;
- }
- String tmp;
- int count ;
- //send command to serial as no need to transfer ESP command
- //to avoid any pollution if Uploading file to SDCard
- //block every query
- //empty the serial buffer and incoming data
- if(ESP_SERIAL_OUT.available()) {
- BRIDGE::processFromSerial2TCP();
- delay(1);
- }
- //Send command
- ESP_SERIAL_OUT.println(cmd);
- count = 0;
- String current_buffer;
- String current_line;
- //int pos;
- int temp_counter = 0;
-
- //pickup the list
- while (count < MAX_TRY) {
- //give some time between each buffer
- if (ESP_SERIAL_OUT.available()) {
- count = 0;
- size_t len = ESP_SERIAL_OUT.available();
- uint8_t sbuf[len+1];
- //read buffer
- ESP_SERIAL_OUT.readBytes(sbuf, len);
- //change buffer as string
- sbuf[len]='\0';
- //add buffer to current one if any
- current_buffer += (char * ) sbuf;
- while (current_buffer.indexOf("\n") !=-1) {
- //remove the possible "\r"
- current_buffer.replace("\r","");
- //pos = current_buffer.indexOf("\n");
- //get line
- current_line = current_buffer.substring(0,current_buffer.indexOf("\n"));
- //if line is command ack - just exit so save the time out period
- if ((current_line == "ok") || (current_line == "wait")) {
- count = MAX_TRY;
- break;
- }
- //check line
- //save time no need to continue
- if (current_line.indexOf("busy:") > -1 || current_line.indexOf("T:") > -1 || current_line.indexOf("B:") > -1) {
- temp_counter++;
- } else {
- }
- if (temp_counter > 5) {
- break;
- }
- //current remove line from buffer
- tmp = current_buffer.substring(current_buffer.indexOf("\n")+1,current_buffer.length());
- current_buffer = tmp;
- delay(0);
- }
- delay (0);
- } else {
- delay(1);
- }
- //it is sending too many temp status should be heating so let's exit the loop
- if (temp_counter > 5) {
- count = MAX_TRY;
- }
- count++;
- }
- if(ESP_SERIAL_OUT.available()) {
- BRIDGE::processFromSerial2TCP();
- delay(1);
- }
- }
- return result;
-}
-
-
-//write a string (array of byte with a 0x00 at the end)
-bool CONFIG::write_string(int pos, const char * byte_buffer)
-{
- int size_buffer;
- int maxsize = EEPROM_SIZE;
- size_buffer= strlen(byte_buffer);
- //check if parameters are acceptable
- switch (pos) {
- case EP_ADMIN_PWD:
- case EP_USER_PWD:
- maxsize = MAX_LOCAL_PASSWORD_LENGTH;
- break;
- case EP_AP_SSID:
- case EP_STA_SSID:
- maxsize = MAX_SSID_LENGTH;
- break;
- case EP_AP_PASSWORD:
- case EP_STA_PASSWORD:
- maxsize = MAX_PASSWORD_LENGTH;
- break;
- case EP_HOSTNAME:
- maxsize = MAX_HOSTNAME_LENGTH;
- break;
- case EP_TIME_SERVER1:
- case EP_TIME_SERVER2:
- case EP_TIME_SERVER3:
- case EP_DATA_STRING:
- maxsize = MAX_DATA_LENGTH;
- break;
- default:
- maxsize = EEPROM_SIZE;
- break;
- }
- if ((size_buffer==0 && !(pos == EP_DATA_STRING)) || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) {
- LOG("Error write string\r\n")
- return false;
- }
- //copy the value(s)
- EEPROM.begin(EEPROM_SIZE);
- for (int i = 0; i < size_buffer; i++) {
- EEPROM.write(pos + i, byte_buffer[i]);
- }
-
- //0 terminal
- EEPROM.write(pos + size_buffer, 0x00);
- EEPROM.commit();
- EEPROM.end();
- return true;
-}
-
-//write a buffer
-bool CONFIG::write_buffer(int pos, const byte * byte_buffer, int size_buffer)
-{
- //check if parameters are acceptable
- if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
- LOG("Error write buffer\r\n")
- return false;
- }
- EEPROM.begin(EEPROM_SIZE);
- //copy the value(s)
- for (int i = 0; i < size_buffer; i++) {
- EEPROM.write(pos + i, byte_buffer[i]);
- }
- EEPROM.commit();
- EEPROM.end();
- return true;
-}
-
-//read a flag / byte
-bool CONFIG::write_byte(int pos, const byte value)
-{
- //check if parameters are acceptable
- if (pos+1 > EEPROM_SIZE) {
- LOG("Error write byte\r\n")
- return false;
- }
- EEPROM.begin(EEPROM_SIZE);
- EEPROM.write(pos, value);
- EEPROM.commit();
- EEPROM.end();
- return true;
-}
-
-bool CONFIG::reset_config()
-{
- if(!CONFIG::write_string(EP_DATA_STRING,"")) {
- return false;
- }
- if(!CONFIG::write_byte(EP_WIFI_MODE,DEFAULT_WIFI_MODE)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&DEFAULT_BAUD_RATE,INTEGER_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_string(EP_AP_SSID,FPSTR(DEFAULT_AP_SSID))) {
- return false;
- }
- if(!CONFIG::write_string(EP_AP_PASSWORD,FPSTR(DEFAULT_AP_PASSWORD))) {
- return false;
- }
- if(!CONFIG::write_string(EP_STA_SSID,FPSTR(DEFAULT_STA_SSID))) {
- return false;
- }
- if(!CONFIG::write_string(EP_STA_PASSWORD,FPSTR(DEFAULT_STA_PASSWORD))) {
- return false;
- }
- if(!CONFIG::write_byte(EP_AP_IP_MODE,DEFAULT_AP_IP_MODE)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_STA_IP_MODE,DEFAULT_STA_IP_MODE)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_STA_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_STA_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_STA_PHY_MODE,DEFAULT_PHY_MODE)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_AP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_AP_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_AP_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_AP_PHY_MODE,DEFAULT_PHY_MODE)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_SLEEP_MODE,DEFAULT_SLEEP_MODE)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_CHANNEL,DEFAULT_CHANNEL)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_AUTH_TYPE,DEFAULT_AUTH_TYPE)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_SSID_VISIBLE,DEFAULT_SSID_VISIBLE)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&DEFAULT_WEB_PORT,INTEGER_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&DEFAULT_DATA_PORT,INTEGER_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME,DEFAULT_REFRESH_PAGE_TIME)) {
- return false;
- }
- if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME2,DEFAULT_REFRESH_PAGE_TIME)) {
- return false;
- }
- if(!CONFIG::write_string(EP_HOSTNAME,wifi_config.get_default_hostname())) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_XY_FEEDRATE,(const byte *)&DEFAULT_XY_FEEDRATE,INTEGER_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_Z_FEEDRATE,(const byte *)&DEFAULT_Z_FEEDRATE,INTEGER_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_buffer(EP_E_FEEDRATE,(const byte *)&DEFAULT_E_FEEDRATE,INTEGER_LENGTH)) {
- return false;
- }
- if(!CONFIG::write_string(EP_ADMIN_PWD,FPSTR(DEFAULT_ADMIN_PWD))) {
- return false;
- }
- if(!CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_TARGET_FW, UNKNOWN_FW)) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_TIMEZONE, DEFAULT_TIME_ZONE)) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_TIME_ISDST, DEFAULT_TIME_DST)) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_PRIMARY_SD, DEFAULT_PRIMARY_SD)) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_SECONDARY_SD, DEFAULT_SECONDARY_SD)) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_IS_DIRECT_SD, DEFAULT_IS_DIRECT_SD)) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_DIRECT_SD_CHECK, DEFAULT_DIRECT_SD_CHECK)) {
- return false;
- }
-
- if(!CONFIG::write_byte(EP_SD_CHECK_UPDATE_AT_BOOT, DEFAULT_SD_CHECK_UPDATE_AT_BOOT)) {
- return false;
- }
-
- if(!CONFIG::write_string(EP_TIME_SERVER1,FPSTR(DEFAULT_TIME_SERVER1))) {
- return false;
- }
-
- if(!CONFIG::write_string(EP_TIME_SERVER2,FPSTR(DEFAULT_TIME_SERVER2))) {
- return false;
- }
-
- if(!CONFIG::write_string(EP_TIME_SERVER3,FPSTR(DEFAULT_TIME_SERVER3))) {
- return false;
- }
- return true;
-}
-
-void CONFIG::print_config(tpipe output, bool plaintext)
-{
- if (!plaintext)BRIDGE::print(F("{\"chip_id\":\""), output);
- else BRIDGE::print(F("Chip ID: "), output);
-#ifdef ARDUINO_ARCH_ESP8266
- BRIDGE::print(String(ESP.getChipId()).c_str(), output);
-#else
- BRIDGE::print(String((uint16_t)(ESP.getEfuseMac()>>32)).c_str(), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"cpu\":\""), output);
- else BRIDGE::print(F("CPU Frequency: "), output);
- BRIDGE::print(String(ESP.getCpuFreqMHz()).c_str(), output);
- if (plaintext)BRIDGE::print(F("Mhz"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#ifdef ARDUINO_ARCH_ESP32
- if (!plaintext)BRIDGE::print(F("\"cpu_temp\":\""), output);
- else BRIDGE::print(F("CPU Temperature: "), output);
- BRIDGE::print(String(temperatureRead(),1).c_str(), output);
- if (plaintext)BRIDGE::print(F("C"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\"freemem\":\""), output);
- else BRIDGE::print(F("Free memory: "), output);
- BRIDGE::print(formatBytes(ESP.getFreeHeap()).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\""), output);
- BRIDGE::print(F("SDK"), output);
- if (!plaintext)BRIDGE::print(F("\":\""), output);
- else BRIDGE::print(F(": "), output);
- BRIDGE::print(ESP.getSdkVersion(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"flash_size\":\""), output);
- else BRIDGE::print(F("Flash Size: "), output);
- BRIDGE::print(formatBytes(ESP.getFlashChipSize()).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#ifdef ARDUINO_ARCH_ESP8266
- fs::FSInfo info;
- SPIFFS.info(info);
- if (!plaintext)BRIDGE::print(F("\"update_size\":\""), output);
- else BRIDGE::print(F("Available Size for update: "), output);
- uint32_t flashsize = ESP.getFlashChipSize();
- if (flashsize > 1024 * 1024) flashsize = 1024 * 1024;
- BRIDGE::print(formatBytes(flashsize - ESP.getSketchSize()-info.totalBytes).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else {
- if ((flashsize - ESP.getSketchSize()-info.totalBytes) > (ESP.getSketchSize())) BRIDGE::println(F("(Ok)"), output);
- else BRIDGE::println(F("(Not enough)"), output);
- }
-
- if (!plaintext)BRIDGE::print(F("\"spiffs_size\":\""), output);
- else BRIDGE::print(F("Available Size for SPIFFS: "), output);
-
- BRIDGE::print(formatBytes(info.totalBytes).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#else
- if (!plaintext)BRIDGE::print(F("\"update_size\":\""), output);
- else BRIDGE::print(F("Available Size for update: "), output);
- uint32_t flashsize = ESP.getFlashChipSize();
-//Not OTA on 2Mb board per spec
- if (flashsize > 0x20000) flashsize = 0x140000;
- else flashsize = 0x0;
- BRIDGE::print(formatBytes(flashsize).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else {
- if (flashsize > 0x0) BRIDGE::println(F("(Ok)"), output);
- else BRIDGE::print(F("(Not enough)"), output);
- }
- if (!plaintext)BRIDGE::print(F("\"spiffs_size\":\""), output);
- else BRIDGE::print(F("Available Size for SPIFFS: "), output);
- BRIDGE::print(formatBytes(SPIFFS.totalBytes()).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\"baud_rate\":\""), output);
- else BRIDGE::print(F("Baud rate: "), output);
- uint32_t br = ESP_SERIAL_OUT.baudRate();
-#ifdef ARDUINO_ARCH_ESP32
- //workaround for ESP32
- if(br == 115201)br = 115200;
- if(br == 230423)br = 230400;
-#endif
- BRIDGE::print(String(br).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"sleep_mode\":\""), output);
- else BRIDGE::print(F("Sleep mode: "), output);
-#ifdef ARDUINO_ARCH_ESP32
- wifi_ps_type_t ps_type;
- esp_wifi_get_ps(&ps_type);
-#else
- WiFiSleepType_t ps_type;
- ps_type = WiFi.getSleepMode();
-#endif
- if (ps_type == WIFI_NONE_SLEEP) {
- BRIDGE::print(F("None"), output);
-#ifdef ARDUINO_ARCH_ESP8266
- } else if (ps_type == WIFI_LIGHT_SLEEP) {
- BRIDGE::print(F("Light"), output);
-#endif
- } else if (ps_type == WIFI_MODEM_SLEEP) {
- BRIDGE::print(F("Modem"), output);
- } else {
- BRIDGE::print(F("???"), output);
- }
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"channel\":\""), output);
- else BRIDGE::print(F("Channel: "), output);
- BRIDGE::print(String(WiFi.channel()).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#ifdef ARDUINO_ARCH_ESP32
- uint8_t PhyMode;
- if (WiFi.getMode() == WIFI_STA)esp_wifi_get_protocol(ESP_IF_WIFI_STA, &PhyMode);
- else esp_wifi_get_protocol(ESP_IF_WIFI_AP, &PhyMode);
-#else
- WiFiPhyMode_t PhyMode = WiFi.getPhyMode();
-#endif
- if (!plaintext)BRIDGE::print(F("\"phy_mode\":\""), output);
- else BRIDGE::print(F("Phy Mode: "), output);
- if (PhyMode == (WIFI_PHY_MODE_11G))BRIDGE::print(F("11g"), output);
- else if (PhyMode == (WIFI_PHY_MODE_11B))BRIDGE::print(F("11b"), output);
- else if (PhyMode == (WIFI_PHY_MODE_11N))BRIDGE::print(F("11n"), output);
- else BRIDGE::print(F("???"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"web_port\":\""), output);
- else BRIDGE::print(F("Web port: "), output);
- BRIDGE::print(String(wifi_config.iweb_port).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"data_port\":\""), output);
- else BRIDGE::print(F("Data port: "), output);
-#ifdef TCP_IP_DATA_FEATURE
- BRIDGE::print(String(wifi_config.idata_port).c_str(), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (WiFi.getMode() == WIFI_STA || WiFi.getMode() == WIFI_AP_STA) {
- if (!plaintext)BRIDGE::print(F("\"hostname\":\""), output);
- else BRIDGE::print(F("Hostname: "), output);
-#ifdef ARDUINO_ARCH_ESP32
- BRIDGE::print(WiFi.getHostname(), output);
-#else
- BRIDGE::print(WiFi.hostname().c_str(), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- }
-
- if (!plaintext)BRIDGE::print(F("\"active_mode\":\""), output);
- else BRIDGE::print(F("Active Mode: "), output);
- if (WiFi.getMode() == WIFI_STA) {
- BRIDGE::print(F("Station ("), output);
- BRIDGE::print(WiFi.macAddress().c_str(), output);
- BRIDGE::print(F(")"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- if (WiFi.isConnected()) {
- if (!plaintext)BRIDGE::print(F("\"connected_ssid\":\""), output);
- else BRIDGE::print(F("Connected to: "), output);
- BRIDGE::print(WiFi.SSID().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- if (!plaintext)BRIDGE::print(F("\"connected_signal\":\""), output);
- else BRIDGE::print(F("Signal: "), output);
- BRIDGE::print(String(wifi_config.getSignal(WiFi.RSSI())).c_str(), output);
- BRIDGE::print(F("%"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- }
- else {
- if (!plaintext)BRIDGE::print(F("\"connection_status\":\""), output);
- else BRIDGE::print(F("Connection Status: "), output);
- BRIDGE::print(F("Connection Status: "), output);
- if (WiFi.status() == WL_DISCONNECTED) {
- BRIDGE::print(F("Disconnected"), output);
- } else if (WiFi.status() == WL_CONNECTION_LOST) {
- BRIDGE::print(F("Connection lost"), output);
- } else if (WiFi.status() == WL_CONNECT_FAILED) {
- BRIDGE::print(F("Connection failed"), output);
- } else if (WiFi.status() == WL_NO_SSID_AVAIL) {
- BRIDGE::print(F("No connection"), output);
- } else if (WiFi.status() == WL_IDLE_STATUS ) {
- BRIDGE::print(F("Idle"), output);
- } else BRIDGE::print(F("Unknown"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- }
- if (!plaintext)BRIDGE::print(F("\"ip_mode\":\""), output);
- else BRIDGE::print(F("IP Mode: "), output);
-#ifdef ARDUINO_ARCH_ESP32
- tcpip_adapter_dhcp_status_t dhcp_status;
- tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &dhcp_status);
- if (dhcp_status == TCPIP_ADAPTER_DHCP_STARTED)
-#else
- if (wifi_station_dhcpc_status()==DHCP_STARTED)
-#endif
- {
- BRIDGE::print(F("DHCP"), output);
- }
- else BRIDGE::print(F("Static"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"ip\":\""), output);
- else BRIDGE::print(F("IP: "), output);
- BRIDGE::print(WiFi.localIP().toString().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"gw\":\""), output);
- else BRIDGE::print(F("Gateway: "), output);
- BRIDGE::print(WiFi.gatewayIP().toString().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"msk\":\""), output);
- else BRIDGE::print(F("Mask: "), output);
- BRIDGE::print(WiFi.subnetMask().toString().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"dns\":\""), output);
- else BRIDGE::print(F("DNS: "), output);
- BRIDGE::print(WiFi.dnsIP().toString().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"disabled_mode\":\""), output);
- else BRIDGE::print(F("Disabled Mode: "), output);
- BRIDGE::print(F("Access Point ("), output);
- BRIDGE::print(WiFi.softAPmacAddress().c_str(), output);
- BRIDGE::print(F(")"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- } else if (WiFi.getMode() == WIFI_AP) {
- BRIDGE::print(F("Access Point ("), output);
- BRIDGE::print(WiFi.softAPmacAddress().c_str(), output);
- BRIDGE::print(F(")"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- //get current config
-#ifdef ARDUINO_ARCH_ESP32
- wifi_ap_config_t apconfig;
- wifi_config_t conf;
- esp_wifi_get_config(ESP_IF_WIFI_AP, &conf);
- apconfig.ssid_hidden = conf.ap.ssid_hidden;
- apconfig.authmode = conf.ap.authmode;
- apconfig.max_connection = conf.ap.max_connection;
-#else
- struct softap_config apconfig;
- wifi_softap_get_config(&apconfig);
-#endif
- if (!plaintext)BRIDGE::print(F("\"ap_ssid\":\""), output);
- else BRIDGE::print(F("SSID: "), output);
-#ifdef ARDUINO_ARCH_ESP32
- BRIDGE::print((const char*)conf.ap.ssid, output);
-#else
- BRIDGE::print((const char*)apconfig.ssid, output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"ssid_visible\":\""), output);
- else BRIDGE::print(F("Visible: "), output);
- BRIDGE::print((apconfig.ssid_hidden == 0)?F("Yes"):F("No"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"ssid_authentication\":\""), output);
- else BRIDGE::print(F("Authentication: "), output);
- if (apconfig.authmode==AUTH_OPEN) {
- BRIDGE::print(F("None"), output);
- } else if (apconfig.authmode==AUTH_WEP) {
- BRIDGE::print(F("WEP"), output);
- } else if (apconfig.authmode==AUTH_WPA_PSK) {
- BRIDGE::print(F("WPA"), output);
- } else if (apconfig.authmode==AUTH_WPA2_PSK) {
- BRIDGE::print(F("WPA2"), output);
- } else {
- BRIDGE::print(F("WPA/WPA2"), output);
- }
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"ssid_max_connections\":\""), output);
- else BRIDGE::print(F("Max Connections: "), output);
- BRIDGE::print(String(apconfig.max_connection).c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"ssid_dhcp\":\""), output);
- else BRIDGE::print(F("DHCP Server: "), output);
-#ifdef ARDUINO_ARCH_ESP32
- tcpip_adapter_dhcp_status_t dhcp_status;
- tcpip_adapter_dhcps_get_status(TCPIP_ADAPTER_IF_AP, &dhcp_status);
- if (dhcp_status == TCPIP_ADAPTER_DHCP_STARTED)
-#else
- if(wifi_softap_dhcps_status() == DHCP_STARTED)
-#endif
- {
- BRIDGE::print(F("Started"), output);
- }
- else BRIDGE::print(F("Stopped"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"ip\":\""), output);
- else BRIDGE::print(F("IP: "), output);
- BRIDGE::print(WiFi.softAPIP().toString().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#ifdef ARDUINO_ARCH_ESP32
- tcpip_adapter_ip_info_t ip;
- tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip);
-#else
- struct ip_info ip;
- wifi_get_ip_info(SOFTAP_IF, &ip);
-#endif
- if (!plaintext)BRIDGE::print(F("\"gw\":\""), output);
- else BRIDGE::print(F("Gateway: "), output);
- BRIDGE::print(IPAddress(ip.gw.addr).toString().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"msk\":\""), output);
- else BRIDGE::print(F("Mask: "), output);
- BRIDGE::print(IPAddress(ip.netmask.addr).toString().c_str(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
-
- if (!plaintext)BRIDGE::print(F("\"connected_clients\":["), output);
- else BRIDGE::print(F("Connected clients: "), output);
- int client_counter=0;
-#ifdef ARDUINO_ARCH_ESP32
- wifi_sta_list_t station;
- tcpip_adapter_sta_list_t tcpip_sta_list;
- esp_wifi_ap_get_sta_list(&station);
- tcpip_adapter_get_sta_list(&station, &tcpip_sta_list);
-#else
- struct station_info * station;
- station = wifi_softap_get_station_info();
-#endif
- String stmp ="";
-#ifdef ARDUINO_ARCH_ESP32
- for (int i=0; i < station.num; i++){
-#else
- while(station) {
-#endif
- if(stmp.length() > 0) {
- if (!plaintext)stmp+=F(",");
- else stmp+=F("\n");
-
- }
- if (!plaintext)stmp+=F("{\"bssid\":\"");
- //BSSID
-#ifdef ARDUINO_ARCH_ESP32
- stmp += CONFIG::mac2str(tcpip_sta_list.sta[i].mac);
-#else
- stmp += CONFIG::mac2str(station->bssid);
-#endif
- if (!plaintext)stmp+=F("\",\"ip\":\"");
- else stmp += F(" ");
- //IP
-#ifdef ARDUINO_ARCH_ESP32
- stmp += IPAddress(tcpip_sta_list.sta[i].ip.addr).toString().c_str();
-#else
- stmp += IPAddress((const uint8_t *)&station->ip).toString().c_str();
-#endif
- if (!plaintext)stmp+=F("\"}");
- //increment counter
- client_counter++;
-#ifdef ARDUINO_ARCH_ESP32
- }
-#else
- //go next record
- station =STAILQ_NEXT(station, next);
- }
- wifi_softap_free_station_info();
-#endif
- if (!plaintext) {
- BRIDGE::print(stmp.c_str(), output);
- BRIDGE::print(F("],"), output);
- }
- else {
- //display number of client
- BRIDGE::println(String(client_counter).c_str(), output);
- //display list if any
- if(stmp.length() > 0)BRIDGE::println(stmp.c_str(), output);
- }
-
- if (!plaintext)BRIDGE::print(F("\"disabled_mode\":\""), output);
- else BRIDGE::print(F("Disabled Mode: "), output);
- BRIDGE::print(F("Station ("), output);
- BRIDGE::print(WiFi.macAddress().c_str(), output);
- BRIDGE::print(F(") is disabled"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- } else if (WiFi.getMode() == WIFI_AP_STA) {
- BRIDGE::print(F("Mixed"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- if (!plaintext)BRIDGE::print(F("\"active_mode\":\""), output);
- else BRIDGE::print(F("Active Mode: "), output);
- BRIDGE::print(F("Access Point ("), output);
- BRIDGE::print(WiFi.softAPmacAddress().c_str(), output);
- BRIDGE::println(F(")"), output);
- BRIDGE::print(F("Station ("), output);
- BRIDGE::print(WiFi.macAddress().c_str(), output);
- BRIDGE::print(F(")"), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- } else {
- BRIDGE::print("Wifi Off", output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
- }
-
- if (!plaintext)BRIDGE::print(F("\"captive_portal\":\""), output);
- else BRIDGE::print(F("Captive portal: "), output);
-#ifdef CAPTIVE_PORTAL_FEATURE
- BRIDGE::print(F("Enabled"), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"ssdp\":\""), output);
- else BRIDGE::print(F("SSDP: "), output);
-#ifdef SSDP_FEATURE
- BRIDGE::print(F("Enabled"), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"netbios\":\""), output);
- else BRIDGE::print(F("NetBios: "), output);
-#ifdef NETBIOS_FEATURE
- BRIDGE::print(F("Enabled"), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"mdns\":\""), output);
- else BRIDGE::print(F("mDNS: "), output);
-#ifdef MDNS_FEATURE
- BRIDGE::print(F("Enabled"), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"web_update\":\""), output);
- else BRIDGE::print(F("Web Update: "), output);
-#ifdef WEB_UPDATE_FEATURE
- BRIDGE::print(F("Enabled"), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"pin recovery\":\""), output);
- else BRIDGE::print(F("Pin Recovery: "), output);
-#ifdef RECOVERY_FEATURE
- BRIDGE::print(F("Enabled"), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"autentication\":\""), output);
- else BRIDGE::print(F("Authentication: "), output);
-#ifdef AUTHENTICATION_FEATURE
- BRIDGE::print(F("Enabled"), output);
-#else
- BRIDGE::print(F("Disabled"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-
- if (!plaintext)BRIDGE::print(F("\"target_fw\":\""), output);
- else BRIDGE::print(F("Target Firmware: "), output);
- BRIDGE::print(CONFIG::GetFirmwareTargetName(), output);
- if (!plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#ifdef DEBUG_ESP3D
- if (!plaintext)BRIDGE::print(F("\"debug\":\""), output);
- else BRIDGE::print(F("Debug: "), output);
- BRIDGE::print(F("Debug Enabled :"), output);
-#ifdef DEBUG_OUTPUT_SPIFFS
- BRIDGE::print(F("SPIFFS"), output);
-#endif
-#ifdef DEBUG_OUTPUT_SD
- BRIDGE::print(F("SD"), output);
-#endif
-#ifdef DEBUG_OUTPUT_SERIAL
- BRIDGE::print(F("serial"), output);
-#endif
-#ifdef DEBUG_OUTPUT_TCP
- BRIDGE::print(F("TCP"), output);
-#endif
- if (plaintext)BRIDGE::print(F("\","), output);
- else BRIDGE::print(F("\n"), output);
-#endif
- if (!plaintext)BRIDGE::print(F("\"fw\":\""), output);
- else BRIDGE::print(F("FW version: "), output);
- BRIDGE::print(FW_VERSION, output);
- if (!plaintext)BRIDGE::print(F("\"}"), output);
- else BRIDGE::print(F("\n"), output);
-}
diff --git a/esp3d/data/index.html.gz b/esp3d/data/index.html.gz
deleted file mode 100644
index 8ed88ab7..00000000
Binary files a/esp3d/data/index.html.gz and /dev/null differ
diff --git a/esp3d/esp3d.ino b/esp3d/esp3d.ino
deleted file mode 100644
index 24bec6aa..00000000
--- a/esp3d/esp3d.ino
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- This file is part of ESP3D Firmware for 3D printer.
-
- ESP3D Firmware for 3D printer is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- ESP3D Firmware for 3D printer is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this Firmware. If not, see .
-
- This firmware is using the standard arduino IDE with module to support ESP8266:
- https://github.com/esp8266/Arduino from Bootmanager
-
- Latest version of the code and documentation can be found here :
- https://github.com/luc-github/ESP3D
-
- Main author: luc lebosse
-
-*/
-//be sure correct IDE and settings are used for ESP8266 or ESP32
-#if !(defined( ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32))
-#error Oops! Make sure you have 'ESP8266 or ESP32' compatible board selected from the 'Tools -> Boards' menu.
-#endif
-#include
-#include "config.h"
-#include "wificonf.h"
-#include "bridge.h"
-#include "webinterface.h"
-#include "command.h"
-#ifdef ARDUINO_ARCH_ESP8266
-#include "ESP8266WiFi.h"
-#ifdef MDNS_FEATURE
-#include
-#endif
-#include
-#else
-#include
-#ifdef MDNS_FEATURE
-#include
-#endif
-#include "esp_wifi.h"
-#include
-#include "FS.h"
-#include "SPIFFS.h"
-#include "Update.h"
-#endif
-#include
-
-
-#ifdef CAPTIVE_PORTAL_FEATURE
-#include
-extern DNSServer dnsServer;
-#endif
-#ifdef SSDP_FEATURE
-#ifdef ARDUINO_ARCH_ESP8266
-#include
-#else
-//#include
-#endif
-#endif
-#ifdef NETBIOS_FEATURE
-#ifdef ARDUINO_ARCH_ESP8266
-#include
-#else
-//#include
-#endif
-#endif
-#ifndef FS_NO_GLOBALS
-#define FS_NO_GLOBALS
-#endif
-#include
-
-void setup()
-{
- bool breset_config=false;
- bool directsd_check = false;
- web_interface = NULL;
-#ifdef TCP_IP_DATA_FEATURE
- data_server = NULL;
-#endif
- // init:
-#ifdef DEBUG_ESP3D
- if (ESP_SERIAL_OUT.baudRate() != DEFAULT_BAUD_RATE)ESP_SERIAL_OUT.begin(DEFAULT_BAUD_RATE);
- delay(2000);
- LOG("\r\nDebug Serial set\r\n")
-#endif
- //WiFi.disconnect();
- WiFi.mode(WIFI_OFF);
- delay(8000);
- CONFIG::InitDirectSD();
- CONFIG::InitPins();
-#ifdef RECOVERY_FEATURE
- delay(8000);
- //check if reset config is requested
- if (digitalRead(RESET_CONFIG_PIN)==0) {
- breset_config=true; //if requested =>reset settings
- }
-#endif
- //check if EEPROM has value
- if ( !CONFIG::InitBaudrate() || !CONFIG::InitExternalPorts()) {
- breset_config=true; //cannot access to config settings=> reset settings
- LOG("Error no EEPROM access\r\n")
- }
-
- //reset is requested
- if(breset_config) {
- //update EEPROM with default settings
- if (ESP_SERIAL_OUT.baudRate() != DEFAULT_BAUD_RATE)ESP_SERIAL_OUT.begin(DEFAULT_BAUD_RATE);
-#ifdef ARDUINO_ARCH_ESP8266
- ESP_SERIAL_OUT.setRxBufferSize(SERIAL_RX_BUFFER_SIZE);
-#endif
- delay(2000);
- ESP_SERIAL_OUT.println(F("M117 ESP EEPROM reset"));
-#ifdef DEBUG_ESP3D
- CONFIG::print_config(DEBUG_PIPE, true);
- delay(1000);
-#endif
- CONFIG::reset_config();
- delay(1000);
- //put some default value to a void some exception at first start
- WiFi.mode(WIFI_AP);
-#ifdef ARDUINO_ARCH_ESP8266
- WiFi.setPhyMode(WIFI_PHY_MODE_11G);
-#else
- esp_wifi_set_protocol(ESP_IF_WIFI_AP, WIFI_PHY_MODE_11G);
-#endif
- CONFIG::esp_restart();
- }
-#if defined(DEBUG_ESP3D) && defined(DEBUG_OUTPUT_SERIAL)
- LOG("\r\n");
- delay(500);
- ESP_SERIAL_OUT.flush();
-#endif
- //get target FW
- CONFIG::InitFirmwareTarget();
- //Update is done if any so should be Ok
-#ifdef ARDUINO_ARCH_ESP32
- SPIFFS.begin(true);
-#else
- SPIFFS.begin();
-#endif
-
- //setup wifi according settings
- if (!wifi_config.Setup()) {
- ESP_SERIAL_OUT.println(F("M117 Safe mode 1"));
- //try again in AP mode
- if (!wifi_config.Setup(true)) {
- ESP_SERIAL_OUT.println(F("M117 Safe mode 2"));
- wifi_config.Safe_Setup();
- }
- }
- delay(1000);
- //setup servers
- if (!wifi_config.Enable_servers()) {
- ESP_SERIAL_OUT.println(F("M117 Error enabling servers"));
- }
- LOG("Setup Done\r\n");
-}
-
-
-
-//main loop
-void loop()
-{
- //be sure wifi is on to proceed wifi function
- if (WiFi.getMode()!=WIFI_OFF ) {
-#ifdef CAPTIVE_PORTAL_FEATURE
- if (WiFi.getMode()!=WIFI_STA ) {
- dnsServer.processNextRequest();
- }
-#endif
-//web requests
- web_interface->web_server.handleClient();
-#ifdef TCP_IP_DATA_FEATURE
- BRIDGE::processFromTCP2Serial();
-#endif
- }
- BRIDGE::processFromSerial2TCP();
- //in case of restart requested
- if (web_interface->restartmodule) {
- CONFIG::esp_restart();
- }
-}
diff --git a/esp3d/nofile.h b/esp3d/nofile.h
deleted file mode 100644
index e2fff90d..00000000
--- a/esp3d/nofile.h
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- nofile.h - ESP3D data file
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-//data generated by https://github.com/AraHaan/bin2c
-//bin2c Conversion Tool v0.14.0 - Windows - [FINAL].
-#define PAGE_NOFILES_SIZE 4776
-const char PAGE_NOFILES [] PROGMEM =
-{
-
- 0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0xED, 0x5C, 0x7D, 0x93, 0xDA, 0x46,
- 0x93, 0xFF, 0x2A, 0xB2, 0x52, 0x36, 0x70, 0x2B, 0x58, 0x49, 0xBC, 0xA3, 0x05, 0x3F, 0x49, 0x1C,
- 0x5F, 0x7C, 0xE5, 0xC4, 0x2E, 0xEF, 0xFA, 0xEE, 0xAA, 0xE2, 0x94, 0x4B, 0x48, 0x03, 0xE8, 0xB1,
- 0x90, 0x74, 0xD2, 0xB0, 0xBB, 0x98, 0xF0, 0xDD, 0xAF, 0x7B, 0x5E, 0xA4, 0x91, 0x10, 0x2C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A0, 0x0E, 0xF1, 0x83, 0x07,
- 0x4E, 0x5A, 0x70, 0xCC, 0x0A, 0x94, 0x63, 0xD6, 0x8B, 0x17, 0x00, 0xE1, 0xCF, 0xA0, 0x49, 0xBA,
- 0x66, 0xD9, 0x02, 0xF6, 0x46, 0xA0, 0x9E, 0x75, 0x22, 0x16, 0x36, 0x02, 0x79, 0xD6, 0x41, 0xA5,
- 0xAA, 0x05, 0x67, 0x08, 0x49, 0xCE, 0x5D, 0x10, 0xF9, 0xF1, 0x5D, 0x4D, 0xB4, 0x38, 0x7E, 0xDB,
- 0xE1, 0x5C, 0x5D, 0x8A, 0xEB, 0xE4, 0xAB, 0x4B, 0xF1, 0x03, 0x17, 0xF6, 0x3F, 0x96, 0xF9, 0x7F,
- 0x4B, 0x13, 0x97, 0xBB, 0x5F, 0x46, 0x00, 0x00
-};
diff --git a/esp3d/storestrings.cpp b/esp3d/storestrings.cpp
deleted file mode 100644
index 9f306118..00000000
--- a/esp3d/storestrings.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- storestrings.cpp - rolling storage class
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-#include "storestrings.h"
-//Constructor
-STORESTRINGS_CLASS::STORESTRINGS_CLASS (int maxsize, int maxstringlength)
-{
-//for rolling buffer
-//if max size is reached then remove oldest one and add the new one
- _maxsize=maxsize;
-//to limit the storage space
- _maxstringlength=maxstringlength;
-//need space for the "..."
- if (_maxstringlength<4 && _maxstringlength!=-1) {
- _maxstringlength=4;
- }
-}
-//Destructor
-STORESTRINGS_CLASS::~STORESTRINGS_CLASS ()
-{
- // clear list and content
- clear();
-}
-
-bool STORESTRINGS_CLASS::setsize(int size)
-{
- _maxsize=size;
- return true;
-}
-bool STORESTRINGS_CLASS::setlength(int len)
-{
- if (len < 4) {
- return false;
- }
- _maxstringlength = len;
- return true;
-}
-
-//Clear list and content
-void STORESTRINGS_CLASS::clear()
-{
- //while list is not empty
- while(_charlist.size()) {
- //remove element
- char * str = _charlist.pop();
- //destroy it
- delete str;
- }
-}
-
-bool STORESTRINGS_CLASS::add (const __FlashStringHelper *str)
-{
- String stmp;
- stmp=str;
- return add(stmp.c_str());
-}
-//Add element in storage
-bool STORESTRINGS_CLASS::add (const char * string)
-{
- //if we reach max size
- if (_maxsize==_charlist.size()) {
- //remove oldest one
- char * str = _charlist.shift();
- delete str;
- }
- //add new one
- //get size including \0 at the end
- size_t size = strlen(string)+1;
- bool need_resize=false;
- if ( (_maxstringlength!=-1) && (size >_maxstringlength+1 )) {
- need_resize = true;
- size=_maxstringlength+1;
- }
- //reserve memory
- char * ptr = new char[size*sizeof(char)];
- //copy string to storage
- if (need_resize) {
- //copy maximum length minus 3
- strncpy(ptr,string,_maxstringlength-3);
- strcpy(ptr+_maxstringlength-3,"...");
- } else {
- //copy as it is
- strcpy(ptr,string);
- }
- //add storage to list
- _charlist.add(ptr);
- return true;
-}
-//Remove element at pos position
-bool STORESTRINGS_CLASS::remove(int pos)
-{
- //be sure index is in range
- if (pos<0 && pos>(_charlist.size()-1)) {
- return false;
- }
- //remove item from list
- char * str = _charlist.remove(pos);
- //destroy item
- delete str;
- return true;
-}
-//Get element at pos position
-const char * STORESTRINGS_CLASS::get(int pos)
-{
- //be sure index is in range
- if (pos<0 && pos>(_charlist.size()-1)) {
- return NULL;
- }
- return (const char *) _charlist.get(pos);
-}
-//Get index for defined string
-int STORESTRINGS_CLASS::get_index(const char * string)
-{
- //parse the list until it is found
- for (int p=0; p<_charlist.size(); p++) {
- if (strcmp ( _charlist.get(p), string)==0) {
- return p;
- }
- }
- //if not found return -1
- return -1;
-}
-
diff --git a/esp3d/storestrings.h b/esp3d/storestrings.h
deleted file mode 100644
index ca89df0a..00000000
--- a/esp3d/storestrings.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- storestrings.h - rolling storage class
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#ifndef STORESTRINGS_h
-#define STORESTRINGS_h
-#include
-#include "GenLinkedList.h"
-class STORESTRINGS_CLASS
-{
-public:
- STORESTRINGS_CLASS (int maxsize = -1, int maxstringlength=-1);
- ~STORESTRINGS_CLASS ();
- bool add (const char * string);
- inline bool add (String & string)
- {
- return add(string.c_str());
- };
- bool add (const __FlashStringHelper *str);
- bool remove(int pos);
- const char * get(int pos);
- int get_index(const char * string);
- void clear();
- inline int size()
- {
- return _charlist.size();
- };
- bool setsize(int size);
- bool setlength(int len);
- inline int getsize()
- {
- return _maxsize;
- };
- inline int getlength()
- {
- return _maxstringlength;
- };
-
-private:
- int _maxsize;
- int _maxstringlength;
- GenLinkedList _charlist;
-};
-
-#endif
diff --git a/esp3d/wificonf.cpp b/esp3d/wificonf.cpp
deleted file mode 100644
index de45a921..00000000
--- a/esp3d/wificonf.cpp
+++ /dev/null
@@ -1,505 +0,0 @@
-/*
- wificonf.cpp - ESP3D configuration class
-
- Copyright (c) 2014 Luc Lebosse. All rights reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-#include "config.h"
-#include "wificonf.h"
-#include "bridge.h"
-#include "webinterface.h"
-
-#ifdef ARDUINO_ARCH_ESP8266
-#include "ESP8266WiFi.h"
-#ifdef MDNS_FEATURE
-#include
-#endif
-#else
-#include
-#include "esp_wifi.h"
-#ifdef MDNS_FEATURE
-#include
-#endif
-#endif
-#include "IPAddress.h"
-#ifdef CAPTIVE_PORTAL_FEATURE
-#include
-DNSServer dnsServer;
-const byte DNS_PORT = 53;
-#endif
-#ifdef ARDUINO_ARCH_ESP8266
-#include
-#else
-#include
-#endif
-#ifdef SSDP_FEATURE
-#include
-#endif
-#ifdef NETBIOS_FEATURE
-#ifdef ARDUINO_ARCH_ESP8266
-#include
-#else
-#include
-#endif
-#endif
-#ifdef ARDUINO_ARCH_ESP8266
-extern "C" {
-#include "user_interface.h"
-}
-#endif
-#ifdef TIMESTAMP_FEATURE
-#include
-#endif
-
-WIFI_CONFIG::WIFI_CONFIG()
-{
- iweb_port=DEFAULT_WEB_PORT;
- idata_port=DEFAULT_DATA_PORT;
- baud_rate=DEFAULT_BAUD_RATE;
- sleep_mode=DEFAULT_SLEEP_MODE;
- _hostname[0]=0;
-}
-
-int32_t WIFI_CONFIG::getSignal(int32_t RSSI)
-{
- if (RSSI <= -100) {
- return 0;
- }
- if (RSSI >= -50) {
- return 100;
- }
- return (2* (RSSI+100));
-}
-
-const char * WIFI_CONFIG::get_hostname()
-{
- String hname;
-#ifdef ARDUINO_ARCH_ESP8266
- hname = WiFi.hostname();
-#else
- hname = WiFi.getHostname();
-#endif
- if (hname.length()==0) {
- if (!CONFIG::read_string(EP_HOSTNAME, _hostname, MAX_HOSTNAME_LENGTH)) {
- strcpy(_hostname,get_default_hostname());
- }
- } else {
- strcpy(_hostname,hname.c_str());
- }
- return _hostname;
-}
-
-const char * WIFI_CONFIG::get_default_hostname()
-{
- static char hostname[13];
- uint8_t mac [WL_MAC_ADDR_LENGTH];
- WiFi.macAddress(mac);
- if (0>sprintf(hostname,"ESP_%02X%02X%02X",mac[3],mac[4],mac[5])) {
- strcpy (hostname, "ESP8266");
- }
- return hostname;
-}
-
-//safe setup if no connection
-void WIFI_CONFIG::Safe_Setup()
-{
-#ifdef CAPTIVE_PORTAL_FEATURE
- dnsServer.stop();
- delay(100);
-#endif
-
- WiFi.disconnect();
- //setup Soft AP
- WiFi.mode(WIFI_AP);
- IPAddress local_ip (DEFAULT_IP_VALUE[0],DEFAULT_IP_VALUE[1],DEFAULT_IP_VALUE[2],DEFAULT_IP_VALUE[3]);
- IPAddress gateway (DEFAULT_GATEWAY_VALUE[0],DEFAULT_GATEWAY_VALUE[1],DEFAULT_GATEWAY_VALUE[2],DEFAULT_GATEWAY_VALUE[3]);
- IPAddress subnet (DEFAULT_MASK_VALUE[0],DEFAULT_MASK_VALUE[1],DEFAULT_MASK_VALUE[2],DEFAULT_MASK_VALUE[3]);
- String ssid = FPSTR(DEFAULT_AP_SSID);
- String pwd = FPSTR(DEFAULT_AP_PASSWORD);
- WiFi.softAP(ssid.c_str(),pwd.c_str());
- delay(500);
- WiFi.softAPConfig( local_ip, gateway, subnet);
- delay(1000);
- ESP_SERIAL_OUT.println(F("M117 Safe mode started"));
-}
-
-//Read configuration settings and apply them
-bool WIFI_CONFIG::Setup(bool force_ap)
-{
- char pwd[MAX_PASSWORD_LENGTH+1];
- char sbuf[MAX_SSID_LENGTH+1];
- char hostname [MAX_HOSTNAME_LENGTH+1];
- //int wstatus;
- IPAddress currentIP;
- byte bflag=0;
- byte bmode=0;
- //system_update_cpu_freq(SYS_CPU_160MHZ);
- //set the sleep mode
- if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) {
- LOG("Error read Sleep mode\r\n")
- return false;
- }
-#ifdef ARDUINO_ARCH_ESP8266
- WiFi.setSleepMode ((WiFiSleepType_t)bflag);
-#else
- esp_wifi_set_ps((wifi_ps_type_t)bflag);
-#endif
- sleep_mode=bflag;
- if (force_ap) {
- bmode = AP_MODE;
- } else {
- //AP or client ?
- if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) ) {
- LOG("Error read wifi mode\r\n")
- return false;
- }
- }
- if (!CONFIG::read_string(EP_HOSTNAME, hostname, MAX_HOSTNAME_LENGTH)) {
- strcpy(hostname,get_default_hostname());
- }
- //this is AP mode
- if (bmode==AP_MODE) {
- LOG("Set AP mode\r\n")
- if(!CONFIG::read_string(EP_AP_SSID, sbuf, MAX_SSID_LENGTH)) {
- return false;
- }
- if(!CONFIG::read_string(EP_AP_PASSWORD, pwd, MAX_PASSWORD_LENGTH)) {
- return false;
- }
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- ESP_SERIAL_OUT.print(F("SSID "));
- ESP_SERIAL_OUT.println(sbuf);
- LOG("SSID ")
- LOG(sbuf)
- LOG("\r\n")
- //DHCP or Static IP ?
- if (!CONFIG::read_byte(EP_AP_IP_MODE, &bflag )) {
- LOG("Error IP mode\r\n")
- return false;
- }
- LOG("IP Mode: ")
- LOG(CONFIG::intTostr(bflag))
- LOG("\r\n")
- if (bflag==STATIC_IP_MODE) {
- byte ip_buf[4];
- LOG("Static mode\r\n")
- //get the IP
- LOG("IP value:")
- if (!CONFIG::read_buffer(EP_AP_IP_VALUE,ip_buf, IP_LENGTH)) {
- LOG("Error\r\n")
- return false;
- }
- IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
- LOG(local_ip.toString())
- LOG("\r\nGW value:")
- //get the gateway
- if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,ip_buf, IP_LENGTH)) {
- LOG("Error\r\n")
- return false;
- }
- IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
- LOG(gateway.toString())
- LOG("\r\nMask value:")
- //get the mask
- if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,ip_buf, IP_LENGTH)) {
- LOG("Error Mask value\r\n")
- return false;
- }
- IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
- LOG(subnet.toString())
- LOG("\r\n")
- //apply according active wifi mode
- LOG("Set IP\r\n")
- WiFi.softAPConfig( local_ip, gateway, subnet);
- delay(100);
- }
- LOG("Disable STA\r\n")
- WiFi.enableSTA(false);
- delay(100);
- LOG("Set phy mode\r\n")
- //setup PHY_MODE
- if (!CONFIG::read_byte(EP_AP_PHY_MODE, &bflag )) {
- return false;
- }
-#ifdef ARDUINO_ARCH_ESP32
- esp_wifi_set_protocol(ESP_IF_WIFI_AP, bflag);
-#endif
- LOG("Set AP\r\n")
- //setup Soft AP
- WiFi.mode(WIFI_AP);
- delay(50);
- WiFi.softAP(sbuf, pwd);
- delay(100);
-#ifdef ARDUINO_ARCH_ESP8266
- WiFi.setPhyMode((WiFiPhyMode_t)bflag);
-#endif
- delay(100);
- LOG("Get current config\r\n")
- //get current config
-#ifdef ARDUINO_ARCH_ESP32
- wifi_config_t conf;
- esp_wifi_get_config(ESP_IF_WIFI_AP, &conf);
-#else
- struct softap_config apconfig;
- wifi_softap_get_config(&apconfig);
-#endif
- //set the chanel
- if (!CONFIG::read_byte(EP_CHANNEL, &bflag )) {
- return false;
- }
-#ifdef ARDUINO_ARCH_ESP32
- conf.ap.channel=bflag;
-#else
- apconfig.channel=bflag;
-#endif
- //set Authentification type
- if (!CONFIG::read_byte(EP_AUTH_TYPE, &bflag )) {
- return false;
- }
-#ifdef ARDUINO_ARCH_ESP32
- conf.ap.authmode=(wifi_auth_mode_t)bflag;
-#else
- apconfig.authmode=(AUTH_MODE)bflag;
-#endif
- //set the visibility of SSID
- if (!CONFIG::read_byte(EP_SSID_VISIBLE, &bflag )) {
- return false;
- }
-#ifdef ARDUINO_ARCH_ESP32
- conf.ap.ssid_hidden=!bflag;
-#else
- apconfig.ssid_hidden=!bflag;
-#endif
-
- //no need to add these settings to configuration just use default ones
-#ifdef ARDUINO_ARCH_ESP32
- conf.ap.max_connection=DEFAULT_MAX_CONNECTIONS;
- conf.ap.beacon_interval=DEFAULT_BEACON_INTERVAL;
- if (esp_wifi_set_config(ESP_IF_WIFI_AP, &conf)!=ESP_OK){
- ESP_SERIAL_OUT.println(F("M117 Error Wifi AP!"));
- delay(1000);
- }
-#else
- apconfig.max_connection=DEFAULT_MAX_CONNECTIONS;
- apconfig.beacon_interval=DEFAULT_BEACON_INTERVAL;
- //apply settings to current and to default
- if (!wifi_softap_set_config(&apconfig) || !wifi_softap_set_config_current(&apconfig)) {
- ESP_SERIAL_OUT.println(F("M117 Error Wifi AP!"));
- delay(1000);
- }
-#endif
- } else {
- LOG("Set STA mode\r\n")
- if(!CONFIG::read_string(EP_STA_SSID, sbuf, MAX_SSID_LENGTH)) {
- return false;
- }
- if(!CONFIG::read_string(EP_STA_PASSWORD, pwd, MAX_PASSWORD_LENGTH)) {
- return false;
- }
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- ESP_SERIAL_OUT.print(F("SSID "));
- ESP_SERIAL_OUT.println(sbuf);
- LOG("SSID ")
- LOG(sbuf)
- LOG("\r\n")
- if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) {
- return false;
- }
- if (bflag==STATIC_IP_MODE) {
- byte ip_buf[4];
- //get the IP
- if (!CONFIG::read_buffer(EP_STA_IP_VALUE,ip_buf, IP_LENGTH)) {
- return false;
- }
- IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
- //get the gateway
- if (!CONFIG::read_buffer(EP_STA_GATEWAY_VALUE,ip_buf, IP_LENGTH)) {
- return false;
- }
- IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
- //get the mask
- if (!CONFIG::read_buffer(EP_STA_MASK_VALUE,ip_buf, IP_LENGTH)) {
- return false;
- }
- IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
- //apply according active wifi mode
- WiFi.config( local_ip, gateway, subnet);
- }
- WiFi.enableAP(false);
- delay(100);
- //setup PHY_MODE
- if (!CONFIG::read_byte(EP_STA_PHY_MODE, &bflag )) {
- return false;
- }
-#ifdef ARDUINO_ARCH_ESP32
- esp_wifi_set_protocol(ESP_IF_WIFI_STA, bflag);
-#endif
- //setup station mode
- WiFi.mode(WIFI_STA);
- delay(100);
-#ifdef ARDUINO_ARCH_ESP8266
- WiFi.setPhyMode((WiFiPhyMode_t)bflag);
-#endif
- WiFi.begin(sbuf, pwd);
- delay(100);
- byte i=0;
- //try to connect
- byte dot = 0;
- String msg;
- while (WiFi.status() != WL_CONNECTED && i<40) {
- switch(WiFi.status()) {
- case 1:
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- ESP_SERIAL_OUT.println(F("No SSID found!"));
- break;
-
- case 4:
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- ESP_SERIAL_OUT.println(F("No Connection!"));
- break;
-
- default:
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- if (dot == 0)msg = F("Connecting");
- dot++;
- msg.trim();
- msg +=F(".");
- //for smoothieware to keep position
- for (byte i= 0;i< 4-dot; i++)msg +=F(" ");
- if (dot == 4)dot=0;
- ESP_SERIAL_OUT.println(msg);
- break;
- }
- delay(500);
- i++;
- }
- if (WiFi.status() != WL_CONNECTED) {
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- ESP_SERIAL_OUT.println(F("Not Connectied!"));
- return false;
- }
-#ifdef ARDUINO_ARCH_ESP8266
- WiFi.hostname(hostname);
-#else
- WiFi.setHostname(hostname);
-#endif
- }
-
- //Get IP
- if (WiFi.getMode()==WIFI_STA) {
- currentIP=WiFi.localIP();
- } else {
- currentIP=WiFi.softAPIP();
- }
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- ESP_SERIAL_OUT.println(currentIP);
- ESP_SERIAL_OUT.flush();
- return true;
-}
-
-bool WIFI_CONFIG::Enable_servers()
-{
- //start web interface
- web_interface = new WEBINTERFACE_CLASS(wifi_config.iweb_port);
- //here the list of headers to be recorded
- const char * headerkeys[] = {"Cookie"} ;
- size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*);
- //ask server to track these headers
- web_interface->web_server.collectHeaders(headerkeys, headerkeyssize );
-#ifdef CAPTIVE_PORTAL_FEATURE
- if (WiFi.getMode()!=WIFI_STA ) {
- // if DNSServer is started with "*" for domain name, it will reply with
- // provided IP to all DNS request
- dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
- dnsServer.start(DNS_PORT, "*", WiFi.softAPIP());
- }
-#endif
- web_interface->web_server.begin();
-#ifdef TCP_IP_DATA_FEATURE
- //start TCP/IP interface
- data_server = new WiFiServer (wifi_config.idata_port);
- data_server->begin();
- data_server->setNoDelay(true);
-#endif
-
-#ifdef MDNS_FEATURE
- // Set up mDNS responder:
- //useless in AP mode and service consuming
- if (WiFi.getMode()!=WIFI_AP ){
- char hostname [MAX_HOSTNAME_LENGTH+1];
- if (!CONFIG::read_string(EP_HOSTNAME, hostname, MAX_HOSTNAME_LENGTH)) {
- strcpy(hostname,get_default_hostname());
- }
- if (!mdns.begin(hostname)) {
- ESP_SERIAL_OUT.print(FPSTR(M117_));
- ESP_SERIAL_OUT.println(F("Error with mDNS!"));
- delay(1000);
- } else {
- // Check for any mDNS queries and send responses
- delay(100);
- wifi_config.mdns.addService("http", "tcp", wifi_config.iweb_port);
- }
- }
-#endif
-#if defined(SSDP_FEATURE) || defined(NETBIOS_FEATURE)
- String shost;
- if (!CONFIG::read_string(EP_HOSTNAME, shost, MAX_HOSTNAME_LENGTH)) {
- shost=wifi_config.get_default_hostname();
- }
-#endif
-#ifdef SSDP_FEATURE
- String stmp;
- SSDP.setSchemaURL("description.xml");
- SSDP.setHTTPPort( wifi_config.iweb_port);
- SSDP.setName(shost.c_str());
- stmp=String(ESP.getChipId());
- SSDP.setSerialNumber(stmp.c_str());
- SSDP.setURL("/");
- SSDP.setModelName("ESP8266 01");
- SSDP.setModelNumber("01");
- SSDP.setModelURL("http://espressif.com/en/products/esp8266/");
- SSDP.setManufacturer("Espressif Systems");
- SSDP.setManufacturerURL("http://espressif.com");
- SSDP.setDeviceType("upnp:rootdevice");
- if (WiFi.getMode()!=WIFI_AP )SSDP.begin();
-#endif
-#ifdef NETBIOS_FEATURE
- //useless in AP mode and service consuming
- if (WiFi.getMode()!=WIFI_AP )NBNS.begin(shost.c_str());
-#endif
-
- return true;
-}
-
-bool WIFI_CONFIG::Disable_servers()
-{
-#ifdef TCP_IP_DATA_FEATURE
- data_server->stop();
-#endif
-#ifdef CAPTIVE_PORTAL_FEATURE
- if (WiFi.getMode()!=WIFI_STA ) {
- dnsServer.stop();
- }
-#endif
-#ifdef NETBIOS_FEATURE
- //useless in AP mode and service consuming
- if (WiFi.getMode()!=WIFI_AP )NBNS.end();
-#endif
- web_interface->web_server.stop();
- return true;
-}
-
-WIFI_CONFIG wifi_config;
diff --git a/libraries/WebServer/src/ESP8266WebServer.h b/examples/basicesp3d/basicesp3d.ino
similarity index 66%
rename from libraries/WebServer/src/ESP8266WebServer.h
rename to examples/basicesp3d/basicesp3d.ino
index d4330064..13f28c3b 100644
--- a/libraries/WebServer/src/ESP8266WebServer.h
+++ b/examples/basicesp3d/basicesp3d.ino
@@ -1,8 +1,7 @@
/*
- ESP8266WebServer.h - Dead simple web-server.
- Supports only one simultaneous client, knows how to handle GET and POST.
+ basic esp3d sample
- Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
+ Copyright (c) 2014 Luc Lebosse. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -17,13 +16,21 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
*/
+//library include
+#include "esp3d.h"
+//global variable
+Esp3D myesp3d;
-#ifndef ESP8266WEBSERVER_H
-#define ESP8266WEBSERVER_H
+//Setup
+void setup()
+{
+ myesp3d.begin();
+}
-#include
-
-#endif //ESP8266WEBSERVER_H
+//main loop
+void loop()
+{
+ myesp3d.process();
+}
diff --git a/libraries/AsyncTCP/.travis.yml b/libraries/AsyncTCP/.travis.yml
new file mode 100644
index 00000000..89808806
--- /dev/null
+++ b/libraries/AsyncTCP/.travis.yml
@@ -0,0 +1,37 @@
+sudo: false
+language: bash
+os:
+ - linux
+
+script:
+ - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
+ - sleep 3
+ - export DISPLAY=:1.0
+ - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
+ - tar xf arduino-1.6.5-linux64.tar.xz
+ - mv arduino-1.6.5 $HOME/arduino_ide
+ - export PATH="$HOME/arduino_ide:$PATH"
+ - which arduino
+ - mkdir -p $HOME/Arduino/libraries
+ - cp -r $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/ESPAsyncTCP
+ - cd $HOME/arduino_ide/hardware
+ - mkdir esp8266com
+ - cd esp8266com
+ - git clone https://github.com/esp8266/Arduino.git esp8266
+ - cd esp8266/tools
+ - python get.py
+ - source $TRAVIS_BUILD_DIR/travis/common.sh
+ - arduino --board esp8266com:esp8266:generic --save-prefs
+ - arduino --get-pref sketchbook.path
+ - build_sketches arduino $HOME/Arduino/libraries/ESPAsyncTCP esp8266
+
+notifications:
+ email:
+ on_success: change
+ on_failure: change
+ webhooks:
+ urls:
+ - https://webhooks.gitter.im/e/60e65d0c78ea0a920347
+ on_success: change # options: [always|never|change] default: always
+ on_failure: always # options: [always|never|change] default: always
+ on_start: false # default: false
diff --git a/libraries/AsyncTCP/LICENSE b/libraries/AsyncTCP/LICENSE
new file mode 100644
index 00000000..65c5ca88
--- /dev/null
+++ b/libraries/AsyncTCP/LICENSE
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/libraries/AsyncTCP/README.md b/libraries/AsyncTCP/README.md
new file mode 100644
index 00000000..023849bf
--- /dev/null
+++ b/libraries/AsyncTCP/README.md
@@ -0,0 +1,11 @@
+# AsyncTCP
+Async TCP Library for ESP32 Arduino
+
+[](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+
+This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP32 MCUs.
+
+This library is the base for [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer)
+
+## AsyncClient and AsyncServer
+The base classes on which everything else is built. They expose all possible scenarios, but are really raw and require more skills to use.
diff --git a/libraries/AsyncTCP/component.mk b/libraries/AsyncTCP/component.mk
new file mode 100644
index 00000000..bb5bb161
--- /dev/null
+++ b/libraries/AsyncTCP/component.mk
@@ -0,0 +1,3 @@
+COMPONENT_ADD_INCLUDEDIRS := src
+COMPONENT_SRCDIRS := src
+CXXFLAGS += -fno-rtti
diff --git a/libraries/AsyncTCP/library.json b/libraries/AsyncTCP/library.json
new file mode 100644
index 00000000..0644061e
--- /dev/null
+++ b/libraries/AsyncTCP/library.json
@@ -0,0 +1,19 @@
+{
+ "name":"AsyncTCP",
+ "description":"Asynchronous TCP Library for ESP32",
+ "keywords":"async,tcp",
+ "authors":
+ {
+ "name": "Hristo Gochkov",
+ "maintainer": true
+ },
+ "repository":
+ {
+ "type": "git",
+ "url": "https://github.com/me-no-dev/AsyncTCP.git"
+ },
+ "version": "1.0.0",
+ "license": "LGPL-3.0",
+ "frameworks": "arduino",
+ "platforms": ["espressif32", "espressif32_stage"]
+}
diff --git a/libraries/AsyncTCP/library.properties b/libraries/AsyncTCP/library.properties
new file mode 100644
index 00000000..d9e8e47d
--- /dev/null
+++ b/libraries/AsyncTCP/library.properties
@@ -0,0 +1,9 @@
+name=AsyncTCP
+version=1.0.0
+author=Me-No-Dev
+maintainer=Me-No-Dev
+sentence=Async TCP Library for ESP32
+paragraph=Async TCP Library for ESP32
+category=Other
+url=https://github.com/me-no-dev/AsyncTCP
+architectures=*
diff --git a/libraries/AsyncTCP/src/AsyncTCP.cpp b/libraries/AsyncTCP/src/AsyncTCP.cpp
new file mode 100644
index 00000000..ba1929b8
--- /dev/null
+++ b/libraries/AsyncTCP/src/AsyncTCP.cpp
@@ -0,0 +1,1055 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "Arduino.h"
+
+#include "AsyncTCP.h"
+extern "C"{
+#include "lwip/opt.h"
+#include "lwip/tcp.h"
+#include "lwip/inet.h"
+#include "lwip/dns.h"
+}
+
+/*
+ * TCP/IP Event Task
+ * */
+
+typedef enum {
+ LWIP_TCP_SENT, LWIP_TCP_RECV, LWIP_TCP_ERROR, LWIP_TCP_POLL
+} lwip_event_t;
+
+typedef struct {
+ lwip_event_t event;
+ void *arg;
+ union {
+ struct {
+ void * pcb;
+ int8_t err;
+ } connected;
+ struct {
+ int8_t err;
+ } error;
+ struct {
+ tcp_pcb * pcb;
+ uint16_t len;
+ } sent;
+ struct {
+ tcp_pcb * pcb;
+ pbuf * pb;
+ int8_t err;
+ } recv;
+ struct {
+ tcp_pcb * pcb;
+ } poll;
+ struct {
+ tcp_pcb * pcb;
+ int8_t err;
+ } accept;
+ struct {
+ const char * name;
+ ip_addr_t addr;
+ } dns;
+ };
+} lwip_event_packet_t;
+
+static xQueueHandle _async_queue;
+static TaskHandle_t _async_service_task_handle = NULL;
+
+static void _handle_async_event(lwip_event_packet_t * e){
+
+ if(e->event == LWIP_TCP_RECV){
+ AsyncClient::_s_recv(e->arg, e->recv.pcb, e->recv.pb, e->recv.err);
+ } else if(e->event == LWIP_TCP_SENT){
+ AsyncClient::_s_sent(e->arg, e->sent.pcb, e->sent.len);
+ } else if(e->event == LWIP_TCP_POLL){
+ AsyncClient::_s_poll(e->arg, e->poll.pcb);
+ } else if(e->event == LWIP_TCP_ERROR){
+ AsyncClient::_s_error(e->arg, e->error.err);
+ }
+ free((void*)(e));
+}
+
+static void _async_service_task(void *pvParameters){
+ lwip_event_packet_t * packet = NULL;
+ for (;;) {
+ if(xQueueReceive(_async_queue, &packet, 0) == pdTRUE){
+ //dispatch packet
+ _handle_async_event(packet);
+ } else {
+ vTaskDelay(1);
+ }
+ }
+ vTaskDelete(NULL);
+ _async_service_task_handle = NULL;
+}
+/*
+static void _stop_async_task(){
+ if(_async_service_task_handle){
+ vTaskDelete(_async_service_task_handle);
+ _async_service_task_handle = NULL;
+ }
+}
+*/
+static bool _start_async_task(){
+ if(!_async_queue){
+ _async_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *));
+ if(!_async_queue){
+ return false;
+ }
+ }
+ if(!_async_service_task_handle){
+ xTaskCreatePinnedToCore(_async_service_task, "async_tcp", 8192, NULL, 3, &_async_service_task_handle, 1);
+ if(!_async_service_task_handle){
+ return false;
+ }
+ }
+ return true;
+}
+
+/*
+ * LwIP Callbacks
+ * */
+
+static int8_t _tcp_poll(void * arg, struct tcp_pcb * pcb) {
+ if(!_async_queue){
+ return ERR_OK;
+ }
+ lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t));
+ e->event = LWIP_TCP_POLL;
+ e->arg = arg;
+ e->poll.pcb = pcb;
+ if (xQueueSend(_async_queue, &e, portMAX_DELAY) != pdPASS) {
+ free((void*)(e));
+ }
+ return ERR_OK;
+}
+
+static int8_t _tcp_recv(void * arg, struct tcp_pcb * pcb, struct pbuf *pb, int8_t err) {
+ if(!_async_queue){
+ return ERR_OK;
+ }
+ lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t));
+ e->event = LWIP_TCP_RECV;
+ e->arg = arg;
+ e->recv.pcb = pcb;
+ e->recv.pb = pb;
+ e->recv.err = err;
+ if (xQueueSend(_async_queue, &e, portMAX_DELAY) != pdPASS) {
+ free((void*)(e));
+ }
+ return ERR_OK;
+}
+
+static int8_t _tcp_sent(void * arg, struct tcp_pcb * pcb, uint16_t len) {
+ if(!_async_queue){
+ return ERR_OK;
+ }
+ lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t));
+ e->event = LWIP_TCP_SENT;
+ e->arg = arg;
+ e->sent.pcb = pcb;
+ e->sent.len = len;
+ if (xQueueSend(_async_queue, &e, portMAX_DELAY) != pdPASS) {
+ free((void*)(e));
+ }
+ return ERR_OK;
+}
+
+static void _tcp_error(void * arg, int8_t err) {
+ if(!_async_queue){
+ return;
+ }
+ lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t));
+ e->event = LWIP_TCP_ERROR;
+ e->arg = arg;
+ e->error.err = err;
+ if (xQueueSend(_async_queue, &e, portMAX_DELAY) != pdPASS) {
+ free((void*)(e));
+ }
+}
+
+/*
+ * TCP/IP API Calls
+ * */
+
+#include "lwip/priv/tcpip_priv.h"
+
+typedef struct {
+ struct tcpip_api_call call;
+ tcp_pcb * pcb;
+ int8_t err;
+ union {
+ struct {
+ const char* data;
+ size_t size;
+ uint8_t apiflags;
+ } write;
+ size_t received;
+ struct {
+ ip_addr_t * addr;
+ uint16_t port;
+ tcp_connected_fn cb;
+ } connect;
+ struct {
+ ip_addr_t * addr;
+ uint16_t port;
+ } bind;
+ uint8_t backlog;
+ };
+} tcp_api_call_t;
+
+static err_t _tcp_output_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = tcp_output(msg->pcb);
+ return msg->err;
+}
+
+static esp_err_t _tcp_output(tcp_pcb * pcb) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ tcpip_api_call(_tcp_output_api, (struct tcpip_api_call*)&msg);
+ return msg.err;
+}
+
+static err_t _tcp_write_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = tcp_write(msg->pcb, msg->write.data, msg->write.size, msg->write.apiflags);
+ return msg->err;
+}
+
+static esp_err_t _tcp_write(tcp_pcb * pcb, const char* data, size_t size, uint8_t apiflags) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ msg.write.data = data;
+ msg.write.size = size;
+ msg.write.apiflags = apiflags;
+ tcpip_api_call(_tcp_write_api, (struct tcpip_api_call*)&msg);
+ return msg.err;
+}
+
+static err_t _tcp_recved_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = 0;
+ tcp_recved(msg->pcb, msg->received);
+ return msg->err;
+}
+
+static esp_err_t _tcp_recved(tcp_pcb * pcb, size_t len) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ msg.received = len;
+ tcpip_api_call(_tcp_recved_api, (struct tcpip_api_call*)&msg);
+ return msg.err;
+}
+
+static err_t _tcp_connect_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = tcp_connect(msg->pcb, msg->connect.addr, msg->connect.port, msg->connect.cb);
+ return msg->err;
+}
+
+static esp_err_t _tcp_connect(tcp_pcb * pcb, ip_addr_t * addr, uint16_t port, tcp_connected_fn cb) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ msg.connect.addr = addr;
+ msg.connect.port = port;
+ msg.connect.cb = cb;
+ tcpip_api_call(_tcp_connect_api, (struct tcpip_api_call*)&msg);
+ return msg.err;
+}
+
+static err_t _tcp_close_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = tcp_close(msg->pcb);
+ return msg->err;
+}
+
+static esp_err_t _tcp_close(tcp_pcb * pcb) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ tcpip_api_call(_tcp_close_api, (struct tcpip_api_call*)&msg);
+ return msg.err;
+}
+
+static err_t _tcp_abort_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = 0;
+ tcp_abort(msg->pcb);
+ return msg->err;
+}
+
+static esp_err_t _tcp_abort(tcp_pcb * pcb) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ tcpip_api_call(_tcp_abort_api, (struct tcpip_api_call*)&msg);
+ return msg.err;
+}
+
+static err_t _tcp_bind_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = tcp_bind(msg->pcb, msg->bind.addr, msg->bind.port);
+ return msg->err;
+}
+
+static esp_err_t _tcp_bind(tcp_pcb * pcb, ip_addr_t * addr, uint16_t port) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ msg.bind.addr = addr;
+ msg.bind.port = port;
+ tcpip_api_call(_tcp_bind_api, (struct tcpip_api_call*)&msg);
+ return msg.err;
+}
+
+static err_t _tcp_listen_api(struct tcpip_api_call *api_call_msg){
+ tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
+ msg->err = 0;
+ msg->pcb = tcp_listen_with_backlog(msg->pcb, msg->backlog);
+ return msg->err;
+}
+
+static tcp_pcb * _tcp_listen_with_backlog(tcp_pcb * pcb, uint8_t backlog) {
+ tcp_api_call_t msg;
+ msg.pcb = pcb;
+ msg.backlog = backlog?backlog:0xFF;
+ tcpip_api_call(_tcp_listen_api, (struct tcpip_api_call*)&msg);
+ return msg.pcb;
+}
+#define _tcp_listen(p) _tcp_listen_with_backlog(p, 0xFF);
+
+
+
+/*
+ Async TCP Client
+ */
+
+AsyncClient::AsyncClient(tcp_pcb* pcb)
+: _connect_cb(0)
+, _connect_cb_arg(0)
+, _discard_cb(0)
+, _discard_cb_arg(0)
+, _sent_cb(0)
+, _sent_cb_arg(0)
+, _error_cb(0)
+, _error_cb_arg(0)
+, _recv_cb(0)
+, _recv_cb_arg(0)
+, _timeout_cb(0)
+, _timeout_cb_arg(0)
+, _pcb_busy(false)
+, _pcb_sent_at(0)
+, _close_pcb(false)
+, _ack_pcb(true)
+, _rx_last_packet(0)
+, _rx_since_timeout(0)
+, _ack_timeout(ASYNC_MAX_ACK_TIME)
+, _connect_port(0)
+, prev(NULL)
+, next(NULL)
+, _in_lwip_thread(false)
+{
+ _pcb = pcb;
+ if(_pcb){
+ _rx_last_packet = millis();
+ tcp_arg(_pcb, this);
+ tcp_recv(_pcb, &_tcp_recv);
+ tcp_sent(_pcb, &_tcp_sent);
+ tcp_err(_pcb, &_tcp_error);
+ tcp_poll(_pcb, &_tcp_poll, 1);
+ }
+}
+
+AsyncClient::~AsyncClient(){
+ if(_pcb)
+ _close();
+}
+
+bool AsyncClient::connect(IPAddress ip, uint16_t port){
+ if (_pcb){
+ log_w("already connected, state %d", _pcb->state);
+ return false;
+ }
+ if(!_start_async_task()){
+ log_e("failed to start task");
+ return false;
+ }
+
+ ip_addr_t addr;
+ addr.type = IPADDR_TYPE_V4;
+ addr.u_addr.ip4.addr = ip;
+
+ tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
+ if (!pcb){
+ log_e("pcb == NULL");
+ return false;
+ }
+
+ tcp_arg(pcb, this);
+ tcp_err(pcb, &_tcp_error);
+ if(_in_lwip_thread){
+ tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);
+ } else {
+ _tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);
+ }
+ return true;
+}
+
+AsyncClient& AsyncClient::operator=(const AsyncClient& other){
+ if (_pcb)
+ _close();
+
+ _pcb = other._pcb;
+ if (_pcb) {
+ _rx_last_packet = millis();
+ tcp_arg(_pcb, this);
+ tcp_recv(_pcb, &_tcp_recv);
+ tcp_sent(_pcb, &_tcp_sent);
+ tcp_err(_pcb, &_tcp_error);
+ tcp_poll(_pcb, &_tcp_poll, 1);
+ }
+ return *this;
+}
+
+int8_t AsyncClient::_connected(void* pcb, int8_t err){
+ _pcb = reinterpret_cast(pcb);
+ if(_pcb){
+ _rx_last_packet = millis();
+ _pcb_busy = false;
+ tcp_recv(_pcb, &_tcp_recv);
+ tcp_sent(_pcb, &_tcp_sent);
+ tcp_poll(_pcb, &_tcp_poll, 1);
+ }
+ _in_lwip_thread = true;
+ if(_connect_cb)
+ _connect_cb(_connect_cb_arg, this);
+ _in_lwip_thread = false;
+ return ERR_OK;
+}
+
+int8_t AsyncClient::_close(){
+ int8_t err = ERR_OK;
+ if(_pcb) {
+ //log_i("");
+ tcp_arg(_pcb, NULL);
+ tcp_sent(_pcb, NULL);
+ tcp_recv(_pcb, NULL);
+ tcp_err(_pcb, NULL);
+ tcp_poll(_pcb, NULL, 0);
+ if(_in_lwip_thread){
+ err = tcp_close(_pcb);
+ } else {
+ err = _tcp_close(_pcb);
+ }
+ if(err != ERR_OK) {
+ err = abort();
+ }
+ _pcb = NULL;
+ if(_discard_cb)
+ _discard_cb(_discard_cb_arg, this);
+ }
+ return err;
+}
+
+void AsyncClient::_error(int8_t err) {
+ if(_pcb){
+ tcp_arg(_pcb, NULL);
+ tcp_sent(_pcb, NULL);
+ tcp_recv(_pcb, NULL);
+ tcp_err(_pcb, NULL);
+ tcp_poll(_pcb, NULL, 0);
+ _pcb = NULL;
+ }
+ if(_error_cb)
+ _error_cb(_error_cb_arg, this, err);
+ if(_discard_cb)
+ _discard_cb(_discard_cb_arg, this);
+}
+
+int8_t AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) {
+ _rx_last_packet = millis();
+ //log_i("%u", len);
+ _pcb_busy = false;
+ if(_sent_cb)
+ _sent_cb(_sent_cb_arg, this, len, (millis() - _pcb_sent_at));
+ return ERR_OK;
+}
+
+int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
+ if(pb == NULL){
+ return _close();
+ }
+
+ while(pb != NULL){
+ _rx_last_packet = millis();
+ //we should not ack before we assimilate the data
+ //log_i("%u", pb->len);
+ //Serial.write((const uint8_t *)pb->payload, pb->len);
+ _ack_pcb = true;
+ pbuf *b = pb;
+ if(_recv_cb)
+ _recv_cb(_recv_cb_arg, this, b->payload, b->len);
+ if(!_ack_pcb)
+ _rx_ack_len += b->len;
+ else
+ _tcp_recved(pcb, b->len);
+ pb = b->next;
+ b->next = NULL;
+ pbuf_free(b);
+ }
+ return ERR_OK;
+}
+
+int8_t AsyncClient::_poll(tcp_pcb* pcb){
+ // Close requested
+ if(_close_pcb){
+ _close_pcb = false;
+ _close();
+ return ERR_OK;
+ }
+ uint32_t now = millis();
+
+ // ACK Timeout
+ if(_pcb_busy && _ack_timeout && (now - _pcb_sent_at) >= _ack_timeout){
+ _pcb_busy = false;
+ log_w("ack timeout %d", pcb->state);
+ if(_timeout_cb)
+ _timeout_cb(_timeout_cb_arg, this, (now - _pcb_sent_at));
+ return ERR_OK;
+ }
+ // RX Timeout
+ if(_rx_since_timeout && (now - _rx_last_packet) >= (_rx_since_timeout * 1000)){
+ log_w("rx timeout %d", pcb->state);
+ _close();
+ return ERR_OK;
+ }
+ // Everything is fine
+ if(_poll_cb)
+ _poll_cb(_poll_cb_arg, this);
+ return ERR_OK;
+}
+
+void AsyncClient::_dns_found(ip_addr_t *ipaddr){
+ _in_lwip_thread = true;
+ if(ipaddr){
+ connect(IPAddress(ipaddr->u_addr.ip4.addr), _connect_port);
+ } else {
+ log_e("dns fail");
+ if(_error_cb)
+ _error_cb(_error_cb_arg, this, -55);
+ if(_discard_cb)
+ _discard_cb(_discard_cb_arg, this);
+ }
+ _in_lwip_thread = false;
+}
+
+bool AsyncClient::operator==(const AsyncClient &other) {
+ return _pcb == other._pcb;
+}
+
+bool AsyncClient::connect(const char* host, uint16_t port){
+ ip_addr_t addr;
+ err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_s_dns_found, this);
+ if(err == ERR_OK) {
+ return connect(IPAddress(addr.u_addr.ip4.addr), port);
+ } else if(err == ERR_INPROGRESS) {
+ _connect_port = port;
+ return true;
+ }
+ log_e("error: %d", err);
+ return false;
+}
+
+int8_t AsyncClient::abort(){
+ if(_pcb) {
+ log_w("state %d", _pcb->state);
+ if(_in_lwip_thread){
+ tcp_abort(_pcb);
+ } else {
+ _tcp_abort(_pcb);
+ }
+ _pcb = NULL;
+ }
+ return ERR_ABRT;
+}
+
+void AsyncClient::close(bool now){
+ if(_in_lwip_thread){
+ tcp_recved(_pcb, _rx_ack_len);
+ } else {
+ _tcp_recved(_pcb, _rx_ack_len);
+ }
+ if(now)
+ _close();
+ else
+ _close_pcb = true;
+}
+
+void AsyncClient::stop() {
+ close(false);
+}
+
+bool AsyncClient::free(){
+ if(!_pcb)
+ return true;
+ if(_pcb->state == 0 || _pcb->state > 4)
+ return true;
+ return false;
+}
+
+size_t AsyncClient::space(){
+ if((_pcb != NULL) && (_pcb->state == 4)){
+ return tcp_sndbuf(_pcb);
+ }
+ return 0;
+}
+
+size_t AsyncClient::write(const char* data) {
+ if(data == NULL)
+ return 0;
+ return write(data, strlen(data));
+}
+
+size_t AsyncClient::write(const char* data, size_t size, uint8_t apiflags) {
+ size_t will_send = add(data, size, apiflags);
+ if(!will_send || !send())
+ return 0;
+ return will_send;
+}
+
+
+size_t AsyncClient::add(const char* data, size_t size, uint8_t apiflags) {
+ if(!_pcb || size == 0 || data == NULL)
+ return 0;
+ size_t room = space();
+ if(!room)
+ return 0;
+ size_t will_send = (room < size) ? room : size;
+ int8_t err = ERR_OK;
+ if(_in_lwip_thread){
+ err = tcp_write(_pcb, data, will_send, apiflags);
+ } else {
+ err = _tcp_write(_pcb, data, will_send, apiflags);
+ }
+ if(err != ERR_OK)
+ return 0;
+ return will_send;
+}
+
+bool AsyncClient::send(){
+ int8_t err = ERR_OK;
+ if(_in_lwip_thread){
+ err = tcp_output(_pcb);
+ } else {
+ err = _tcp_output(_pcb);
+ }
+ if(err == ERR_OK){
+ _pcb_busy = true;
+ _pcb_sent_at = millis();
+ return true;
+ }
+ return false;
+}
+
+size_t AsyncClient::ack(size_t len){
+ if(len > _rx_ack_len)
+ len = _rx_ack_len;
+ if(len){
+ if(_in_lwip_thread){
+ tcp_recved(_pcb, len);
+ } else {
+ _tcp_recved(_pcb, len);
+ }
+ }
+ _rx_ack_len -= len;
+ return len;
+}
+
+// Operators
+
+AsyncClient & AsyncClient::operator+=(const AsyncClient &other) {
+ if(next == NULL){
+ next = (AsyncClient*)(&other);
+ next->prev = this;
+ } else {
+ AsyncClient *c = next;
+ while(c->next != NULL) c = c->next;
+ c->next =(AsyncClient*)(&other);
+ c->next->prev = c;
+ }
+ return *this;
+}
+
+void AsyncClient::setRxTimeout(uint32_t timeout){
+ _rx_since_timeout = timeout;
+}
+
+uint32_t AsyncClient::getRxTimeout(){
+ return _rx_since_timeout;
+}
+
+uint32_t AsyncClient::getAckTimeout(){
+ return _ack_timeout;
+}
+
+void AsyncClient::setAckTimeout(uint32_t timeout){
+ _ack_timeout = timeout;
+}
+
+void AsyncClient::setNoDelay(bool nodelay){
+ if(!_pcb)
+ return;
+ if(nodelay)
+ tcp_nagle_disable(_pcb);
+ else
+ tcp_nagle_enable(_pcb);
+}
+
+bool AsyncClient::getNoDelay(){
+ if(!_pcb)
+ return false;
+ return tcp_nagle_disabled(_pcb);
+}
+
+uint16_t AsyncClient::getMss(){
+ if(_pcb)
+ return tcp_mss(_pcb);
+ return 0;
+}
+
+uint32_t AsyncClient::getRemoteAddress() {
+ if(!_pcb)
+ return 0;
+ return _pcb->remote_ip.u_addr.ip4.addr;
+}
+
+uint16_t AsyncClient::getRemotePort() {
+ if(!_pcb)
+ return 0;
+ return _pcb->remote_port;
+}
+
+uint32_t AsyncClient::getLocalAddress() {
+ if(!_pcb)
+ return 0;
+ return _pcb->local_ip.u_addr.ip4.addr;
+}
+
+uint16_t AsyncClient::getLocalPort() {
+ if(!_pcb)
+ return 0;
+ return _pcb->local_port;
+}
+
+IPAddress AsyncClient::remoteIP() {
+ return IPAddress(getRemoteAddress());
+}
+
+uint16_t AsyncClient::remotePort() {
+ return getRemotePort();
+}
+
+IPAddress AsyncClient::localIP() {
+ return IPAddress(getLocalAddress());
+}
+
+uint16_t AsyncClient::localPort() {
+ return getLocalPort();
+}
+
+uint8_t AsyncClient::state() {
+ if(!_pcb)
+ return 0;
+ return _pcb->state;
+}
+
+bool AsyncClient::connected(){
+ if (!_pcb)
+ return false;
+ return _pcb->state == 4;
+}
+
+bool AsyncClient::connecting(){
+ if (!_pcb)
+ return false;
+ return _pcb->state > 0 && _pcb->state < 4;
+}
+
+bool AsyncClient::disconnecting(){
+ if (!_pcb)
+ return false;
+ return _pcb->state > 4 && _pcb->state < 10;
+}
+
+bool AsyncClient::disconnected(){
+ if (!_pcb)
+ return true;
+ return _pcb->state == 0 || _pcb->state == 10;
+}
+
+bool AsyncClient::freeable(){
+ if (!_pcb)
+ return true;
+ return _pcb->state == 0 || _pcb->state > 4;
+}
+
+bool AsyncClient::canSend(){
+ return space() > 0;
+}
+
+
+// Callback Setters
+
+void AsyncClient::onConnect(AcConnectHandler cb, void* arg){
+ _connect_cb = cb;
+ _connect_cb_arg = arg;
+}
+
+void AsyncClient::onDisconnect(AcConnectHandler cb, void* arg){
+ _discard_cb = cb;
+ _discard_cb_arg = arg;
+}
+
+void AsyncClient::onAck(AcAckHandler cb, void* arg){
+ _sent_cb = cb;
+ _sent_cb_arg = arg;
+}
+
+void AsyncClient::onError(AcErrorHandler cb, void* arg){
+ _error_cb = cb;
+ _error_cb_arg = arg;
+}
+
+void AsyncClient::onData(AcDataHandler cb, void* arg){
+ _recv_cb = cb;
+ _recv_cb_arg = arg;
+}
+
+void AsyncClient::onTimeout(AcTimeoutHandler cb, void* arg){
+ _timeout_cb = cb;
+ _timeout_cb_arg = arg;
+}
+
+void AsyncClient::onPoll(AcConnectHandler cb, void* arg){
+ _poll_cb = cb;
+ _poll_cb_arg = arg;
+}
+
+
+void AsyncClient::_s_dns_found(const char * name, ip_addr_t * ipaddr, void * arg){
+ reinterpret_cast(arg)->_dns_found(ipaddr);
+}
+
+int8_t AsyncClient::_s_poll(void * arg, struct tcp_pcb * pcb) {
+ reinterpret_cast(arg)->_poll(pcb);
+ return ERR_OK;
+}
+
+int8_t AsyncClient::_s_recv(void * arg, struct tcp_pcb * pcb, struct pbuf *pb, int8_t err) {
+ reinterpret_cast(arg)->_recv(pcb, pb, err);
+ return ERR_OK;
+}
+
+int8_t AsyncClient::_s_sent(void * arg, struct tcp_pcb * pcb, uint16_t len) {
+ reinterpret_cast(arg)->_sent(pcb, len);
+ return ERR_OK;
+}
+
+void AsyncClient::_s_error(void * arg, int8_t err) {
+ reinterpret_cast(arg)->_error(err);
+}
+
+int8_t AsyncClient::_s_connected(void * arg, void * pcb, int8_t err){
+ reinterpret_cast(arg)->_connected(pcb, err);
+ return ERR_OK;
+}
+
+const char * AsyncClient::errorToString(int8_t error){
+ switch(error){
+ case 0: return "OK";
+ case -1: return "Out of memory error";
+ case -2: return "Buffer error";
+ case -3: return "Timeout";
+ case -4: return "Routing problem";
+ case -5: return "Operation in progress";
+ case -6: return "Illegal value";
+ case -7: return "Operation would block";
+ case -8: return "Connection aborted";
+ case -9: return "Connection reset";
+ case -10: return "Connection closed";
+ case -11: return "Not connected";
+ case -12: return "Illegal argument";
+ case -13: return "Address in use";
+ case -14: return "Low-level netif error";
+ case -15: return "Already connected";
+ case -55: return "DNS failed";
+ default: return "UNKNOWN";
+ }
+}
+
+const char * AsyncClient::stateToString(){
+ switch(state()){
+ case 0: return "Closed";
+ case 1: return "Listen";
+ case 2: return "SYN Sent";
+ case 3: return "SYN Received";
+ case 4: return "Established";
+ case 5: return "FIN Wait 1";
+ case 6: return "FIN Wait 2";
+ case 7: return "Close Wait";
+ case 8: return "Closing";
+ case 9: return "Last ACK";
+ case 10: return "Time Wait";
+ default: return "UNKNOWN";
+ }
+}
+
+/*
+ Async TCP Server
+ */
+struct pending_pcb {
+ tcp_pcb* pcb;
+ pbuf *pb;
+ struct pending_pcb * next;
+};
+
+AsyncServer::AsyncServer(IPAddress addr, uint16_t port)
+: _port(port)
+, _addr(addr)
+, _noDelay(false)
+, _in_lwip_thread(false)
+, _pcb(0)
+, _connect_cb(0)
+, _connect_cb_arg(0)
+{}
+
+AsyncServer::AsyncServer(uint16_t port)
+: _port(port)
+, _addr((uint32_t) IPADDR_ANY)
+, _noDelay(false)
+, _in_lwip_thread(false)
+, _pcb(0)
+, _connect_cb(0)
+, _connect_cb_arg(0)
+{}
+
+AsyncServer::~AsyncServer(){
+ end();
+}
+
+void AsyncServer::onClient(AcConnectHandler cb, void* arg){
+ _connect_cb = cb;
+ _connect_cb_arg = arg;
+}
+
+int8_t AsyncServer::_s_accept(void * arg, tcp_pcb * pcb, int8_t err){
+ reinterpret_cast(arg)->_accept(pcb, err);
+ return ERR_OK;
+}
+
+int8_t AsyncServer::_accept(tcp_pcb* pcb, int8_t err){
+ tcp_accepted(_pcb);
+ if(_connect_cb){
+
+ if (_noDelay)
+ tcp_nagle_disable(pcb);
+ else
+ tcp_nagle_enable(pcb);
+
+ AsyncClient *c = new AsyncClient(pcb);
+ if(c){
+ _in_lwip_thread = true;
+ c->_in_lwip_thread = true;
+ _connect_cb(_connect_cb_arg, c);
+ c->_in_lwip_thread = false;
+ _in_lwip_thread = false;
+ return ERR_OK;
+ }
+ }
+ if(tcp_close(pcb) != ERR_OK){
+ tcp_abort(pcb);
+ }
+ log_e("FAIL");
+ return ERR_OK;
+}
+
+void AsyncServer::begin(){
+ if(_pcb)
+ return;
+
+ if(!_start_async_task()){
+ log_e("failed to start task");
+ return;
+ }
+ int8_t err;
+ _pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
+ if (!_pcb){
+ log_e("_pcb == NULL");
+ return;
+ }
+
+ ip_addr_t local_addr;
+ local_addr.type = IPADDR_TYPE_V4;
+ local_addr.u_addr.ip4.addr = (uint32_t) _addr;
+ err = _tcp_bind(_pcb, &local_addr, _port);
+
+ if (err != ERR_OK) {
+ _tcp_close(_pcb);
+ log_e("bind error: %d", err);
+ return;
+ }
+
+ static uint8_t backlog = 5;
+ _pcb = _tcp_listen_with_backlog(_pcb, backlog);
+ //_pcb = _tcp_listen(_pcb);
+ if (!_pcb) {
+ log_e("listen_pcb == NULL");
+ return;
+ }
+ tcp_arg(_pcb, (void*) this);
+ tcp_accept(_pcb, &_s_accept);
+}
+
+void AsyncServer::end(){
+ if(_pcb){
+ tcp_arg(_pcb, NULL);
+ tcp_accept(_pcb, NULL);
+ if(_in_lwip_thread){
+ tcp_abort(_pcb);
+ } else {
+ _tcp_abort(_pcb);
+ }
+ _pcb = NULL;
+ }
+}
+
+void AsyncServer::setNoDelay(bool nodelay){
+ _noDelay = nodelay;
+}
+
+bool AsyncServer::getNoDelay(){
+ return _noDelay;
+}
+
+uint8_t AsyncServer::status(){
+ if (!_pcb)
+ return 0;
+ return _pcb->state;
+}
diff --git a/libraries/AsyncTCP/src/AsyncTCP.h b/libraries/AsyncTCP/src/AsyncTCP.h
new file mode 100644
index 00000000..1c24ac92
--- /dev/null
+++ b/libraries/AsyncTCP/src/AsyncTCP.h
@@ -0,0 +1,191 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef ASYNCTCP_H_
+#define ASYNCTCP_H_
+
+#include "IPAddress.h"
+#include
+extern "C" {
+#include "freertos/semphr.h"
+}
+
+class AsyncClient;
+
+#define ASYNC_MAX_ACK_TIME 5000
+#define ASYNC_WRITE_FLAG_COPY 0x01 //will allocate new buffer to hold the data while sending (else will hold reference to the data given)
+#define ASYNC_WRITE_FLAG_MORE 0x02 //will not send PSH flag, meaning that there should be more data to be sent before the application should react.
+
+typedef std::function AcConnectHandler;
+typedef std::function AcAckHandler;
+typedef std::function AcErrorHandler;
+typedef std::function AcDataHandler;
+typedef std::function AcTimeoutHandler;
+
+struct tcp_pcb;
+struct pbuf;
+struct _ip_addr;
+
+class AsyncClient {
+ protected:
+ tcp_pcb* _pcb;
+
+ AcConnectHandler _connect_cb;
+ void* _connect_cb_arg;
+ AcConnectHandler _discard_cb;
+ void* _discard_cb_arg;
+ AcAckHandler _sent_cb;
+ void* _sent_cb_arg;
+ AcErrorHandler _error_cb;
+ void* _error_cb_arg;
+ AcDataHandler _recv_cb;
+ void* _recv_cb_arg;
+ AcTimeoutHandler _timeout_cb;
+ void* _timeout_cb_arg;
+ AcConnectHandler _poll_cb;
+ void* _poll_cb_arg;
+
+ bool _pcb_busy;
+ uint32_t _pcb_sent_at;
+ bool _close_pcb;
+ bool _ack_pcb;
+ uint32_t _rx_ack_len;
+ uint32_t _rx_last_packet;
+ uint32_t _rx_since_timeout;
+ uint32_t _ack_timeout;
+ uint16_t _connect_port;
+
+ int8_t _close();
+ int8_t _connected(void* pcb, int8_t err);
+ void _error(int8_t err);
+ int8_t _poll(tcp_pcb* pcb);
+ int8_t _sent(tcp_pcb* pcb, uint16_t len);
+ void _dns_found(struct _ip_addr *ipaddr);
+
+
+ public:
+ AsyncClient* prev;
+ AsyncClient* next;
+
+ AsyncClient(tcp_pcb* pcb = 0);
+ ~AsyncClient();
+
+ AsyncClient & operator=(const AsyncClient &other);
+ AsyncClient & operator+=(const AsyncClient &other);
+
+ bool operator==(const AsyncClient &other);
+
+ bool operator!=(const AsyncClient &other) {
+ return !(*this == other);
+ }
+ bool connect(IPAddress ip, uint16_t port);
+ bool connect(const char* host, uint16_t port);
+ void close(bool now = false);
+ void stop();
+ int8_t abort();
+ bool free();
+
+ bool canSend();//ack is not pending
+ size_t space();
+ size_t add(const char* data, size_t size, uint8_t apiflags=0);//add for sending
+ bool send();//send all data added with the method above
+ size_t ack(size_t len); //ack data that you have not acked using the method below
+ void ackLater(){ _ack_pcb = false; } //will not ack the current packet. Call from onData
+
+ size_t write(const char* data);
+ size_t write(const char* data, size_t size, uint8_t apiflags=0); //only when canSend() == true
+
+ uint8_t state();
+ bool connecting();
+ bool connected();
+ bool disconnecting();
+ bool disconnected();
+ bool freeable();//disconnected or disconnecting
+
+ uint16_t getMss();
+ uint32_t getRxTimeout();
+ void setRxTimeout(uint32_t timeout);//no RX data timeout for the connection in seconds
+ uint32_t getAckTimeout();
+ void setAckTimeout(uint32_t timeout);//no ACK timeout for the last sent packet in milliseconds
+ void setNoDelay(bool nodelay);
+ bool getNoDelay();
+ uint32_t getRemoteAddress();
+ uint16_t getRemotePort();
+ uint32_t getLocalAddress();
+ uint16_t getLocalPort();
+
+ IPAddress remoteIP();
+ uint16_t remotePort();
+ IPAddress localIP();
+ uint16_t localPort();
+
+ void onConnect(AcConnectHandler cb, void* arg = 0); //on successful connect
+ void onDisconnect(AcConnectHandler cb, void* arg = 0); //disconnected
+ void onAck(AcAckHandler cb, void* arg = 0); //ack received
+ void onError(AcErrorHandler cb, void* arg = 0); //unsuccessful connect or error
+ void onData(AcDataHandler cb, void* arg = 0); //data received
+ void onTimeout(AcTimeoutHandler cb, void* arg = 0); //ack timeout
+ void onPoll(AcConnectHandler cb, void* arg = 0); //every 125ms when connected
+
+ const char * errorToString(int8_t error);
+ const char * stateToString();
+
+ int8_t _recv(tcp_pcb* pcb, pbuf* pb, int8_t err);
+
+ static int8_t _s_poll(void *arg, struct tcp_pcb *tpcb);
+ static int8_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, int8_t err);
+ static void _s_error(void *arg, int8_t err);
+ static int8_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len);
+ static int8_t _s_connected(void* arg, void* tpcb, int8_t err);
+ static void _s_dns_found(const char *name, struct _ip_addr *ipaddr, void *arg);
+
+ bool _in_lwip_thread;
+};
+
+class AsyncServer {
+ protected:
+ uint16_t _port;
+ IPAddress _addr;
+ bool _noDelay;
+ bool _in_lwip_thread;
+ tcp_pcb* _pcb;
+ AcConnectHandler _connect_cb;
+ void* _connect_cb_arg;
+
+ public:
+
+ AsyncServer(IPAddress addr, uint16_t port);
+ AsyncServer(uint16_t port);
+ ~AsyncServer();
+ void onClient(AcConnectHandler cb, void* arg);
+ void begin();
+ void end();
+ void setNoDelay(bool nodelay);
+ bool getNoDelay();
+ uint8_t status();
+
+ static int8_t _s_accept(void *arg, tcp_pcb* newpcb, int8_t err);
+ protected:
+ int8_t _accept(tcp_pcb* newpcb, int8_t err);
+};
+
+
+#endif /* ASYNCTCP_H_ */
diff --git a/libraries/AsyncTCP/travis/common.sh b/libraries/AsyncTCP/travis/common.sh
new file mode 100644
index 00000000..57bede34
--- /dev/null
+++ b/libraries/AsyncTCP/travis/common.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+function build_sketches()
+{
+ local arduino=$1
+ local srcpath=$2
+ local platform=$3
+ local sketches=$(find $srcpath -name *.ino)
+ for sketch in $sketches; do
+ local sketchdir=$(dirname $sketch)
+ if [[ -f "$sketchdir/.$platform.skip" ]]; then
+ echo -e "\n\n ------------ Skipping $sketch ------------ \n\n";
+ continue
+ fi
+ echo -e "\n\n ------------ Building $sketch ------------ \n\n";
+ $arduino --verify $sketch;
+ local result=$?
+ if [ $result -ne 0 ]; then
+ echo "Build failed ($1)"
+ return $result
+ fi
+ done
+}
diff --git a/libraries/DHT_sensor_library_for_ESPx/DHTesp.cpp b/libraries/DHT_sensor_library_for_ESPx/DHTesp.cpp
new file mode 100644
index 00000000..49d6ff6d
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/DHTesp.cpp
@@ -0,0 +1,424 @@
+/******************************************************************
+ DHT Temperature & Humidity Sensor library for Arduino & ESP32.
+
+ Features:
+ - Support for DHT11 and DHT22/AM2302/RHT03
+ - Auto detect sensor model
+ - Very low memory footprint
+ - Very small code
+
+ https://github.com/beegee-tokyo/arduino-DHTesp
+
+ Written by Mark Ruys, mark@paracas.nl.
+ Updated to work with ESP32 by Bernd Giesecke, bernd@giesecke.tk
+
+ GNU General Public License, check LICENSE for more information.
+ All text above must be included in any redistribution.
+
+ Datasheets:
+ - http://www.micro4you.com/files/sensor/DHT11.pdf
+ - http://www.adafruit.com/datasheets/DHT22.pdf
+ - http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
+ - http://meteobox.tk/files/AM2302.pdf
+
+ Changelog:
+ 2013-06-10: Initial version
+ 2013-06-12: Refactored code
+ 2013-07-01: Add a resetTimer method
+ 2017-12-12: Added task switch disable
+ Added computeHeatIndex function from Adafruit DNT library
+ 2017-12-14: Added computeDewPoint function from idDHTLib Library
+ Added getComfortRatio function from libDHT Library
+ 2017-12-15: Added computePerception function
+ 2018-01-02: Added example for multiple sensors usage.
+ 2018-01-03: Added function getTempAndHumidity which returns temperature and humidity in one call.
+ 2018-01-03: Added retry in case the reading from the sensor fails with a timeout.
+ 2018-01-08: Added ESP8266 (and probably AVR) compatibility.
+ 2018-03-11: Updated DHT example
+******************************************************************/
+
+#include "DHTesp.h"
+
+void DHTesp::setup(uint8_t pin, DHT_MODEL_t model)
+{
+ DHTesp::pin = pin;
+ DHTesp::model = model;
+ DHTesp::resetTimer(); // Make sure we do read the sensor in the next readSensor()
+
+ if ( model == AUTO_DETECT) {
+ DHTesp::model = DHT22;
+ readSensor();
+ if ( error == ERROR_TIMEOUT ) {
+ DHTesp::model = DHT11;
+ // Warning: in case we auto detect a DHT11, you should wait at least 1000 msec
+ // before your first read request. Otherwise you will get a time out error.
+ }
+ }
+
+ //Set default comfort profile.
+
+ //In computing these constants the following reference was used
+ //http://epb.apogee.net/res/refcomf.asp
+ //It was simplified as 4 straight lines and added very little skew on
+ //the vertical lines (+0.1 on x for C,D)
+ //The for points used are(from top left, clock wise)
+ //A(30%, 30*C) B(70%, 26.2*C) C(70.1%, 20.55*C) D(30.1%, 22.22*C)
+ //On the X axis we have the rel humidity in % and on the Y axis the temperature in *C
+
+ //Too hot line AB
+ m_comfort.m_tooHot_m = -0.095;
+ m_comfort.m_tooHot_b = 32.85;
+ //Too humid line BC
+ m_comfort.m_tooHumid_m = -56.5;
+ m_comfort.m_tooHumid_b = 3981.2;
+ //Too cold line DC
+ m_comfort.m_tooCold_m = -0.04175;
+ m_comfort.m_tooHCold_b = 23.476675;
+ //Too dry line AD
+ m_comfort.m_tooDry_m = -77.8;
+ m_comfort.m_tooDry_b = 2364;
+}
+
+void DHTesp::resetTimer()
+{
+ DHTesp::lastReadTime = millis() - 3000;
+}
+
+float DHTesp::getHumidity()
+{
+ readSensor();
+ if ( error == ERROR_TIMEOUT ) { // Try a second time to read
+ readSensor();
+ }
+ return humidity;
+}
+
+float DHTesp::getTemperature()
+{
+ readSensor();
+ if ( error == ERROR_TIMEOUT ) { // Try a second time to read
+ readSensor();
+ }
+ return temperature;
+}
+
+TempAndHumidity DHTesp::getTempAndHumidity()
+{
+ readSensor();
+ if ( error == ERROR_TIMEOUT ) { // Try a second time to read
+ readSensor();
+ }
+ values.temperature = temperature;
+ values.humidity = humidity;
+ return values;
+}
+
+#ifndef OPTIMIZE_SRAM_SIZE
+
+const char* DHTesp::getStatusString()
+{
+ switch ( error ) {
+ case DHTesp::ERROR_TIMEOUT:
+ return "TIMEOUT";
+
+ case DHTesp::ERROR_CHECKSUM:
+ return "CHECKSUM";
+
+ default:
+ return "OK";
+ }
+}
+
+#else
+
+// At the expense of 26 bytes of extra PROGMEM, we save 11 bytes of
+// SRAM by using the following method:
+
+prog_char P_OK[] PROGMEM = "OK";
+prog_char P_TIMEOUT[] PROGMEM = "TIMEOUT";
+prog_char P_CHECKSUM[] PROGMEM = "CHECKSUM";
+
+const char *DHTesp::getStatusString() {
+ prog_char *c;
+ switch ( error ) {
+ case DHTesp::ERROR_CHECKSUM:
+ c = P_CHECKSUM; break;
+
+ case DHTesp::ERROR_TIMEOUT:
+ c = P_TIMEOUT; break;
+
+ default:
+ c = P_OK; break;
+ }
+
+ static char buffer[9];
+ strcpy_P(buffer, c);
+
+ return buffer;
+}
+
+#endif
+
+void DHTesp::readSensor()
+{
+ // Make sure we don't poll the sensor too often
+ // - Max sample rate DHT11 is 1 Hz (duty cicle 1000 ms)
+ // - Max sample rate DHT22 is 0.5 Hz (duty cicle 2000 ms)
+ unsigned long startTime = millis();
+ if ( (unsigned long)(startTime - lastReadTime) < (model == DHT11 ? 999L : 1999L) ) {
+ return;
+ }
+ lastReadTime = startTime;
+
+ temperature = NAN;
+ humidity = NAN;
+
+ uint16_t rawHumidity = 0;
+ uint16_t rawTemperature = 0;
+ uint16_t data = 0;
+
+ // Request sample
+ digitalWrite(pin, LOW); // Send start signal
+ pinMode(pin, OUTPUT);
+ if ( model == DHT11 ) {
+ delay(18);
+ }
+ else {
+ // This will fail for a DHT11 - that's how we can detect such a device
+ delayMicroseconds(800);
+ }
+
+ pinMode(pin, INPUT);
+ digitalWrite(pin, HIGH); // Switch bus to receive data
+
+ // We're going to read 83 edges:
+ // - First a FALLING, RISING, and FALLING edge for the start bit
+ // - Then 40 bits: RISING and then a FALLING edge per bit
+ // To keep our code simple, we accept any HIGH or LOW reading if it's max 85 usecs long
+
+#ifdef ESP32
+ // ESP32 is a multi core / multi processing chip
+ // It is necessary to disable task switches during the readings
+ portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
+ portENTER_CRITICAL(&mux);
+#else
+ cli();
+#endif
+ for ( int8_t i = -3 ; i < 2 * 40; i++ ) {
+ byte age;
+ startTime = micros();
+
+ do {
+ age = (unsigned long)(micros() - startTime);
+ if ( age > 90 ) {
+ error = ERROR_TIMEOUT;
+#ifdef ESP32
+ portEXIT_CRITICAL(&mux);
+#else
+ sei();
+#endif
+ return;
+ }
+ }
+ while ( digitalRead(pin) == (i & 1) ? HIGH : LOW );
+
+ if ( i >= 0 && (i & 1) ) {
+ // Now we are being fed our 40 bits
+ data <<= 1;
+
+ // A zero max 30 usecs, a one at least 68 usecs.
+ if ( age > 30 ) {
+ data |= 1; // we got a one
+ }
+ }
+
+ switch ( i ) {
+ case 31:
+ rawHumidity = data;
+ break;
+ case 63:
+ rawTemperature = data;
+ data = 0;
+ break;
+ }
+ }
+
+#ifdef ESP32
+ portEXIT_CRITICAL(&mux);
+#else
+ sei();
+#endif
+
+ // Verify checksum
+
+ if ( (byte)(((byte)rawHumidity) + (rawHumidity >> 8) + ((byte)rawTemperature) + (rawTemperature >> 8)) != data ) {
+ error = ERROR_CHECKSUM;
+ return;
+ }
+
+ // Store readings
+
+ if ( model == DHT11 ) {
+ humidity = rawHumidity >> 8;
+ temperature = rawTemperature >> 8;
+ }
+ else {
+ humidity = rawHumidity * 0.1;
+
+ if ( rawTemperature & 0x8000 ) {
+ rawTemperature = -(int16_t)(rawTemperature & 0x7FFF);
+ }
+ temperature = ((int16_t)rawTemperature) * 0.1;
+ }
+
+ error = ERROR_NONE;
+}
+
+//boolean isFahrenheit: True == Fahrenheit; False == Celcius
+float DHTesp::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) {
+ // Using both Rothfusz and Steadman's equations
+ // http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
+ float hi;
+
+ if (!isFahrenheit) {
+ temperature = toFahrenheit(temperature);
+ }
+
+ hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
+
+ if (hi > 79) {
+ hi = -42.379 +
+ 2.04901523 * temperature +
+ 10.14333127 * percentHumidity +
+ -0.22475541 * temperature*percentHumidity +
+ -0.00683783 * pow(temperature, 2) +
+ -0.05481717 * pow(percentHumidity, 2) +
+ 0.00122874 * pow(temperature, 2) * percentHumidity +
+ 0.00085282 * temperature*pow(percentHumidity, 2) +
+ -0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
+
+ if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0))
+ hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);
+
+ else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0))
+ hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
+ }
+
+ return isFahrenheit ? hi : toCelsius(hi);
+}
+
+//boolean isFahrenheit: True == Fahrenheit; False == Celcius
+float DHTesp::computeDewPoint(float temperature, float percentHumidity, bool isFahrenheit) {
+ // reference: http://wahiduddin.net/calc/density_algorithms.htm
+ if (isFahrenheit) {
+ temperature = toCelsius(temperature);
+ }
+ double A0 = 373.15 / (273.15 + (double) temperature);
+ double SUM = -7.90298 * (A0 - 1);
+ SUM += 5.02808 * log10(A0);
+ SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1 / A0))) - 1) ;
+ SUM += 8.1328e-3 * (pow(10, (-3.49149 * (A0 - 1))) - 1) ;
+ SUM += log10(1013.246);
+ double VP = pow(10, SUM - 3) * (double) percentHumidity;
+ double Td = log(VP / 0.61078); // temp var
+ Td = (241.88 * Td) / (17.558 - Td);
+ return isFahrenheit ? toFahrenheit(Td) : Td;
+}
+
+//boolean isFahrenheit: True == Fahrenheit; False == Celcius
+byte DHTesp::computePerception(float temperature, float percentHumidity, bool isFahrenheit) {
+ // Computing human perception from dew point
+ // reference: https://en.wikipedia.org/wiki/Dew_point ==> Relationship to human comfort
+ // reference: Horstmeyer, Steve (2006-08-15). "Relative Humidity....Relative to What? The Dew Point Temperature...a better approach". Steve Horstmeyer, Meteorologist, WKRC TV, Cincinnati, Ohio, USA. Retrieved 2009-08-20.
+ // Using table
+ // Return value Dew point Human perception[6]
+ // 7 Over 26 °C Severely high, even deadly for asthma related illnesses
+ // 6 24–26 °C Extremely uncomfortable, oppressive
+ // 5 21–24 °C Very humid, quite uncomfortable
+ // 4 18–21 °C Somewhat uncomfortable for most people at upper edge
+ // 3 16–18 °C OK for most, but all perceive the humidity at upper edge
+ // 2 13–16 °C Comfortable
+ // 1 10–12 °C Very comfortable
+ // 0 Under 10 °C A bit dry for some
+
+ if (isFahrenheit) {
+ temperature = toCelsius(temperature);
+ }
+ float dewPoint = computeDewPoint(temperature, percentHumidity);
+
+ if (dewPoint < 10.0f) {
+ return Perception_Dry;
+ } else if (dewPoint < 13.0f) {
+ return Perception_VeryComfy;
+ } else if (dewPoint < 16.0f) {
+ return Perception_Comfy;
+ } else if (dewPoint < 18.0f) {
+ return Perception_Ok;
+ } else if (dewPoint < 21.0f) {
+ return Perception_UnComfy;
+ } else if (dewPoint < 24.0f) {
+ return Perception_QuiteUnComfy;
+ } else if (dewPoint < 26.0f) {
+ return Perception_VeryUnComfy;
+ }
+ // else dew >= 26.0
+ return Perception_SevereUncomfy;
+}
+
+//boolean isFahrenheit: True == Fahrenheit; False == Celcius
+float DHTesp::getComfortRatio(ComfortState& destComfortStatus, float temperature, float percentHumidity, bool isFahrenheit) {
+ float ratio = 100; //100%
+ float distance = 0;
+ float kTempFactor = 3; //take into account the slope of the lines
+ float kHumidFactor = 0.1; //take into account the slope of the lines
+ uint8_t tempComfort = 0;
+
+ if (isFahrenheit) {
+ temperature = toCelsius(temperature);
+ }
+
+ destComfortStatus = Comfort_OK;
+
+ distance = m_comfort.distanceTooHot(temperature, percentHumidity);
+ if(distance > 0)
+ {
+ //update the comfort descriptor
+ tempComfort += (uint8_t)Comfort_TooHot;
+ //decrease the comfot ratio taking the distance into account
+ ratio -= distance * kTempFactor;
+ }
+
+ distance = m_comfort.distanceTooHumid(temperature, percentHumidity);
+ if(distance > 0)
+ {
+ //update the comfort descriptor
+ tempComfort += (uint8_t)Comfort_TooHumid;
+ //decrease the comfot ratio taking the distance into account
+ ratio -= distance * kHumidFactor;
+ }
+
+ distance = m_comfort.distanceTooCold(temperature, percentHumidity);
+ if(distance > 0)
+ {
+ //update the comfort descriptor
+ tempComfort += (uint8_t)Comfort_TooCold;
+ //decrease the comfot ratio taking the distance into account
+ ratio -= distance * kTempFactor;
+ }
+
+ distance = m_comfort.distanceTooDry(temperature, percentHumidity);
+ if(distance > 0)
+ {
+ //update the comfort descriptor
+ tempComfort += (uint8_t)Comfort_TooDry;
+ //decrease the comfot ratio taking the distance into account
+ ratio -= distance * kHumidFactor;
+ }
+
+ destComfortStatus = (ComfortState)tempComfort;
+
+ if(ratio < 0)
+ ratio = 0;
+
+ return ratio;
+}
diff --git a/libraries/DHT_sensor_library_for_ESPx/DHTesp.h b/libraries/DHT_sensor_library_for_ESPx/DHTesp.h
new file mode 100644
index 00000000..a062449a
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/DHTesp.h
@@ -0,0 +1,170 @@
+/******************************************************************
+ DHT Temperature & Humidity Sensor library for Arduino & ESP32.
+
+ Features:
+ - Support for DHT11 and DHT22/AM2302/RHT03
+ - Auto detect sensor model
+ - Very low memory footprint
+ - Very small code
+
+ https://github.com/beegee-tokyo/arduino-DHTesp
+
+ Written by Mark Ruys, mark@paracas.nl.
+ Updated to work with ESP32 by Bernd Giesecke, bernd@giesecke.tk
+
+ GNU General Public License, check LICENSE for more information.
+ All text above must be included in any redistribution.
+
+ Datasheets:
+ - http://www.micro4you.com/files/sensor/DHT11.pdf
+ - http://www.adafruit.com/datasheets/DHT22.pdf
+ - http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
+ - http://meteobox.tk/files/AM2302.pdf
+
+ Changelog:
+ 2013-06-10: Initial version
+ 2013-06-12: Refactored code
+ 2013-07-01: Add a resetTimer method
+ 2017-12-12: Added task switch disable
+ Added computeHeatIndex function from Adafruit DNT library
+ 2017-12-14: Added computeDewPoint function from idDHTLib Library
+ Added getComfortRatio function from libDHT Library
+ 2017-12-15: Added computePerception function
+ 2018-01-02: Added example for multiple sensors usage.
+ 2018-01-03: Added function getTempAndHumidity which returns temperature and humidity in one call.
+ 2018-01-03: Added retry in case the reading from the sensor fails with a timeout.
+ 2018-01-08: Added ESP8266 (and probably AVR) compatibility.
+ ******************************************************************/
+
+#ifndef dhtesp_h
+#define dhtesp_h
+
+#if ARDUINO < 100
+ #include
+#else
+ #include
+#endif
+
+// Reference: http://epb.apogee.net/res/refcomf.asp (References invalid)
+enum ComfortState {
+ Comfort_OK = 0,
+ Comfort_TooHot = 1,
+ Comfort_TooCold = 2,
+ Comfort_TooDry = 4,
+ Comfort_TooHumid = 8,
+ Comfort_HotAndHumid = 9,
+ Comfort_HotAndDry = 5,
+ Comfort_ColdAndHumid = 10,
+ Comfort_ColdAndDry = 6
+};
+
+// References https://en.wikipedia.org/wiki/Dew_point ==> Relationship to human comfort
+enum PerceptionState {
+ Perception_Dry = 0,
+ Perception_VeryComfy = 1,
+ Perception_Comfy = 2,
+ Perception_Ok = 3,
+ Perception_UnComfy = 4,
+ Perception_QuiteUnComfy = 5,
+ Perception_VeryUnComfy = 6,
+ Perception_SevereUncomfy = 7
+};
+
+struct TempAndHumidity {
+ float temperature;
+ float humidity;
+};
+
+struct ComfortProfile
+{
+ //Represent the 4 line equations:
+ //dry, humid, hot, cold, using the y = mx + b formula
+ float m_tooHot_m, m_tooHot_b;
+ float m_tooCold_m, m_tooHCold_b;
+ float m_tooDry_m, m_tooDry_b;
+ float m_tooHumid_m, m_tooHumid_b;
+
+ inline bool isTooHot(float temp, float humidity) {return (temp > (humidity * m_tooHot_m + m_tooHot_b));}
+ inline bool isTooHumid(float temp, float humidity) {return (temp > (humidity * m_tooHumid_m + m_tooHumid_b));}
+ inline bool isTooCold(float temp, float humidity) {return (temp < (humidity * m_tooCold_m + m_tooHCold_b));}
+ inline bool isTooDry(float temp, float humidity) {return (temp < (humidity * m_tooDry_m + m_tooDry_b));}
+
+ inline float distanceTooHot(float temp, float humidity) {return temp - (humidity * m_tooHot_m + m_tooHot_b);}
+ inline float distanceTooHumid(float temp, float humidity) {return temp - (humidity * m_tooHumid_m + m_tooHumid_b);}
+ inline float distanceTooCold(float temp, float humidity) {return (humidity * m_tooCold_m + m_tooHCold_b) - temp;}
+ inline float distanceTooDry(float temp, float humidity) {return (humidity * m_tooDry_m + m_tooDry_b) - temp;}
+};
+
+class DHTesp
+{
+public:
+
+ typedef enum {
+ AUTO_DETECT,
+ DHT11,
+ DHT22,
+ AM2302, // Packaged DHT22
+ RHT03 // Equivalent to DHT22
+ }
+ DHT_MODEL_t;
+
+ typedef enum {
+ ERROR_NONE = 0,
+ ERROR_TIMEOUT,
+ ERROR_CHECKSUM
+ }
+ DHT_ERROR_t;
+
+ TempAndHumidity values;
+
+ void setup(uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);
+ void resetTimer();
+
+ float getTemperature();
+ float getHumidity();
+ TempAndHumidity getTempAndHumidity();
+
+ DHT_ERROR_t getStatus() { return error; };
+ const char* getStatusString();
+
+ DHT_MODEL_t getModel() { return model; }
+
+ int getMinimumSamplingPeriod() { return model == DHT11 ? 1000 : 2000; }
+
+ int8_t getNumberOfDecimalsTemperature() { return model == DHT11 ? 0 : 1; };
+ int8_t getLowerBoundTemperature() { return model == DHT11 ? 0 : -40; };
+ int8_t getUpperBoundTemperature() { return model == DHT11 ? 50 : 125; };
+
+ int8_t getNumberOfDecimalsHumidity() { return 0; };
+ int8_t getLowerBoundHumidity() { return model == DHT11 ? 20 : 0; };
+ int8_t getUpperBoundHumidity() { return model == DHT11 ? 90 : 100; };
+
+ static float toFahrenheit(float fromCelcius) { return 1.8 * fromCelcius + 32.0; };
+ static float toCelsius(float fromFahrenheit) { return (fromFahrenheit - 32.0) / 1.8; };
+
+ float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=false);
+ float computeDewPoint(float temperature, float percentHumidity, bool isFahrenheit=false);
+ float getComfortRatio(ComfortState& destComfStatus, float temperature, float percentHumidity, bool isFahrenheit=false);
+ ComfortProfile getComfortProfile() {return m_comfort;}
+ void setComfortProfile(ComfortProfile& c) {m_comfort = c;}
+ inline bool isTooHot(float temp, float humidity) {return m_comfort.isTooHot(temp, humidity);}
+ inline bool isTooHumid(float temp, float humidity) {return m_comfort.isTooHumid(temp, humidity);}
+ inline bool isTooCold(float temp, float humidity) {return m_comfort.isTooCold(temp, humidity);}
+ inline bool isTooDry(float temp, float humidity) {return m_comfort.isTooDry(temp, humidity);}
+ byte computePerception(float temperature, float percentHumidity, bool isFahrenheit=false);
+protected:
+ void readSensor();
+
+ float temperature;
+ float humidity;
+
+ uint8_t pin;
+
+private:
+ DHT_MODEL_t model;
+ DHT_ERROR_t error;
+ unsigned long lastReadTime;
+ ComfortProfile m_comfort;
+};
+
+#endif /*dhtesp_h*/
diff --git a/gpl.txt b/libraries/DHT_sensor_library_for_ESPx/LICENSE
similarity index 99%
rename from gpl.txt
rename to libraries/DHT_sensor_library_for_ESPx/LICENSE
index 94a9ed02..30ace6a8 100644
--- a/gpl.txt
+++ b/libraries/DHT_sensor_library_for_ESPx/LICENSE
@@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
-
- Copyright (C)
+ {one line to give the program's name and a brief idea of what it does.}
+ Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
- Copyright (C)
+ {project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
-.
+.
\ No newline at end of file
diff --git a/libraries/DHT_sensor_library_for_ESPx/README.md b/libraries/DHT_sensor_library_for_ESPx/README.md
new file mode 100644
index 00000000..e51edcf9
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/README.md
@@ -0,0 +1,149 @@
+DHTesp
+===
+
+An Arduino library for reading the DHT family of temperature and humidity sensors.
+Forked from [arduino-DHT](https://github.com/markruys/arduino-DHT)
+Original written by Mark Ruys, .
+
+Why did I clone this library instead of forking the original repo and push the changes?
+When I searched through Github for DHT libraries, I found a lot of them, some of them offers additional functions, some of them only basic temperature and humidity values. I wanted to combine all interesting functions into one library. In addition, none of the DHT libraries I found were written to work without errors on the ESP32. For ESP32 (a multi core/ multi processing SOC) task switching must be disabled while reading data from the sensor.
+Another problem I found is that many of the available libraries use the same naming (dht.h, dht.cpp), which easily leads to conflicts if different libraries are used for different platforms.
+
+The library is tested as well on ESP8266 and should work on AVR boards as well.
+
+Changes to the original library:
+--------
+- 2017-12-12: Renamed DHT class to DHTesp and filenames from dht.* to DHTesp.* to avoid conflicts with other libraries - beegee-tokyo, .
+- 2017-12-12: Updated to work with ESP32 - beegee-tokyo, .
+- 2017-12-12: Added function computeHeatIndex. Reference: [Adafruit DHT library](https://github.com/adafruit/DHT-sensor-library).
+- 2017-12-14: Added function computeDewPoint. Reference: [idDHTLib](https://github.com/niesteszeck/idDHTLib).
+- 2017-12-14: Added function getComfortRatio. Reference: [libDHT](https://github.com/ADiea/libDHT). (References about Human Comfort invalid)
+- 2017-12-15: Added function computePerception. Reference: [WikiPedia Dew point==> Relationship to human comfort](https://en.wikipedia.org/wiki/Dew_point) - beegee-tokyo, .
+- 2018-01-02: Added example for multiple sensors usage.
+- 2018-01-03: Added function getTempAndHumidity which returns temperature and humidity in one call.
+- 2018-01-03: Added retry in case the reading from the sensor fails with a timeout.
+- 2018-01-08: Added ESP8266 (and probably AVR) compatibility.
+- 2018-03-11: Updated DHT example
+Features
+--------
+ - Support for DHT11 and DHT22, AM2302, RHT03
+ - Auto detect sensor model
+ - Determine heat index
+ - Determine dewpoint
+ - Determine thermal comfort:
+ * Empiric comfort function based on comfort profiles(parametric lines)
+ * Multiple comfort profiles possible. Default based on http://epb.apogee.net/res/refcomf.asp (References invalid)
+ * Determine if it's too cold, hot, humid, dry, based on current comfort profile
+ * More info at [Determining Thermal Comfort Using a Humidity and Temperature Sensor](https://www.azosensors.com/article.aspx?ArticleID=487)
+ - Determine human perception based on humidity, temperature and dew point according to Horstmeyer, Steve (2006-08-15). [Relative Humidity....Relative to What? The Dew Point Temperature...a better approach](http://www.shorstmeyer.com/wxfaqs/humidity/humidity.html)
+
+Functions
+-----
+_**`void setup(uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);`**_
+- Call to initialize the interface, define the GPIO pin to which the sensor is connected and define the sensor type. Valid sensor types are:
+ - AUTO_DETECT Try to detect which sensor is connected
+ - DHT11
+ - DHT22
+ - AM2302 Packaged DHT22
+ - RHT03 Equivalent to DHT22
+
+_**`void resetTimer();`**_
+- Reset last time the sensor was read
+
+_**`float getTemperature();`**_
+- Get the temperature in degree Centigrade from the sensor
+Either one of _`getTemperature()`_ or _`getHumidity()`_ or _`getTempAndHumidity()`_ initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
+See example _`DHT_ESP32.ino`_ or _`DHT_Test.ino`_
+
+_**`float getHumidity();`**_
+- Get the humidity from the sensor
+Either one of _`getTemperature()`_ or _`getHumidity()`_ or _`getTempAndHumidity()`_ initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
+See example _`DHT_ESP32.ino`_ or _`DHT_Test.ino`_
+
+_**`TempAndHumidity getTempAndHumidity();`**_
+- Get the temperature and humidity from the sensor
+Either one of _`getTemperature()`_ or _`getHumidity()`_ or _`getTempAndHumidity()`_ initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
+Return value is a struct of type _`TempAndHumidity`_ with temperature and humidity as float values.
+See example _`DHT_Multi.ino`_
+
+_**`DHT_ERROR_t getStatus();`**_
+- Get last error if reading from the sensor failed. Possible values are:
+ - ERROR_NONE no error occured
+ - ERROR_TIMEOUT timeout reading from the sensor
+ - ERROR_CHECKSUM checksum of received values doesn't match
+
+_**`const char* getStatusString();`**_
+- Get last error as a char *
+
+_**`DHT_MODEL_t getModel()`**_
+- Get detected (or defined) sensor type
+
+_**`int getMinimumSamplingPeriod();`**_
+- Get minimmum possible sampling period. For DHT11 this is 1000ms, for other sensors it is 2000ms
+
+_**`int8_t getNumberOfDecimalsTemperature();`**_
+- Get number of decimals in the temperature value. For DHT11 this is 0, for other sensors it is 1
+
+_**`int8_t getLowerBoundTemperature();`**_
+- Get lower temperature range of the sensor. For DHT11 this is 0 degree Centigrade, for other sensors this is -40 degree Centrigrade
+
+_**`int8_t getUpperBoundTemperature();`**_
+- Get upper temperature range of the sensor. For DHT11 this is 50 degree Centigrade, for other sensors this is 125 degree Centrigrade
+
+_**`int8_t getNumberOfDecimalsHumidity();`**_
+- Get number of decimals in the humidity value. This is always 0.
+
+_**`int8_t getLowerBoundHumidity();`**_
+- Get lower humidity range of the sensor. For DHT11 this is 20 percent, for other sensors this is 0 percent
+
+_**`int8_t getUpperBoundHumidity();`**_
+- Get upper temperature range of the sensor. For DHT11 this is 90 percent, for other sensors this is 100 percent
+
+_**`static float toFahrenheit(float fromCelcius);`**_
+- Convert Centrigrade value to Fahrenheit value
+
+_**`static float toCelsius(float fromFahrenheit) { return (fromFahrenheit - 32.0) / 1.8; };`**_
+- Convert Fahrenheit value to Centigrade value
+
+_**`float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=false);`**_
+- Compute the heat index. Default temperature is in Centrigrade.
+
+_**`float computeDewPoint(float temperature, float percentHumidity, bool isFahrenheit=false);`**_
+- Compute the dew point. Default temperature is in Centrigrade.
+
+_**`float getComfortRatio(ComfortState& destComfStatus, float temperature, float percentHumidity, bool isFahrenheit=false);`**_
+- Compute the comfort ratio. Default temperature is in Centrigrade. Return values:
+0 -> OK
+1 -> Too Hot
+2 -> Too cold
+4 -> Too dry
+8 -> Too humid
+9 -> Hot and humid
+5 -> Hot and dry
+10 -> Cold and humid
+6 -> Cold and dry
+
+_**`byte computePerception(float temperature, float percentHumidity, bool isFahrenheit=false);`**_
+- Compute the human perception. Default temperature is in Centrigrade. Return values:
+0 -> Dry
+1 -> Very comfortable
+2 -> Comfortable
+3 -> Ok
+4 -> Uncomfortable
+5 -> Quite uncomfortable
+6 -> Very uncomfortable
+7 -> Severe uncomfortable
+
+Usage
+-----
+See [examples](https://github.com/beegee-tokyo/DHTesp/blob/master/examples). For all the options, see [dhtesp.h](https://github.com/beegee-tokyo/DHTesp/blob/master/DHTesp.h).
+
+Installation
+------------
+
+In Arduino IDE open Sketch->Include Library->Manage Libraries then search for _**DHT ESP**_
+In PlatformIO open PlatformIO Home, switch to libraries and search for _**DHT ESP32**_. Or install the library in the terminal with _**`platformio lib install 2029`**_
+
+For manual installation [download](https://github.com/beegee-tokyo/DHTesp/archive/master.zip) the archive, unzip it and place the DHTesp folder into the library directory.
+In Arduino IDE this is usually _**`/libraries/`**_
+In PlatformIO this is usually _**``**_
diff --git a/libraries/DHT_sensor_library_for_ESPx/examples/DHT_ESP32/DHT_ESP32.ino b/libraries/DHT_sensor_library_for_ESPx/examples/DHT_ESP32/DHT_ESP32.ino
new file mode 100644
index 00000000..282bbaa1
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/examples/DHT_ESP32/DHT_ESP32.ino
@@ -0,0 +1,172 @@
+#include "DHTesp.h"
+#include "ESP32Ticker.h"
+
+/**************************************************************/
+/* Example how to read DHT sensors from an ESP32 using multi- */
+/* tasking. */
+/* This example depends on the ESP32Ticker library to wake up */
+/* the task every 20 seconds */
+/* Please install Ticker-esp32 library first */
+/* bertmelis/Ticker-esp32 */
+/* https://github.com/bertmelis/Ticker-esp32 */
+/**************************************************************/
+
+DHTesp dht;
+
+void tempTask(void *pvParameters);
+bool getTemperature();
+void triggerGetTemp();
+
+/** Task handle for the light value read task */
+TaskHandle_t tempTaskHandle = NULL;
+/** Ticker for temperature reading */
+Ticker tempTicker;
+/** Comfort profile */
+ComfortState cf;
+/** Flag if task should run */
+bool tasksEnabled = false;
+/** Pin number for DHT11 data pin */
+int dhtPin = 17;
+
+/**
+ * initTemp
+ * Setup DHT library
+ * Setup task and timer for repeated measurement
+ * @return bool
+ * true if task and timer are started
+ * false if task or timer couldn't be started
+ */
+bool initTemp() {
+ byte resultValue = 0;
+ // Initialize temperature sensor
+ dht.setup(dhtPin, DHTesp::DHT11);
+ Serial.println("DHT initiated");
+
+ // Start task to get temperature
+ xTaskCreatePinnedToCore(
+ tempTask, /* Function to implement the task */
+ "tempTask ", /* Name of the task */
+ 4000, /* Stack size in words */
+ NULL, /* Task input parameter */
+ 5, /* Priority of the task */
+ &tempTaskHandle, /* Task handle. */
+ 1); /* Core where the task should run */
+
+ if (tempTaskHandle == NULL) {
+ Serial.println("Failed to start task for temperature update");
+ return false;
+ } else {
+ // Start update of environment data every 20 seconds
+ tempTicker.attach(20, triggerGetTemp);
+ }
+ return true;
+}
+
+/**
+ * triggerGetTemp
+ * Sets flag dhtUpdated to true for handling in loop()
+ * called by Ticker getTempTimer
+ */
+void triggerGetTemp() {
+ if (tempTaskHandle != NULL) {
+ xTaskResumeFromISR(tempTaskHandle);
+ }
+}
+
+/**
+ * Task to reads temperature from DHT11 sensor
+ * @param pvParameters
+ * pointer to task parameters
+ */
+void tempTask(void *pvParameters) {
+ Serial.println("tempTask loop started");
+ while (1) // tempTask loop
+ {
+ if (tasksEnabled) {
+ // Get temperature values
+ getTemperature();
+ }
+ // Got sleep again
+ vTaskSuspend(NULL);
+ }
+}
+
+/**
+ * getTemperature
+ * Reads temperature from DHT11 sensor
+ * @return bool
+ * true if temperature could be aquired
+ * false if aquisition failed
+*/
+bool getTemperature() {
+ // Reading temperature for humidity takes about 250 milliseconds!
+ // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
+ TempAndHumidity newValues = dht.getTempAndHumidity();
+ // Check if any reads failed and exit early (to try again).
+ if (dht.getStatus() != 0) {
+ Serial.println("DHT11 error status: " + String(dht.getStatusString()));
+ return false;
+ }
+
+ float heatIndex = dht.computeHeatIndex(newValues.temperature, newValues.humidity);
+ float dewPoint = dht.computeDewPoint(newValues.temperature, newValues.humidity);
+ float cr = dht.getComfortRatio(cf, newValues.temperature, newValues.humidity);
+
+ String comfortStatus;
+ switch(cf) {
+ case Comfort_OK:
+ comfortStatus = "Comfort_OK";
+ break;
+ case Comfort_TooHot:
+ comfortStatus = "Comfort_TooHot";
+ break;
+ case Comfort_TooCold:
+ comfortStatus = "Comfort_TooCold";
+ break;
+ case Comfort_TooDry:
+ comfortStatus = "Comfort_TooDry";
+ break;
+ case Comfort_TooHumid:
+ comfortStatus = "Comfort_TooHumid";
+ break;
+ case Comfort_HotAndHumid:
+ comfortStatus = "Comfort_HotAndHumid";
+ break;
+ case Comfort_HotAndDry:
+ comfortStatus = "Comfort_HotAndDry";
+ break;
+ case Comfort_ColdAndHumid:
+ comfortStatus = "Comfort_ColdAndHumid";
+ break;
+ case Comfort_ColdAndDry:
+ comfortStatus = "Comfort_ColdAndDry";
+ break;
+ default:
+ comfortStatus = "Unknown:";
+ break;
+ };
+
+ Serial.println(" T:" + String(newValues.temperature) + " H:" + String(newValues.humidity) + " I:" + String(heatIndex) + " D:" + String(dewPoint) + " " + comfortStatus);
+ return true;
+}
+
+void setup()
+{
+ Serial.begin(115200);
+ Serial.println();
+ Serial.println("DHT ESP32 example with tasks");
+ initTemp();
+}
+
+void loop() {
+ if (!tasksEnabled) {
+ // Wait 2 seconds to let system settle down
+ delay(2000);
+ // Enable task that will read values from the DHT sensor
+ tasksEnabled = true;
+ if (tempTaskHandle != NULL) {
+ vTaskResume(tempTaskHandle);
+ }
+ }
+ yield();
+}
diff --git a/libraries/DHT_sensor_library_for_ESPx/examples/DHT_Multi/DHT_Multi.ino b/libraries/DHT_sensor_library_for_ESPx/examples/DHT_Multi/DHT_Multi.ino
new file mode 100644
index 00000000..75997f19
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/examples/DHT_Multi/DHT_Multi.ino
@@ -0,0 +1,119 @@
+#include
+
+#include "ESP32Ticker.h"
+#include "DHTesp.h"
+
+/** Initialize DHT sensor 1 */
+DHTesp dhtSensor1;
+/** Initialize DHT sensor 2 */
+DHTesp dhtSensor2;
+/** Initialize DHT sensor 3 */
+DHTesp dhtSensor3;
+/** Task handle for the light value read task */
+TaskHandle_t tempTaskHandle = NULL;
+/** Pin number for DHT11 1 data pin */
+int dhtPin1 = 17;
+/** Pin number for DHT11 2 data pin */
+int dhtPin2 = 16;
+/** Pin number for DHT11 3 data pin */
+int dhtPin3 = 27;
+/** Ticker for temperature reading */
+Ticker tempTicker;
+/** Flags for temperature readings finished */
+bool gotNewTemperature = false;
+/** Data from sensor 1 */
+TempAndHumidity sensor1Data;
+/** Data from sensor 2 */
+TempAndHumidity sensor2Data;
+/** Data from sensor 3 */
+TempAndHumidity sensor3Data;
+
+/* Flag if main loop is running */
+bool tasksEnabled = false;
+
+/**
+
+/**
+ * Task to reads temperature from DHT11 sensor
+ * @param pvParameters
+ * pointer to task parameters
+ */
+void tempTask(void *pvParameters) {
+ Serial.println("tempTask loop started");
+ while (1) // tempTask loop
+ {
+ if (tasksEnabled && !gotNewTemperature) { // Read temperature only if old data was processed already
+ // Reading temperature for humidity takes about 250 milliseconds!
+ // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
+ sensor1Data = dhtSensor1.getTempAndHumidity(); // Read values from sensor 1
+ sensor2Data = dhtSensor2.getTempAndHumidity(); // Read values from sensor 1
+ sensor3Data = dhtSensor3.getTempAndHumidity(); // Read values from sensor 1
+ gotNewTemperature = true;
+ }
+ vTaskSuspend(NULL);
+ }
+}
+
+/**
+ * triggerGetTemp
+ * Sets flag dhtUpdated to true for handling in loop()
+ * called by Ticker tempTicker
+ */
+void triggerGetTemp() {
+ if (tempTaskHandle != NULL) {
+ xTaskResumeFromISR(tempTaskHandle);
+ }
+}
+
+/**
+ * Arduino setup function (called once after boot/reboot)
+ */
+void setup() {
+ Serial.begin(115200);
+ Serial.println("Example for 3 DHT11/22 sensors");
+
+ // Initialize temperature sensor 1
+ dhtSensor1.setup(dhtPin1, DHTesp::DHT11);
+ // Initialize temperature sensor 2
+ dhtSensor2.setup(dhtPin2, DHTesp::DHT11);
+ // Initialize temperature sensor 3
+ dhtSensor3.setup(dhtPin3, DHTesp::DHT11);
+
+ // Start task to get temperature
+ xTaskCreatePinnedToCore(
+ tempTask, /* Function to implement the task */
+ "tempTask ", /* Name of the task */
+ 4000, /* Stack size in words */
+ NULL, /* Task input parameter */
+ 5, /* Priority of the task */
+ &tempTaskHandle, /* Task handle. */
+ 1); /* Core where the task should run */
+
+ if (tempTaskHandle == NULL) {
+ Serial.println("[ERROR] Failed to start task for temperature update");
+ } else {
+ // Start update of environment data every 30 seconds
+ tempTicker.attach(30, triggerGetTemp);
+ }
+
+ // Signal end of setup() to tasks
+ tasksEnabled = true;
+} // End of setup.
+
+
+/**
+ * loop
+ * Arduino loop function, called once 'setup' is complete (your own code
+ * should go here)
+ */
+void loop() {
+ if (gotNewTemperature) {
+ Serial.println("Sensor 1 data:");
+ Serial.println("Temp: " + String(sensor1Data.temperature,2) + "'C Humidity: " + String(sensor1Data.humidity,1) + "%");
+ Serial.println("Sensor 2 data:");
+ Serial.println("Temp: " + String(sensor2Data.temperature,2) + "'C Humidity: " + String(sensor2Data.humidity,1) + "%");
+ Serial.println("Sensor 3 data:");
+ Serial.println("Temp: " + String(sensor3Data.temperature,2) + "'C Humidity: " + String(sensor3Data.humidity,1) + "%");
+ gotNewTemperature = false;
+ }
+} // End of loop
diff --git a/libraries/DHT_sensor_library_for_ESPx/examples/DHT_Test/DHT_Test.ino b/libraries/DHT_sensor_library_for_ESPx/examples/DHT_Test/DHT_Test.ino
new file mode 100644
index 00000000..a374e460
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/examples/DHT_Test/DHT_Test.ino
@@ -0,0 +1,38 @@
+#include "DHTesp.h"
+
+DHTesp dht;
+
+void setup()
+{
+ Serial.begin(115200);
+ Serial.println();
+ Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)\tHeatIndex (C)\t(F)");
+
+ dht.setup(22); // Connect DHT sensor to GPIO 17
+}
+
+void loop()
+{
+
+ //delay(dht.getMinimumSamplingPeriod()*1.2);
+ static uint32_t last_dht_update= 0;
+ uint32_t now_dht = millis();
+ if (now_dht - last_dht_update > dht.getMinimumSamplingPeriod() *1.2) {
+ last_dht_update = now_dht;
+ float humidity = dht.getHumidity();
+ float temperature = dht.getTemperature();
+
+ Serial.print(dht.getStatusString());
+ Serial.print("\t H:");
+ Serial.print(humidity, 1);
+ Serial.print("%\t\T :");
+ Serial.print(temperature, 1);
+ Serial.println("C\t\t");
+ //Serial.print(dht.toFahrenheit(temperature), 1);
+ //Serial.print("\t\t");
+ //Serial.print(dht.computeHeatIndex(temperature, humidity, false), 1);
+ //Serial.print("\t\t");
+ //Serial.println(dht.computeHeatIndex(dht.toFahrenheit(temperature), humidity, true), 1);
+ }
+}
+
diff --git a/libraries/DHT_sensor_library_for_ESPx/keywords.txt b/libraries/DHT_sensor_library_for_ESPx/keywords.txt
new file mode 100644
index 00000000..953f244b
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/keywords.txt
@@ -0,0 +1,79 @@
+#######################################
+# Syntax Coloring Map For DHTesp
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+DHTesp KEYWORD1
+TempAndHumidity KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+setup KEYWORD2
+getTemperature KEYWORD2
+getHumidity KEYWORD2
+getTempAndHumidity KEYWORD2
+getStatus KEYWORD2
+getStatusString KEYWORD2
+getModel KEYWORD2
+getMinimumSamplingPeriod KEYWORD2
+toFahrenheit KEYWORD2
+toCelsius KEYWORD2
+computeHeatIndex KEYWORD2
+computeDewPoint KEYWORD2
+getComfortRatio KEYWORD2
+getNumberOfDecimalsTemperature KEYWORD2
+getLowerBoundTemperature KEYWORD2
+getUpperBoundTemperature KEYWORD2
+getNumberOfDecimalsHumidity KEYWORD2
+getLowerBoundHumidity KEYWORD2
+getUpperBoundHumidity KEYWORD2
+getComfortProfile KEYWORD2
+setComfortProfile KEYWORD2
+isTooHot KEYWORD2
+isTooHumid KEYWORD2
+isTooCold KEYWORD2
+isTooDry KEYWORD2
+computePerception KEYWORD2
+
+#######################################
+# Instances (KEYWORD2)
+#######################################
+
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+
+AUTO_DETECT LITERAL1
+DHT11 LITERAL1
+DHT22 LITERAL1
+AM2302 LITERAL1
+RHT03 LITERAL1
+
+ERROR_NONE LITERAL1
+ERROR_TIMEOUT LITERAL1
+ERROR_CHECKSUM LITERAL1
+
+Comfort_OK LITERAL1
+Comfort_TooHot LITERAL1
+Comfort_TooCold LITERAL1
+Comfort_TooDry LITERAL1
+Comfort_TooHumid LITERAL1
+Comfort_HotAndHumid LITERAL1
+Comfort_HotAndDry LITERAL1
+Comfort_ColdAndHumid LITERAL1
+Comfort_ColdAndDry LITERAL1
+
+Perception_Dry LITERAL1
+Perception_VeryComfy LITERAL1
+Perception_Comfy LITERAL1
+Perception_Ok LITERAL1
+Perception_UnComfy LITERAL1
+Perception_QuiteUnComfy LITERAL1
+Perception_UnComfy LITERAL1
+Perception_VeryUncomfy LITERAL1
diff --git a/libraries/DHT_sensor_library_for_ESPx/library.json b/libraries/DHT_sensor_library_for_ESPx/library.json
new file mode 100644
index 00000000..a9d7f27b
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/library.json
@@ -0,0 +1,15 @@
+{
+ "name": "DHT sensor library for ESPx",
+ "keywords": "onewire, 1-wire, bus, sensor, temperature",
+ "description": "Arduino ESP library for DHT11, DHT22, etc Temp & Humidity Sensors. Last changes: Updated example.",
+ "repository":
+ {
+ "type": "git",
+ "url": "https://github.com/beegee-tokyo/DHTesp.git"
+ },
+ "version": "1.0.6",
+ "frameworks": "arduino",
+ "platforms": "*",
+ "license": "GPL-3.0-only",
+ "homepage": "http://desire.giesecke.tk/index.php/2018/01/30/esp32-dht11/"
+}
diff --git a/libraries/DHT_sensor_library_for_ESPx/library.properties b/libraries/DHT_sensor_library_for_ESPx/library.properties
new file mode 100644
index 00000000..84d28855
--- /dev/null
+++ b/libraries/DHT_sensor_library_for_ESPx/library.properties
@@ -0,0 +1,10 @@
+name=DHT sensor library for ESPx
+version=1.0.6
+author=beegee_tokyo
+maintainer=beegee_tokyo
+sentence=Arduino ESP library for DHT11, DHT22, etc Temp & Humidity Sensors
+paragraph=Optimized libray to match ESP32 requirements. Last changes: Updated example.
+category=Sensors
+url=http://desire.giesecke.tk/index.php/2018/01/30/esp32-dht11/
+architectures=esp8266,esp32,arduino-esp32
+includes=DHTesp.h
diff --git a/libraries/ESP32SSDP/ESP32SSDP.cpp b/libraries/ESP32SSDP/ESP32SSDP.cpp
new file mode 100644
index 00000000..866cce57
--- /dev/null
+++ b/libraries/ESP32SSDP/ESP32SSDP.cpp
@@ -0,0 +1,442 @@
+/*
+ESP32 Simple Service Discovery
+Copyright (c) 2015 Hristo Gochkov
+
+Original (Arduino) version by Filippo Sallemi, July 23, 2014.
+Can be found at: https://github.com/nomadnt/uSSDP
+
+License (MIT license):
+ 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, sublicense, and/or sell
+ copies of the Software, and 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.
+
+*/
+
+#include
+#include "ESP32SSDP.h"
+#include "WiFiUdp.h"
+#include
+
+//#define DEBUG_SSDP Serial
+
+#define SSDP_INTERVAL 1200
+#define SSDP_PORT 1900
+#define SSDP_METHOD_SIZE 10
+#define SSDP_URI_SIZE 2
+#define SSDP_BUFFER_SIZE 64
+#define SSDP_MULTICAST_TTL 2
+static const IPAddress SSDP_MULTICAST_ADDR(239, 255, 255, 250);
+
+
+
+static const char _ssdp_response_template[] PROGMEM =
+ "HTTP/1.1 200 OK\r\n"
+ "EXT:\r\n";
+
+static const char _ssdp_notify_template[] PROGMEM =
+ "NOTIFY * HTTP/1.1\r\n"
+ "HOST: 239.255.255.250:1900\r\n"
+ "NTS: ssdp:alive\r\n";
+
+static const char _ssdp_packet_template[] PROGMEM =
+ "%s" // _ssdp_response_template / _ssdp_notify_template
+ "CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
+ "SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
+ "USN: uuid:%s\r\n" // _uuid
+ "%s: %s\r\n" // "NT" or "ST", _deviceType
+ "LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
+ "\r\n";
+
+static const char _ssdp_schema_template[] PROGMEM =
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/xml\r\n"
+ "Connection: close\r\n"
+ "Access-Control-Allow-Origin: *\r\n"
+ "\r\n"
+ ""
+ ""
+ ""
+ "1 "
+ "0 "
+ " "
+ "http://%u.%u.%u.%u:%u/ " // WiFi.localIP(), _port
+ ""
+ "%s "
+ "%s "
+ "%s "
+ "%s "
+ "%s "
+ "%s "
+ "%s "
+ "%s "
+ "%s "
+ "uuid:%s "
+ " "
+// ""
+// ""
+// "image/png "
+// "48 "
+// "48 "
+// "24 "
+// "icon48.png "
+// " "
+// ""
+// "image/png "
+// "120 "
+// "120 "
+// "24 "
+// "icon120.png "
+// " "
+// " "
+ " \r\n"
+ "\r\n";
+
+struct SSDPTimer {
+ ETSTimer timer;
+};
+
+SSDPClass::SSDPClass() :
+_server(0),
+_timer(new SSDPTimer),
+_port(80),
+_ttl(SSDP_MULTICAST_TTL),
+_respondToPort(0),
+_pending(false),
+_delay(0),
+_process_time(0),
+_notify_time(0)
+{
+ _uuid[0] = '\0';
+ _modelNumber[0] = '\0';
+ sprintf(_deviceType, "urn:schemas-upnp-org:device:Basic:1");
+ _friendlyName[0] = '\0';
+ _presentationURL[0] = '\0';
+ _serialNumber[0] = '\0';
+ _modelName[0] = '\0';
+ _modelURL[0] = '\0';
+ _manufacturer[0] = '\0';
+ _manufacturerURL[0] = '\0';
+ sprintf(_schemaURL, "ssdp/schema.xml");
+}
+
+SSDPClass::~SSDPClass(){
+ delete _timer;
+}
+
+
+bool SSDPClass::begin(){
+ _pending = false;
+
+ uint32_t chipId = ((uint16_t) (ESP.getEfuseMac() >> 32));
+ sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
+ (uint16_t) ((chipId >> 16) & 0xff),
+ (uint16_t) ((chipId >> 8) & 0xff),
+ (uint16_t) chipId & 0xff );
+
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid);
+#endif
+
+ if (_server) {
+ delete (_server);
+ _server = 0;
+ }
+
+ _server = new WiFiUDP;
+
+ if (!(_server->beginMulticast(IPAddress(SSDP_MULTICAST_ADDR), SSDP_PORT))) {
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.println("Error begin");
+#endif
+ return false;
+ }
+
+ _startTimer();
+
+ return true;
+}
+
+void SSDPClass::_send(ssdp_method_t method){
+ char buffer[1460];
+ IPAddress ip = WiFi.localIP();
+
+ char valueBuffer[strlen_P(_ssdp_notify_template)+1];
+ strcpy_P(valueBuffer, (method == NONE)?_ssdp_response_template:_ssdp_notify_template);
+
+ int len = snprintf_P(buffer, sizeof(buffer),
+ _ssdp_packet_template,
+ valueBuffer,
+ SSDP_INTERVAL,
+ _modelName, _modelNumber,
+ _uuid,
+ (method == NONE)?"ST":"NT",
+ _deviceType,
+ ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
+ );
+
+ IPAddress remoteAddr;
+ uint16_t remotePort;
+ if(method == NONE) {
+ remoteAddr = _respondToAddr;
+ remotePort = _respondToPort;
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.print("Sending Response to ");
+#endif
+ } else {
+ remoteAddr = IPAddress(SSDP_MULTICAST_ADDR);
+ remotePort = SSDP_PORT;
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.println("Sending Notify to ");
+#endif
+ }
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.print(remoteAddr);
+ DEBUG_SSDP.print(":");
+ DEBUG_SSDP.println(remotePort);
+#endif
+ _server->beginPacket(remoteAddr, remotePort);
+ _server->println(buffer);
+ _server->endPacket();
+}
+
+void SSDPClass::schema(WiFiClient client){
+ IPAddress ip = WiFi.localIP();
+ char buffer[strlen_P(_ssdp_schema_template)+1];
+ strcpy_P(buffer, _ssdp_schema_template);
+ client.printf(buffer,
+ ip[0], ip[1], ip[2], ip[3], _port,
+ _deviceType,
+ _friendlyName,
+ _presentationURL,
+ _serialNumber,
+ _modelName,
+ _modelNumber,
+ _modelURL,
+ _manufacturer,
+ _manufacturerURL,
+ _uuid
+ );
+}
+
+void SSDPClass::_update(){
+ int nbBytes =0;
+ char * packetBuffer = NULL;
+
+ if(!_pending && _server) {
+ ssdp_method_t method = NONE;
+ nbBytes= _server->parsePacket();
+ typedef enum {METHOD, URI, PROTO, KEY, VALUE, ABORT} states;
+ states state = METHOD;
+ typedef enum {START, MAN, ST, MX} headers;
+ headers header = START;
+
+ uint8_t cursor = 0;
+ uint8_t cr = 0;
+
+ char buffer[SSDP_BUFFER_SIZE] = {0};
+ packetBuffer = new char[nbBytes +1];
+ int message_size=_server->read(packetBuffer,nbBytes);
+ int process_pos = 0;
+ packetBuffer[message_size]='\0';
+ _respondToAddr = _server->remoteIP();
+ _respondToPort = _server->remotePort();
+#ifdef DEBUG_SSDP
+ if (message_size) {
+ DEBUG_SSDP.println("****************************************************");
+ DEBUG_SSDP.println(_server->remoteIP());
+ DEBUG_SSDP.println(packetBuffer);
+ DEBUG_SSDP.println("****************************************************");
+ }
+#endif
+ while(process_pos < message_size){
+
+ char c = packetBuffer[process_pos];
+ process_pos++;
+ (c == '\r' || c == '\n') ? cr++ : cr = 0;
+#ifdef DEBUG_SSDP
+ if ((c == '\r' || c == '\n') && (cr < 2)) DEBUG_SSDP.println(buffer);
+#endif
+ switch(state){
+ case METHOD:
+ if(c == ' '){
+ if(strcmp(buffer, "M-SEARCH") == 0) method = SEARCH;
+
+ if(method == NONE) state = ABORT;
+ else state = URI;
+ cursor = 0;
+
+ } else if(cursor < SSDP_METHOD_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; }
+ break;
+ case URI:
+ if(c == ' '){
+ if(strcmp(buffer, "*")) state = ABORT;
+ else state = PROTO;
+ cursor = 0;
+ } else if(cursor < SSDP_URI_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; }
+ break;
+ case PROTO:
+ if(cr == 2){ state = KEY; cursor = 0; }
+ break;
+ case KEY:
+ if(cr == 4){ _pending = true; _process_time = millis(); }
+ else if(c == ' '){ cursor = 0; state = VALUE; }
+ else if(c != '\r' && c != '\n' && c != ':' && cursor < SSDP_BUFFER_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; }
+ break;
+ case VALUE:
+ if(cr == 2){
+ switch(header){
+ case START:
+ break;
+ case MAN:
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.printf("MAN: %s\n", (char *)buffer);
+#endif
+ break;
+ case ST:
+ if(strcmp(buffer, "ssdp:all")){
+ state = ABORT;
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.printf("REJECT: %s\n", (char *)buffer);
+#endif
+ }
+ // if the search type matches our type, we should respond instead of ABORT
+ if(strcasecmp(buffer, _deviceType) == 0){
+ _pending = true;
+ _process_time = 0;
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.println("the search type matches our type");
+#endif
+ state = KEY;
+ }
+ break;
+ case MX:
+ _delay = random(0, atoi(buffer)) * 1000L;
+ break;
+ }
+
+ if(state != ABORT){ state = KEY; header = START; cursor = 0; }
+ } else if(c != '\r' && c != '\n'){
+ if(header == START){
+ if(strncmp(buffer, "MA", 2) == 0) header = MAN;
+ else if(strcmp(buffer, "ST") == 0) header = ST;
+ else if(strcmp(buffer, "MX") == 0) header = MX;
+ }
+
+ if(cursor < SSDP_BUFFER_SIZE - 1){ buffer[cursor++] = c; buffer[cursor] = '\0'; }
+ }
+ break;
+ case ABORT:
+ _pending = false; _delay = 0;
+ break;
+ }
+ }
+ }
+ if(packetBuffer) delete packetBuffer;
+ if(_pending && (millis() - _process_time) > _delay){
+ _pending = false; _delay = 0;
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.println("Send None");
+#endif
+ _send(NONE);
+ } else if(_notify_time == 0 || (millis() - _notify_time) > (SSDP_INTERVAL * 1000L)){
+ _notify_time = millis();
+ #ifdef DEBUG_SSDP
+ DEBUG_SSDP.println("Send Notify");
+#endif
+ _send(NOTIFY);
+ } else {
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.println("Do not sent");
+#endif
+ }
+
+ if (_pending) {
+ _server->flush();
+ }
+
+}
+
+void SSDPClass::setSchemaURL(const char *url){
+ strlcpy(_schemaURL, url, sizeof(_schemaURL));
+}
+
+void SSDPClass::setHTTPPort(uint16_t port){
+ _port = port;
+}
+
+void SSDPClass::setDeviceType(const char *deviceType){
+ strlcpy(_deviceType, deviceType, sizeof(_deviceType));
+}
+
+void SSDPClass::setName(const char *name){
+ strlcpy(_friendlyName, name, sizeof(_friendlyName));
+}
+
+void SSDPClass::setURL(const char *url){
+ strlcpy(_presentationURL, url, sizeof(_presentationURL));
+}
+
+void SSDPClass::setSerialNumber(const char *serialNumber){
+ strlcpy(_serialNumber, serialNumber, sizeof(_serialNumber));
+}
+
+void SSDPClass::setSerialNumber(const uint32_t serialNumber){
+ snprintf(_serialNumber, sizeof(uint32_t)*2+1, "%08X", serialNumber);
+}
+
+void SSDPClass::setModelName(const char *name){
+ strlcpy(_modelName, name, sizeof(_modelName));
+}
+
+void SSDPClass::setModelNumber(const char *num){
+ strlcpy(_modelNumber, num, sizeof(_modelNumber));
+}
+
+void SSDPClass::setModelURL(const char *url){
+ strlcpy(_modelURL, url, sizeof(_modelURL));
+}
+
+void SSDPClass::setManufacturer(const char *name){
+ strlcpy(_manufacturer, name, sizeof(_manufacturer));
+}
+
+void SSDPClass::setManufacturerURL(const char *url){
+ strlcpy(_manufacturerURL, url, sizeof(_manufacturerURL));
+}
+
+void SSDPClass::setTTL(const uint8_t ttl){
+ _ttl = ttl;
+}
+
+void SSDPClass::_onTimerStatic(SSDPClass* self) {
+#ifdef DEBUG_SSDP
+ DEBUG_SSDP.println("Update");
+#endif
+ self->_update();
+}
+
+void SSDPClass::_startTimer() {
+ ETSTimer* tm = &(_timer->timer);
+ const int interval = 1000;
+ ets_timer_disarm(tm);
+ ets_timer_setfn(tm, reinterpret_cast(&SSDPClass::_onTimerStatic), reinterpret_cast(this));
+ ets_timer_arm(tm, interval, 1 /* repeat */);
+}
+
+#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
+SSDPClass SSDP;
+#endif
diff --git a/libraries/ESP32SSDP/ESP32SSDP.h b/libraries/ESP32SSDP/ESP32SSDP.h
new file mode 100644
index 00000000..e9017baa
--- /dev/null
+++ b/libraries/ESP32SSDP/ESP32SSDP.h
@@ -0,0 +1,126 @@
+/*
+ESP32 Simple Service Discovery
+Copyright (c) 2015 Hristo Gochkov
+
+Original (Arduino) version by Filippo Sallemi, July 23, 2014.
+Can be found at: https://github.com/nomadnt/uSSDP
+
+License (MIT license):
+ 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, sublicense, and/or sell
+ copies of the Software, and 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.
+
+*/
+
+#ifndef ESP32SSDP_H
+#define ESP32SSDP_H
+
+#include
+#include
+#include
+
+#define SSDP_UUID_SIZE 37
+#define SSDP_SCHEMA_URL_SIZE 64
+#define SSDP_DEVICE_TYPE_SIZE 64
+#define SSDP_FRIENDLY_NAME_SIZE 64
+#define SSDP_SERIAL_NUMBER_SIZE 32
+#define SSDP_PRESENTATION_URL_SIZE 128
+#define SSDP_MODEL_NAME_SIZE 64
+#define SSDP_MODEL_URL_SIZE 128
+#define SSDP_MODEL_VERSION_SIZE 32
+#define SSDP_MANUFACTURER_SIZE 64
+#define SSDP_MANUFACTURER_URL_SIZE 128
+
+typedef enum {
+ NONE,
+ SEARCH,
+ NOTIFY
+} ssdp_method_t;
+
+
+struct SSDPTimer;
+
+class SSDPClass{
+ public:
+ SSDPClass();
+ ~SSDPClass();
+
+ bool begin();
+
+ void schema(WiFiClient client);
+
+ void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
+ void setDeviceType(const char *deviceType);
+ void setName(const String& name) { setName(name.c_str()); }
+ void setName(const char *name);
+ void setURL(const String& url) { setURL(url.c_str()); }
+ void setURL(const char *url);
+ void setSchemaURL(const String& url) { setSchemaURL(url.c_str()); }
+ void setSchemaURL(const char *url);
+ void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); }
+ void setSerialNumber(const char *serialNumber);
+ void setSerialNumber(const uint32_t serialNumber);
+ void setModelName(const String& name) { setModelName(name.c_str()); }
+ void setModelName(const char *name);
+ void setModelNumber(const String& num) { setModelNumber(num.c_str()); }
+ void setModelNumber(const char *num);
+ void setModelURL(const String& url) { setModelURL(url.c_str()); }
+ void setModelURL(const char *url);
+ void setManufacturer(const String& name) { setManufacturer(name.c_str()); }
+ void setManufacturer(const char *name);
+ void setManufacturerURL(const String& url) { setManufacturerURL(url.c_str()); }
+ void setManufacturerURL(const char *url);
+ void setHTTPPort(uint16_t port);
+ void setTTL(uint8_t ttl);
+
+ protected:
+ void _send(ssdp_method_t method);
+ void _update();
+ void _startTimer();
+ static void _onTimerStatic(SSDPClass* self);
+
+ WiFiUDP *_server;
+ SSDPTimer* _timer;
+ uint16_t _port;
+ uint8_t _ttl;
+
+ IPAddress _respondToAddr;
+ uint16_t _respondToPort;
+
+ bool _pending;
+ unsigned short _delay;
+ unsigned long _process_time;
+ unsigned long _notify_time;
+
+ char _schemaURL[SSDP_SCHEMA_URL_SIZE];
+ char _uuid[SSDP_UUID_SIZE];
+ char _deviceType[SSDP_DEVICE_TYPE_SIZE];
+ char _friendlyName[SSDP_FRIENDLY_NAME_SIZE];
+ char _serialNumber[SSDP_SERIAL_NUMBER_SIZE];
+ char _presentationURL[SSDP_PRESENTATION_URL_SIZE];
+ char _manufacturer[SSDP_MANUFACTURER_SIZE];
+ char _manufacturerURL[SSDP_MANUFACTURER_URL_SIZE];
+ char _modelName[SSDP_MODEL_NAME_SIZE];
+ char _modelURL[SSDP_MODEL_URL_SIZE];
+ char _modelNumber[SSDP_MODEL_VERSION_SIZE];
+};
+
+#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
+extern SSDPClass SSDP;
+#endif
+
+#endif
diff --git a/libraries/ESP32SSDP/README.rst b/libraries/ESP32SSDP/README.rst
new file mode 100644
index 00000000..b2c92c75
--- /dev/null
+++ b/libraries/ESP32SSDP/README.rst
@@ -0,0 +1,22 @@
+ESP32 Simple Service Discovery Copyright (c) 2015 Hristo Gochkov
+Original (Arduino) version by Filippo Sallemi, July 23, 2014. Can be
+found at: https://github.com/nomadnt/uSSDP
+
+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, sublicense, and/or sell copies of the Software, and 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.
diff --git a/libraries/ESP32SSDP/examples/SSDP/SSDP.ino b/libraries/ESP32SSDP/examples/SSDP/SSDP.ino
new file mode 100644
index 00000000..8014a3a5
--- /dev/null
+++ b/libraries/ESP32SSDP/examples/SSDP/SSDP.ino
@@ -0,0 +1,51 @@
+#include
+#include
+#include
+
+const char* ssid = "********";
+const char* password = "********";
+
+WebServer HTTP(80);
+
+void setup() {
+ Serial.begin(115200);
+ Serial.println();
+ Serial.println("Starting WiFi...");
+
+ WiFi.mode(WIFI_STA);
+ WiFi.begin(ssid, password);
+ if(WiFi.waitForConnectResult() == WL_CONNECTED){
+
+ Serial.printf("Starting HTTP...\n");
+ HTTP.on("/index.html", HTTP_GET, [](){
+ HTTP.send(200, "text/plain", "Hello World!");
+ });
+ HTTP.on("/description.xml", HTTP_GET, [](){
+ SSDP.schema(HTTP.client());
+ });
+ HTTP.begin();
+
+ Serial.printf("Starting SSDP...\n");
+ SSDP.setSchemaURL("description.xml");
+ SSDP.setHTTPPort(80);
+ SSDP.setName("Philips hue clone");
+ SSDP.setSerialNumber("001788102201");
+ SSDP.setURL("index.html");
+ SSDP.setModelName("Philips hue bridge 2012");
+ SSDP.setModelNumber("929000226503");
+ SSDP.setModelURL("http://www.meethue.com");
+ SSDP.setManufacturer("Royal Philips Electronics");
+ SSDP.setManufacturerURL("http://www.philips.com");
+ SSDP.begin();
+
+ Serial.printf("Ready!\n");
+ } else {
+ Serial.printf("WiFi Failed\n");
+ while(1) delay(100);
+ }
+}
+
+void loop() {
+ HTTP.handleClient();
+ delay(1);
+}
diff --git a/libraries/ESP32SSDP/keywords.txt b/libraries/ESP32SSDP/keywords.txt
new file mode 100644
index 00000000..241d3414
--- /dev/null
+++ b/libraries/ESP32SSDP/keywords.txt
@@ -0,0 +1,53 @@
+#######################################
+# Syntax Coloring Map For Ultrasound
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+ESP8266SSDP KEYWORD1
+SSDP KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+begin KEYWORD2
+schema KEYWORD2
+setName KEYWORD2
+setURL KEYWORD2
+setHTTPPort KEYWORD2
+setSchemaURL KEYWORD2
+setSerialNumber KEYWORD2
+setModelName KEYWORD2
+setModelNumber KEYWORD2
+setModelURL KEYWORD2
+setManufacturer KEYWORD2
+setManufacturerURL KEYWORD2
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+SSDP_INTERVAL LITERAL1
+SSDP_PORT LITERAL1
+SSDP_METHOD_SIZE LITERAL1
+SSDP_URI_SIZE LITERAL1
+SSDP_BUFFER_SIZE LITERAL1
+SSDP_BASE_SIZE LITERAL1
+SSDP_FRIENDLY_NAME_SIZE LITERAL1
+SSDP_SERIAL_NUMBER_SIZE LITERAL1
+SSDP_PRESENTATION_URL_SIZE LITERAL1
+SSDP_MODEL_NAME_SIZE LITERAL1
+SSDP_MODEL_URL_SIZE LITERAL1
+SSDP_MODEL_VERSION_SIZE LITERAL1
+SSDP_MANUFACTURER_SIZE LITERAL1
+SSDP_MANUFACTURER_URL_SIZE LITERAL1
+SEARCH LITERAL1
+NOTIFY LITERAL1
+BASIC LITERAL1
+MANAGEABLE LITERAL1
+SOLARPROTECTIONBLIND LITERAL1
+DIGITALSECURITYCAMERA LITERAL1
+HVAC LITERAL1
+LIGHTINGCONTROL LITERAL1
diff --git a/libraries/ESP32SSDP/library.properties b/libraries/ESP32SSDP/library.properties
new file mode 100644
index 00000000..e37cd254
--- /dev/null
+++ b/libraries/ESP32SSDP/library.properties
@@ -0,0 +1,9 @@
+name=ESP32SSPD
+version=1.0
+author=Me-No-Dev
+maintainer=Me-No-Dev
+sentence=Simple SSDP library for ESP32
+paragraph=Only for ESP32
+category=Communication
+url=
+architectures=esp32
diff --git a/libraries/ESPAsyncTCP/.gitignore b/libraries/ESPAsyncTCP/.gitignore
new file mode 100644
index 00000000..9bea4330
--- /dev/null
+++ b/libraries/ESPAsyncTCP/.gitignore
@@ -0,0 +1,2 @@
+
+.DS_Store
diff --git a/libraries/ESPAsyncTCP/.travis.yml b/libraries/ESPAsyncTCP/.travis.yml
new file mode 100644
index 00000000..89808806
--- /dev/null
+++ b/libraries/ESPAsyncTCP/.travis.yml
@@ -0,0 +1,37 @@
+sudo: false
+language: bash
+os:
+ - linux
+
+script:
+ - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
+ - sleep 3
+ - export DISPLAY=:1.0
+ - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
+ - tar xf arduino-1.6.5-linux64.tar.xz
+ - mv arduino-1.6.5 $HOME/arduino_ide
+ - export PATH="$HOME/arduino_ide:$PATH"
+ - which arduino
+ - mkdir -p $HOME/Arduino/libraries
+ - cp -r $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/ESPAsyncTCP
+ - cd $HOME/arduino_ide/hardware
+ - mkdir esp8266com
+ - cd esp8266com
+ - git clone https://github.com/esp8266/Arduino.git esp8266
+ - cd esp8266/tools
+ - python get.py
+ - source $TRAVIS_BUILD_DIR/travis/common.sh
+ - arduino --board esp8266com:esp8266:generic --save-prefs
+ - arduino --get-pref sketchbook.path
+ - build_sketches arduino $HOME/Arduino/libraries/ESPAsyncTCP esp8266
+
+notifications:
+ email:
+ on_success: change
+ on_failure: change
+ webhooks:
+ urls:
+ - https://webhooks.gitter.im/e/60e65d0c78ea0a920347
+ on_success: change # options: [always|never|change] default: always
+ on_failure: always # options: [always|never|change] default: always
+ on_start: false # default: false
diff --git a/libraries/ESPAsyncTCP/LICENSE.txt b/libraries/ESPAsyncTCP/LICENSE.txt
new file mode 100644
index 00000000..65c5ca88
--- /dev/null
+++ b/libraries/ESPAsyncTCP/LICENSE.txt
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/libraries/ESPAsyncTCP/README.md b/libraries/ESPAsyncTCP/README.md
new file mode 100644
index 00000000..2c48453c
--- /dev/null
+++ b/libraries/ESPAsyncTCP/README.md
@@ -0,0 +1,30 @@
+# ESPAsyncTCP [](https://travis-ci.org/me-no-dev/ESPAsyncTCP)
+Async TCP Library for ESP8266 Arduino
+
+For ESP32 look [HERE](https://github.com/me-no-dev/AsyncTCP)
+
+[](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+
+This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP8266 MCUs.
+
+This library is the base for [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer)
+
+## AsyncClient and AsyncServer
+The base classes on which everything else is built. They expose all possible scenarios, but are really raw and require more skills to use.
+
+## AsyncPrinter
+This class can be used to send data like any other ```Print``` interface (```Serial``` for example).
+The object then can be used outside of the Async callbacks (the loop) and receive asynchronously data using ```onData```. The object can be checked if the underlying ```AsyncClient```is connected, or hook to the ```onDisconnect``` callback.
+
+## AsyncTCPbuffer
+This class is really similar to the ```AsyncPrinter```, but it differs in the fact that it can buffer some of the incoming data.
+
+## SyncClient
+It is exactly what it sounds like. This is a standard, blocking TCP Client, similar to the one included in ```ESP8266WiFi```
+
+## Libraries and projects that use AsyncTCP
+- [ESP Async Web Server](https://github.com/me-no-dev/ESPAsyncWebServer)
+- [Async MQTT client](https://github.com/marvinroger/async-mqtt-client)
+- [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets)
+- [ESP8266 Smart Home](https://github.com/baruch/esp8266_smart_home)
+- [KBox Firmware](https://github.com/sarfata/kbox-firmware)
diff --git a/libraries/ESPAsyncTCP/examples/SyncClient/.esp31b.skip b/libraries/ESPAsyncTCP/examples/SyncClient/.esp31b.skip
new file mode 100644
index 00000000..e69de29b
diff --git a/libraries/ESPAsyncTCP/examples/SyncClient/SyncClient.ino b/libraries/ESPAsyncTCP/examples/SyncClient/SyncClient.ino
new file mode 100644
index 00000000..6ecc5255
--- /dev/null
+++ b/libraries/ESPAsyncTCP/examples/SyncClient/SyncClient.ino
@@ -0,0 +1,54 @@
+#ifdef ESP8266
+#include
+#include
+#include
+#else
+#include
+#endif
+#include "ESPAsyncTCP.h"
+#include "SyncClient.h"
+
+const char* ssid = "**********";
+const char* password = "************";
+
+void setup(){
+ Serial.begin(115200);
+ WiFi.begin(ssid, password);
+ if (WiFi.waitForConnectResult() != WL_CONNECTED) {
+ Serial.printf("WiFi Failed!\n");
+ return;
+ }
+ Serial.printf("WiFi Connected!\n");
+ Serial.println(WiFi.localIP());
+#ifdef ESP8266
+ ArduinoOTA.begin();
+#endif
+
+ SyncClient client;
+ if(!client.connect("www.google.com", 80)){
+ Serial.println("Connect Failed");
+ return;
+ }
+ client.setTimeout(2);
+ if(client.printf("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n") > 0){
+ while(client.connected() && client.available() == 0){
+ delay(1);
+ }
+ while(client.available()){
+ Serial.write(client.read());
+ }
+ if(client.connected()){
+ client.stop();
+ }
+ } else {
+ client.stop();
+ Serial.println("Send Failed");
+ while(client.connected()) delay(0);
+ }
+}
+
+void loop(){
+#ifdef ESP8266
+ ArduinoOTA.handle();
+#endif
+}
diff --git a/libraries/ESPAsyncTCP/library.json b/libraries/ESPAsyncTCP/library.json
new file mode 100644
index 00000000..71d9da77
--- /dev/null
+++ b/libraries/ESPAsyncTCP/library.json
@@ -0,0 +1,19 @@
+{
+ "name":"ESPAsyncTCP",
+ "description":"Asynchronous TCP Library for ESP8266",
+ "keywords":"async,tcp",
+ "authors":
+ {
+ "name": "Hristo Gochkov",
+ "maintainer": true
+ },
+ "repository":
+ {
+ "type": "git",
+ "url": "https://github.com/me-no-dev/ESPAsyncTCP.git"
+ },
+ "version": "1.1.1",
+ "license": "LGPL-3.0",
+ "frameworks": "arduino",
+ "platforms":"espressif8266"
+}
diff --git a/libraries/ESPAsyncTCP/library.properties b/libraries/ESPAsyncTCP/library.properties
new file mode 100644
index 00000000..9330e4d6
--- /dev/null
+++ b/libraries/ESPAsyncTCP/library.properties
@@ -0,0 +1,9 @@
+name=ESP AsyncTCP
+version=1.1.0
+author=Me-No-Dev
+maintainer=Me-No-Dev
+sentence=Async TCP Library for ESP8266 and ESP31B
+paragraph=Async TCP Library for ESP8266 and ESP31B
+category=Other
+url=https://github.com/me-no-dev/ESPAsyncTCP
+architectures=*
diff --git a/libraries/ESPAsyncTCP/src/AsyncPrinter.cpp b/libraries/ESPAsyncTCP/src/AsyncPrinter.cpp
new file mode 100644
index 00000000..dd61e764
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/AsyncPrinter.cpp
@@ -0,0 +1,187 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "AsyncPrinter.h"
+
+AsyncPrinter::AsyncPrinter()
+ : _client(NULL)
+ , _data_cb(NULL)
+ , _data_arg(NULL)
+ , _close_cb(NULL)
+ , _close_arg(NULL)
+ , _tx_buffer(NULL)
+ , _tx_buffer_size(1460)
+ , next(NULL)
+{}
+
+AsyncPrinter::AsyncPrinter(AsyncClient *client, size_t txBufLen)
+ : _client(client)
+ , _data_cb(NULL)
+ , _data_arg(NULL)
+ , _close_cb(NULL)
+ , _close_arg(NULL)
+ , _tx_buffer(NULL)
+ , _tx_buffer_size(txBufLen)
+ , next(NULL)
+{
+ _attachCallbacks();
+ _tx_buffer = new cbuf(_tx_buffer_size);
+}
+
+AsyncPrinter::~AsyncPrinter(){
+ _on_close();
+}
+
+void AsyncPrinter::onData(ApDataHandler cb, void *arg){
+ _data_cb = cb;
+ _data_arg = arg;
+}
+
+void AsyncPrinter::onClose(ApCloseHandler cb, void *arg){
+ _close_cb = cb;
+ _close_arg = arg;
+}
+
+int AsyncPrinter::connect(IPAddress ip, uint16_t port){
+ if(_client != NULL && connected())
+ return 0;
+ _client = new AsyncClient();
+ _client->onConnect([](void *obj, AsyncClient *c){ ((AsyncPrinter*)(obj))->_onConnect(c); }, this);
+ if(_client->connect(ip, port)){
+ while(_client->state() < 4)
+ delay(1);
+ return connected();
+ }
+ return 0;
+}
+
+int AsyncPrinter::connect(const char *host, uint16_t port){
+ if(_client != NULL && connected())
+ return 0;
+ _client = new AsyncClient();
+ _client->onConnect([](void *obj, AsyncClient *c){ ((AsyncPrinter*)(obj))->_onConnect(c); }, this);
+ if(_client->connect(host, port)){
+ while(_client->state() < 4)
+ delay(1);
+ return connected();
+ }
+ return 0;
+}
+
+void AsyncPrinter::_onConnect(AsyncClient *c){
+ if(_tx_buffer != NULL){
+ cbuf *b = _tx_buffer;
+ _tx_buffer = NULL;
+ delete b;
+ }
+ _tx_buffer = new cbuf(_tx_buffer_size);
+ _attachCallbacks();
+}
+
+AsyncPrinter::operator bool(){ return connected(); }
+
+AsyncPrinter & AsyncPrinter::operator=(const AsyncPrinter &other){
+ if(_client != NULL){
+ _client->close(true);
+ _client = NULL;
+ }
+ _tx_buffer_size = other._tx_buffer_size;
+ if(_tx_buffer != NULL){
+ cbuf *b = _tx_buffer;
+ _tx_buffer = NULL;
+ delete b;
+ }
+ _tx_buffer = new cbuf(other._tx_buffer_size);
+ _client = other._client;
+ _attachCallbacks();
+ return *this;
+}
+
+size_t AsyncPrinter::write(uint8_t data){
+ return write(&data, 1);
+}
+
+size_t AsyncPrinter::write(const uint8_t *data, size_t len){
+ if(_tx_buffer == NULL || !connected())
+ return 0;
+ size_t toWrite = 0;
+ size_t toSend = len;
+ while(_tx_buffer->room() < toSend){
+ toWrite = _tx_buffer->room();
+ _tx_buffer->write((const char*)data, toWrite);
+ while(!_client->canSend())
+ delay(0);
+ _sendBuffer();
+ toSend -= toWrite;
+ }
+ _tx_buffer->write((const char*)(data+(len - toSend)), toSend);
+ while(!_client->canSend()) delay(0);
+ _sendBuffer();
+ return len;
+}
+
+bool AsyncPrinter::connected(){
+ return (_client != NULL && _client->connected());
+}
+
+void AsyncPrinter::close(){
+ if(_client != NULL)
+ _client->close(true);
+}
+
+size_t AsyncPrinter::_sendBuffer(){
+ size_t available = _tx_buffer->available();
+ if(!connected() || !_client->canSend() || available == 0)
+ return 0;
+ size_t sendable = _client->space();
+ if(sendable < available)
+ available= sendable;
+ char *out = new char[available];
+ _tx_buffer->read(out, available);
+ size_t sent = _client->write(out, available);
+ delete out;
+ return sent;
+}
+
+void AsyncPrinter::_onData(void *data, size_t len){
+ if(_data_cb)
+ _data_cb(_data_arg, this, (uint8_t*)data, len);
+}
+
+void AsyncPrinter::_on_close(){
+ if(_client != NULL){
+ _client = NULL;
+ }
+ if(_tx_buffer != NULL){
+ cbuf *b = _tx_buffer;
+ _tx_buffer = NULL;
+ delete b;
+ }
+ if(_close_cb)
+ _close_cb(_close_arg, this);
+}
+
+void AsyncPrinter::_attachCallbacks(){
+ _client->onPoll([](void *obj, AsyncClient* c){ ((AsyncPrinter*)(obj))->_sendBuffer(); }, this);
+ _client->onAck([](void *obj, AsyncClient* c, size_t len, uint32_t time){ ((AsyncPrinter*)(obj))->_sendBuffer(); }, this);
+ _client->onDisconnect([](void *obj, AsyncClient* c){ ((AsyncPrinter*)(obj))->_on_close(); delete c; }, this);
+ _client->onData([](void *obj, AsyncClient* c, void *data, size_t len){ ((AsyncPrinter*)(obj))->_onData(data, len); }, this);
+}
diff --git a/libraries/ESPAsyncTCP/src/AsyncPrinter.h b/libraries/ESPAsyncTCP/src/AsyncPrinter.h
new file mode 100644
index 00000000..1fa0f8bd
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/AsyncPrinter.h
@@ -0,0 +1,73 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef ASYNCPRINTER_H_
+#define ASYNCPRINTER_H_
+
+#include "Arduino.h"
+#include "ESPAsyncTCP.h"
+#include "cbuf.h"
+
+class AsyncPrinter;
+
+typedef std::function ApDataHandler;
+typedef std::function ApCloseHandler;
+
+class AsyncPrinter: public Print {
+ private:
+ AsyncClient *_client;
+ ApDataHandler _data_cb;
+ void *_data_arg;
+ ApCloseHandler _close_cb;
+ void *_close_arg;
+ cbuf *_tx_buffer;
+ size_t _tx_buffer_size;
+
+ void _onConnect(AsyncClient *c);
+ public:
+ AsyncPrinter *next;
+
+ AsyncPrinter();
+ AsyncPrinter(AsyncClient *client, size_t txBufLen = 1460);
+ virtual ~AsyncPrinter();
+
+ int connect(IPAddress ip, uint16_t port);
+ int connect(const char *host, uint16_t port);
+
+ void onData(ApDataHandler cb, void *arg);
+ void onClose(ApCloseHandler cb, void *arg);
+
+ operator bool();
+ AsyncPrinter & operator=(const AsyncPrinter &other);
+
+ size_t write(uint8_t data);
+ size_t write(const uint8_t *data, size_t len);
+
+ bool connected();
+ void close();
+
+ size_t _sendBuffer();
+ void _onData(void *data, size_t len);
+ void _on_close();
+ void _attachCallbacks();
+};
+
+#endif /* ASYNCPRINTER_H_ */
diff --git a/libraries/ESPAsyncTCP/src/ESPAsyncTCP.cpp b/libraries/ESPAsyncTCP/src/ESPAsyncTCP.cpp
new file mode 100644
index 00000000..593d6d6b
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/ESPAsyncTCP.cpp
@@ -0,0 +1,1066 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "Arduino.h"
+
+#include "ESPAsyncTCP.h"
+extern "C"{
+ #include "lwip/opt.h"
+ #include "lwip/tcp.h"
+ #include "lwip/inet.h"
+ #include "lwip/dns.h"
+ #include "lwip/init.h"
+}
+#include
+
+/*
+ Async TCP Client
+*/
+
+#if ASYNC_TCP_SSL_ENABLED
+AsyncClient::AsyncClient(tcp_pcb* pcb, SSL_CTX * ssl_ctx):
+#else
+AsyncClient::AsyncClient(tcp_pcb* pcb):
+#endif
+ _connect_cb(0)
+ , _connect_cb_arg(0)
+ , _discard_cb(0)
+ , _discard_cb_arg(0)
+ , _sent_cb(0)
+ , _sent_cb_arg(0)
+ , _error_cb(0)
+ , _error_cb_arg(0)
+ , _recv_cb(0)
+ , _recv_cb_arg(0)
+ , _timeout_cb(0)
+ , _timeout_cb_arg(0)
+ , _pcb_busy(false)
+#if ASYNC_TCP_SSL_ENABLED
+ , _pcb_secure(false)
+ , _handshake_done(true)
+#endif
+ , _pcb_sent_at(0)
+ , _close_pcb(false)
+ , _ack_pcb(true)
+ , _tx_unacked_len(0)
+ , _tx_acked_len(0)
+ , _tx_unsent_len(0)
+ , _rx_last_packet(0)
+ , _rx_since_timeout(0)
+ , _ack_timeout(ASYNC_MAX_ACK_TIME)
+ , _connect_port(0)
+ , prev(NULL)
+ , next(NULL)
+{
+ _pcb = pcb;
+ if(_pcb){
+ _rx_last_packet = millis();
+ tcp_setprio(_pcb, TCP_PRIO_MIN);
+ tcp_arg(_pcb, this);
+ tcp_recv(_pcb, &_s_recv);
+ tcp_sent(_pcb, &_s_sent);
+ tcp_err(_pcb, &_s_error);
+ tcp_poll(_pcb, &_s_poll, 1);
+#if ASYNC_TCP_SSL_ENABLED
+ if(ssl_ctx){
+ if(tcp_ssl_new_server(_pcb, ssl_ctx) < 0){
+ _close();
+ return;
+ }
+ tcp_ssl_arg(_pcb, this);
+ tcp_ssl_data(_pcb, &_s_data);
+ tcp_ssl_handshake(_pcb, &_s_handshake);
+ tcp_ssl_err(_pcb, &_s_ssl_error);
+
+ _pcb_secure = true;
+ _handshake_done = false;
+ }
+#endif
+ }
+}
+
+AsyncClient::~AsyncClient(){
+ if(_pcb)
+ _close();
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+bool AsyncClient::connect(IPAddress ip, uint16_t port, bool secure){
+#else
+bool AsyncClient::connect(IPAddress ip, uint16_t port){
+#endif
+ if (_pcb) //already connected
+ return false;
+ ip_addr_t addr;
+ addr.addr = ip;
+#if LWIP_VERSION_MAJOR == 1
+ netif* interface = ip_route(&addr);
+ if (!interface){ //no route to host
+ return false;
+ }
+#endif
+ tcp_pcb* pcb = tcp_new();
+ if (!pcb){ //could not allocate pcb
+ return false;
+ }
+
+#if ASYNC_TCP_SSL_ENABLED
+ _pcb_secure = secure;
+ _handshake_done = !secure;
+#endif
+ tcp_arg(pcb, this);
+ tcp_err(pcb, &_s_error);
+ tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);
+ return true;
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+bool AsyncClient::connect(const char* host, uint16_t port, bool secure){
+#else
+bool AsyncClient::connect(const char* host, uint16_t port){
+#endif
+ ip_addr_t addr;
+ err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_s_dns_found, this);
+ if(err == ERR_OK) {
+#if ASYNC_TCP_SSL_ENABLED
+ return connect(IPAddress(addr.addr), port, secure);
+#else
+ return connect(IPAddress(addr.addr), port);
+#endif
+ } else if(err == ERR_INPROGRESS) {
+#if ASYNC_TCP_SSL_ENABLED
+ _pcb_secure = secure;
+ _handshake_done = !secure;
+#endif
+ _connect_port = port;
+ return true;
+ }
+ return false;
+}
+
+AsyncClient& AsyncClient::operator=(const AsyncClient& other){
+ if (_pcb)
+ _close();
+
+ _pcb = other._pcb;
+ if (_pcb) {
+ _rx_last_packet = millis();
+ tcp_setprio(_pcb, TCP_PRIO_MIN);
+ tcp_arg(_pcb, this);
+ tcp_recv(_pcb, &_s_recv);
+ tcp_sent(_pcb, &_s_sent);
+ tcp_err(_pcb, &_s_error);
+ tcp_poll(_pcb, &_s_poll, 1);
+#if ASYNC_TCP_SSL_ENABLED
+ if(tcp_ssl_has(_pcb)){
+ _pcb_secure = true;
+ _handshake_done = false;
+ tcp_ssl_arg(_pcb, this);
+ tcp_ssl_data(_pcb, &_s_data);
+ tcp_ssl_handshake(_pcb, &_s_handshake);
+ tcp_ssl_err(_pcb, &_s_ssl_error);
+ } else {
+ _pcb_secure = false;
+ _handshake_done = true;
+ }
+#endif
+ }
+ return *this;
+}
+
+bool AsyncClient::operator==(const AsyncClient &other) {
+ return (_pcb != NULL && other._pcb != NULL && (_pcb->remote_ip.addr == other._pcb->remote_ip.addr) && (_pcb->remote_port == other._pcb->remote_port));
+}
+
+int8_t AsyncClient::abort(){
+ if(_pcb) {
+ tcp_abort(_pcb);
+ _pcb = NULL;
+ }
+ return ERR_ABRT;
+}
+
+void AsyncClient::close(bool now){
+ tcp_recved(_pcb, _rx_ack_len);
+ if(now)
+ _close();
+ else
+ _close_pcb = true;
+}
+
+void AsyncClient::stop() {
+ close(false);
+}
+
+bool AsyncClient::free(){
+ if(!_pcb)
+ return true;
+ if(_pcb->state == 0 || _pcb->state > 4)
+ return true;
+ return false;
+}
+
+size_t AsyncClient::write(const char* data) {
+ if(data == NULL)
+ return 0;
+ return write(data, strlen(data));
+}
+
+size_t AsyncClient::write(const char* data, size_t size, uint8_t apiflags) {
+ size_t will_send = add(data, size, apiflags);
+ if(!will_send || !send())
+ return 0;
+ return will_send;
+}
+
+size_t AsyncClient::add(const char* data, size_t size, uint8_t apiflags) {
+ if(!_pcb || size == 0 || data == NULL)
+ return 0;
+ size_t room = space();
+ if(!room)
+ return 0;
+#if ASYNC_TCP_SSL_ENABLED
+ if(_pcb_secure){
+ int sent = tcp_ssl_write(_pcb, (uint8_t*)data, size);
+ if(sent >= 0){
+ _tx_unacked_len += sent;
+ return sent;
+ }
+ _close();
+ return 0;
+ }
+#endif
+ size_t will_send = (room < size) ? room : size;
+ int8_t err = tcp_write(_pcb, data, will_send, apiflags);
+ if(err != ERR_OK)
+ return 0;
+ _tx_unsent_len += will_send;
+ return will_send;
+}
+
+bool AsyncClient::send(){
+#if ASYNC_TCP_SSL_ENABLED
+ if(_pcb_secure)
+ return true;
+#endif
+ if(tcp_output(_pcb) == ERR_OK){
+ _pcb_busy = true;
+ _pcb_sent_at = millis();
+ _tx_unacked_len += _tx_unsent_len;
+ _tx_unsent_len = 0;
+ return true;
+ }
+ _tx_unsent_len = 0;
+ return false;
+}
+
+size_t AsyncClient::ack(size_t len){
+ if(len > _rx_ack_len)
+ len = _rx_ack_len;
+ if(len)
+ tcp_recved(_pcb, len);
+ _rx_ack_len -= len;
+ return len;
+}
+
+// Private Callbacks
+
+long AsyncClient::_connected(void* pcb, long err){
+ _pcb = reinterpret_cast(pcb);
+ if(_pcb){
+ _pcb_busy = false;
+ _rx_last_packet = millis();
+ tcp_setprio(_pcb, TCP_PRIO_MIN);
+ tcp_recv(_pcb, &_s_recv);
+ tcp_sent(_pcb, &_s_sent);
+ tcp_poll(_pcb, &_s_poll, 1);
+#if ASYNC_TCP_SSL_ENABLED
+ if(_pcb_secure){
+ if(tcp_ssl_new_client(_pcb) < 0){
+ return _close();
+ }
+ tcp_ssl_arg(_pcb, this);
+ tcp_ssl_data(_pcb, &_s_data);
+ tcp_ssl_handshake(_pcb, &_s_handshake);
+ tcp_ssl_err(_pcb, &_s_ssl_error);
+ }
+ }
+ if(!_pcb_secure && _connect_cb)
+#else
+ }
+ if(_connect_cb)
+#endif
+ _connect_cb(_connect_cb_arg, this);
+ return ERR_OK;
+}
+
+int8_t AsyncClient::_close(){
+ int8_t err = ERR_OK;
+ if(_pcb) {
+#if ASYNC_TCP_SSL_ENABLED
+ if(_pcb_secure){
+ tcp_ssl_free(_pcb);
+ }
+#endif
+ tcp_arg(_pcb, NULL);
+ tcp_sent(_pcb, NULL);
+ tcp_recv(_pcb, NULL);
+ tcp_err(_pcb, NULL);
+ tcp_poll(_pcb, NULL, 0);
+ err = tcp_close(_pcb);
+ if(err != ERR_OK) {
+ err = abort();
+ }
+ _pcb = NULL;
+ if(_discard_cb)
+ _discard_cb(_discard_cb_arg, this);
+ }
+ return err;
+}
+
+void AsyncClient::_error(long err) {
+ if(_pcb){
+#if ASYNC_TCP_SSL_ENABLED
+ if(_pcb_secure){
+ tcp_ssl_free(_pcb);
+ }
+#endif
+ tcp_arg(_pcb, NULL);
+ tcp_sent(_pcb, NULL);
+ tcp_recv(_pcb, NULL);
+ tcp_err(_pcb, NULL);
+ tcp_poll(_pcb, NULL, 0);
+ _pcb = NULL;
+ }
+ if(_error_cb)
+ _error_cb(_error_cb_arg, this, err);
+ if(_discard_cb)
+ _discard_cb(_discard_cb_arg, this);
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+void AsyncClient::_ssl_error(int8_t err){
+ if(_error_cb)
+ _error_cb(_error_cb_arg, this, err+64);
+}
+#endif
+
+long AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) {
+ _rx_last_packet = millis();
+ ASYNC_TCP_DEBUG("_sent: %u\n", len);
+ _tx_unacked_len -= len;
+ _tx_acked_len += len;
+ if(_tx_unacked_len == 0){
+ _pcb_busy = false;
+ if(_sent_cb)
+ _sent_cb(_sent_cb_arg, this, _tx_acked_len, (millis() - _pcb_sent_at));
+ _tx_acked_len = 0;
+ }
+ return ERR_OK;
+}
+
+long AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, long err) {
+ if(pb == NULL){
+ ASYNC_TCP_DEBUG("_recv: pb == NULL! Closing... %d\n", err);
+ return _close();
+ }
+
+ _rx_last_packet = millis();
+#if ASYNC_TCP_SSL_ENABLED
+ if(_pcb_secure){
+ ASYNC_TCP_DEBUG("_recv: %d\n", pb->tot_len);
+ int read_bytes = tcp_ssl_read(pcb, pb);
+ if(read_bytes < 0){
+ if (read_bytes != SSL_CLOSE_NOTIFY) {
+ ASYNC_TCP_DEBUG("_recv err: %d\n", read_bytes);
+ _close();
+ }
+ return read_bytes;
+ }
+ return ERR_OK;
+ }
+#endif
+ while(pb != NULL){
+ //we should not ack before we assimilate the data
+ _ack_pcb = true;
+ pbuf *b = pb;
+ ASYNC_TCP_DEBUG("_recv: %d\n", b->len);
+ if(_recv_cb)
+ _recv_cb(_recv_cb_arg, this, b->payload, b->len);
+ if(!_ack_pcb)
+ _rx_ack_len += b->len;
+ else
+ tcp_recved(pcb, b->len);
+ pb = b->next;
+ b->next = NULL;
+ pbuf_free(b);
+ }
+ return ERR_OK;
+}
+
+long AsyncClient::_poll(tcp_pcb* pcb){
+ // Close requested
+ if(_close_pcb){
+ _close_pcb = false;
+ _close();
+ return ERR_OK;
+ }
+ uint32_t now = millis();
+
+ // ACK Timeout
+ if(_pcb_busy && _ack_timeout && (now - _pcb_sent_at) >= _ack_timeout){
+ _pcb_busy = false;
+ if(_timeout_cb)
+ _timeout_cb(_timeout_cb_arg, this, (now - _pcb_sent_at));
+ return ERR_OK;
+ }
+ // RX Timeout
+ if(_rx_since_timeout && (now - _rx_last_packet) >= (_rx_since_timeout * 1000)){
+ _close();
+ return ERR_OK;
+ }
+#if ASYNC_TCP_SSL_ENABLED
+ // SSL Handshake Timeout
+ if(_pcb_secure && !_handshake_done && (now - _rx_last_packet) >= 2000){
+ _close();
+ return ERR_OK;
+ }
+#endif
+ // Everything is fine
+ if(_poll_cb)
+ _poll_cb(_poll_cb_arg, this);
+ return ERR_OK;
+}
+
+#if LWIP_VERSION_MAJOR == 1
+void AsyncClient::_dns_found(struct ip_addr *ipaddr){
+#else
+void AsyncClient::_dns_found(const ip_addr *ipaddr){
+#endif
+ if(ipaddr){
+#if ASYNC_TCP_SSL_ENABLED
+ connect(IPAddress(ipaddr->addr), _connect_port, _pcb_secure);
+#else
+ connect(IPAddress(ipaddr->addr), _connect_port);
+#endif
+ } else {
+ if(_error_cb)
+ _error_cb(_error_cb_arg, this, -55);
+ if(_discard_cb)
+ _discard_cb(_discard_cb_arg, this);
+ }
+}
+
+// lWIP Callbacks
+#if LWIP_VERSION_MAJOR == 1
+void AsyncClient::_s_dns_found(const char *name, ip_addr_t *ipaddr, void *arg){
+#else
+void AsyncClient::_s_dns_found(const char *name, const ip_addr *ipaddr, void *arg){
+#endif
+ reinterpret_cast(arg)->_dns_found(ipaddr);
+}
+
+long AsyncClient::_s_poll(void *arg, struct tcp_pcb *tpcb) {
+ return reinterpret_cast(arg)->_poll(tpcb);
+}
+
+long AsyncClient::_s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err) {
+ return reinterpret_cast(arg)->_recv(tpcb, pb, err);
+}
+
+void AsyncClient::_s_error(void *arg, long err) {
+ reinterpret_cast(arg)->_error(err);
+}
+
+long AsyncClient::_s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len) {
+ return reinterpret_cast(arg)->_sent(tpcb, len);
+}
+
+long AsyncClient::_s_connected(void* arg, void* tpcb, long err){
+ return reinterpret_cast(arg)->_connected(tpcb, err);
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+void AsyncClient::_s_data(void *arg, struct tcp_pcb *tcp, uint8_t * data, size_t len){
+ AsyncClient *c = reinterpret_cast(arg);
+ if(c->_recv_cb)
+ c->_recv_cb(c->_recv_cb_arg, c, data, len);
+}
+
+void AsyncClient::_s_handshake(void *arg, struct tcp_pcb *tcp, SSL *ssl){
+ AsyncClient *c = reinterpret_cast(arg);
+ c->_handshake_done = true;
+ if(c->_connect_cb)
+ c->_connect_cb(c->_connect_cb_arg, c);
+}
+
+void AsyncClient::_s_ssl_error(void *arg, struct tcp_pcb *tcp, int8_t err){
+ reinterpret_cast(arg)->_ssl_error(err);
+}
+#endif
+
+// Operators
+
+AsyncClient & AsyncClient::operator+=(const AsyncClient &other) {
+ if(next == NULL){
+ next = (AsyncClient*)(&other);
+ next->prev = this;
+ } else {
+ AsyncClient *c = next;
+ while(c->next != NULL) c = c->next;
+ c->next =(AsyncClient*)(&other);
+ c->next->prev = c;
+ }
+ return *this;
+}
+
+void AsyncClient::setRxTimeout(uint32_t timeout){
+ _rx_since_timeout = timeout;
+}
+
+uint32_t AsyncClient::getRxTimeout(){
+ return _rx_since_timeout;
+}
+
+uint32_t AsyncClient::getAckTimeout(){
+ return _ack_timeout;
+}
+
+void AsyncClient::setAckTimeout(uint32_t timeout){
+ _ack_timeout = timeout;
+}
+
+void AsyncClient::setNoDelay(bool nodelay){
+ if(!_pcb)
+ return;
+ if(nodelay)
+ tcp_nagle_disable(_pcb);
+ else
+ tcp_nagle_enable(_pcb);
+}
+
+bool AsyncClient::getNoDelay(){
+ if(!_pcb)
+ return false;
+ return tcp_nagle_disabled(_pcb);
+}
+
+uint16_t AsyncClient::getMss(){
+ if(_pcb)
+ return tcp_mss(_pcb);
+ return 0;
+}
+
+uint32_t AsyncClient::getRemoteAddress() {
+ if(!_pcb)
+ return 0;
+ return _pcb->remote_ip.addr;
+}
+
+uint16_t AsyncClient::getRemotePort() {
+ if(!_pcb)
+ return 0;
+ return _pcb->remote_port;
+}
+
+uint32_t AsyncClient::getLocalAddress() {
+ if(!_pcb)
+ return 0;
+ return _pcb->local_ip.addr;
+}
+
+uint16_t AsyncClient::getLocalPort() {
+ if(!_pcb)
+ return 0;
+ return _pcb->local_port;
+}
+
+IPAddress AsyncClient::remoteIP() {
+ return IPAddress(getRemoteAddress());
+}
+
+uint16_t AsyncClient::remotePort() {
+ return getRemotePort();
+}
+
+IPAddress AsyncClient::localIP() {
+ return IPAddress(getLocalAddress());
+}
+
+uint16_t AsyncClient::localPort() {
+ return getLocalPort();
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+SSL * AsyncClient::getSSL(){
+ if(_pcb && _pcb_secure){
+ return tcp_ssl_get_ssl(_pcb);
+ }
+ return NULL;
+}
+#endif
+
+uint8_t AsyncClient::state() {
+ if(!_pcb)
+ return 0;
+ return _pcb->state;
+}
+
+bool AsyncClient::connected(){
+ if (!_pcb)
+ return false;
+#if ASYNC_TCP_SSL_ENABLED
+ return _pcb->state == 4 && _handshake_done;
+#else
+ return _pcb->state == 4;
+#endif
+}
+
+bool AsyncClient::connecting(){
+ if (!_pcb)
+ return false;
+ return _pcb->state > 0 && _pcb->state < 4;
+}
+
+bool AsyncClient::disconnecting(){
+ if (!_pcb)
+ return false;
+ return _pcb->state > 4 && _pcb->state < 10;
+}
+
+bool AsyncClient::disconnected(){
+ if (!_pcb)
+ return true;
+ return _pcb->state == 0 || _pcb->state == 10;
+}
+
+bool AsyncClient::freeable(){
+ if (!_pcb)
+ return true;
+ return _pcb->state == 0 || _pcb->state > 4;
+}
+
+bool AsyncClient::canSend(){
+ return !_pcb_busy && (space() > 0);
+}
+
+
+// Callback Setters
+
+void AsyncClient::onConnect(AcConnectHandler cb, void* arg){
+ _connect_cb = cb;
+ _connect_cb_arg = arg;
+}
+
+void AsyncClient::onDisconnect(AcConnectHandler cb, void* arg){
+ _discard_cb = cb;
+ _discard_cb_arg = arg;
+}
+
+void AsyncClient::onAck(AcAckHandler cb, void* arg){
+ _sent_cb = cb;
+ _sent_cb_arg = arg;
+}
+
+void AsyncClient::onError(AcErrorHandler cb, void* arg){
+ _error_cb = cb;
+ _error_cb_arg = arg;
+}
+
+void AsyncClient::onData(AcDataHandler cb, void* arg){
+ _recv_cb = cb;
+ _recv_cb_arg = arg;
+}
+
+void AsyncClient::onTimeout(AcTimeoutHandler cb, void* arg){
+ _timeout_cb = cb;
+ _timeout_cb_arg = arg;
+}
+
+void AsyncClient::onPoll(AcConnectHandler cb, void* arg){
+ _poll_cb = cb;
+ _poll_cb_arg = arg;
+}
+
+
+size_t AsyncClient::space(){
+#if ASYNC_TCP_SSL_ENABLED
+ if((_pcb != NULL) && (_pcb->state == 4) && _handshake_done){
+ uint16_t s = tcp_sndbuf(_pcb);
+ if(_pcb_secure){
+#ifdef AXTLS_2_0_0_SNDBUF
+ return tcp_ssl_sndbuf(_pcb);
+#else
+ if(s >= 128) //safe approach
+ return s - 128;
+ return 0;
+#endif
+ }
+ return s;
+ }
+#else
+ if((_pcb != NULL) && (_pcb->state == 4)){
+ return tcp_sndbuf(_pcb);
+ }
+#endif
+ return 0;
+}
+
+const char * AsyncClient::errorToString(int8_t error){
+ switch(error){
+ case 0: return "OK";
+ case -1: return "Out of memory error";
+ case -2: return "Buffer error";
+ case -3: return "Timeout";
+ case -4: return "Routing problem";
+ case -5: return "Operation in progress";
+ case -6: return "Illegal value";
+ case -7: return "Operation would block";
+ case -8: return "Connection aborted";
+ case -9: return "Connection reset";
+ case -10: return "Connection closed";
+ case -11: return "Not connected";
+ case -12: return "Illegal argument";
+ case -13: return "Address in use";
+ case -14: return "Low-level netif error";
+ case -15: return "Already connected";
+ case -55: return "DNS failed";
+ default: return "UNKNOWN";
+ }
+}
+
+const char * AsyncClient::stateToString(){
+ switch(state()){
+ case 0: return "Closed";
+ case 1: return "Listen";
+ case 2: return "SYN Sent";
+ case 3: return "SYN Received";
+ case 4: return "Established";
+ case 5: return "FIN Wait 1";
+ case 6: return "FIN Wait 2";
+ case 7: return "Close Wait";
+ case 8: return "Closing";
+ case 9: return "Last ACK";
+ case 10: return "Time Wait";
+ default: return "UNKNOWN";
+ }
+}
+
+/*
+ Async TCP Server
+*/
+struct pending_pcb {
+ tcp_pcb* pcb;
+ pbuf *pb;
+ struct pending_pcb * next;
+};
+
+AsyncServer::AsyncServer(IPAddress addr, uint16_t port)
+ : _port(port)
+ , _addr(addr)
+ , _noDelay(false)
+ , _pcb(0)
+ , _connect_cb(0)
+ , _connect_cb_arg(0)
+#if ASYNC_TCP_SSL_ENABLED
+ , _pending(NULL)
+ , _ssl_ctx(NULL)
+ , _file_cb(0)
+ , _file_cb_arg(0)
+#endif
+{}
+
+AsyncServer::AsyncServer(uint16_t port)
+ : _port(port)
+ , _addr((uint32_t) IPADDR_ANY)
+ , _noDelay(false)
+ , _pcb(0)
+ , _connect_cb(0)
+ , _connect_cb_arg(0)
+#if ASYNC_TCP_SSL_ENABLED
+ , _pending(NULL)
+ , _ssl_ctx(NULL)
+ , _file_cb(0)
+ , _file_cb_arg(0)
+#endif
+{}
+
+AsyncServer::~AsyncServer(){
+ end();
+}
+
+void AsyncServer::onClient(AcConnectHandler cb, void* arg){
+ _connect_cb = cb;
+ _connect_cb_arg = arg;
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+void AsyncServer::onSslFileRequest(AcSSlFileHandler cb, void* arg){
+ _file_cb = cb;
+ _file_cb_arg = arg;
+}
+#endif
+
+void AsyncServer::begin(){
+ if(_pcb)
+ return;
+
+ int8_t err;
+ tcp_pcb* pcb = tcp_new();
+ if (!pcb){
+ return;
+ }
+
+ ip_addr_t local_addr;
+ local_addr.addr = (uint32_t) _addr;
+ err = tcp_bind(pcb, &local_addr, _port);
+
+ if (err != ERR_OK) {
+ tcp_close(pcb);
+ return;
+ }
+
+ tcp_pcb* listen_pcb = tcp_listen(pcb);
+ if (!listen_pcb) {
+ tcp_close(pcb);
+ return;
+ }
+ _pcb = listen_pcb;
+ tcp_arg(_pcb, (void*) this);
+ tcp_accept(_pcb, &_s_accept);
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+void AsyncServer::beginSecure(const char *cert, const char *key, const char *password){
+ if(_ssl_ctx){
+ return;
+ }
+ tcp_ssl_file(_s_cert, this);
+ _ssl_ctx = tcp_ssl_new_server_ctx(cert, key, password);
+ if(_ssl_ctx){
+ begin();
+ }
+}
+#endif
+
+void AsyncServer::end(){
+ if(_pcb){
+ //cleanup all connections?
+ tcp_abort(_pcb);
+ tcp_arg(_pcb, NULL);
+ tcp_accept(_pcb, NULL);
+ if(tcp_close(_pcb) != ERR_OK){
+ tcp_abort(_pcb);
+ }
+ _pcb = NULL;
+ }
+#if ASYNC_TCP_SSL_ENABLED
+ if(_ssl_ctx){
+ ssl_ctx_free(_ssl_ctx);
+ _ssl_ctx = NULL;
+ if(_pending){
+ struct pending_pcb * p;
+ while(_pending){
+ p = _pending;
+ _pending = _pending->next;
+ if(p->pb){
+ pbuf_free(p->pb);
+ }
+ free(p);
+ }
+ }
+ }
+#endif
+}
+
+void AsyncServer::setNoDelay(bool nodelay){
+ _noDelay = nodelay;
+}
+
+bool AsyncServer::getNoDelay(){
+ return _noDelay;
+}
+
+uint8_t AsyncServer::status(){
+ if (!_pcb)
+ return 0;
+ return _pcb->state;
+}
+
+long AsyncServer::_accept(tcp_pcb* pcb, long err){
+ if(_connect_cb){
+#if ASYNC_TCP_SSL_ENABLED
+ if (_noDelay || _ssl_ctx)
+#else
+ if (_noDelay)
+#endif
+ tcp_nagle_disable(pcb);
+ else
+ tcp_nagle_enable(pcb);
+
+
+#if ASYNC_TCP_SSL_ENABLED
+ if(_ssl_ctx){
+ if(tcp_ssl_has_client() || _pending){
+ struct pending_pcb * new_item = (struct pending_pcb*)malloc(sizeof(struct pending_pcb));
+ if(!new_item){
+ ASYNC_TCP_DEBUG("### malloc new pending failed!\n");
+ if(tcp_close(pcb) != ERR_OK){
+ tcp_abort(pcb);
+ }
+ return ERR_OK;
+ }
+ ASYNC_TCP_DEBUG("### put to wait: %d\n", _clients_waiting);
+ new_item->pcb = pcb;
+ new_item->pb = NULL;
+ new_item->next = NULL;
+ tcp_setprio(_pcb, TCP_PRIO_MIN);
+ tcp_arg(pcb, this);
+ tcp_poll(pcb, &_s_poll, 1);
+ tcp_recv(pcb, &_s_recv);
+
+ if(_pending == NULL){
+ _pending = new_item;
+ } else {
+ struct pending_pcb * p = _pending;
+ while(p->next != NULL)
+ p = p->next;
+ p->next = new_item;
+ }
+ } else {
+ AsyncClient *c = new AsyncClient(pcb, _ssl_ctx);
+ if(c){
+ c->onConnect([this](void * arg, AsyncClient *c){
+ _connect_cb(_connect_cb_arg, c);
+ }, this);
+ }
+ }
+ return ERR_OK;
+ } else {
+ AsyncClient *c = new AsyncClient(pcb, NULL);
+#else
+ AsyncClient *c = new AsyncClient(pcb);
+#endif
+ if(c){
+ _connect_cb(_connect_cb_arg, c);
+ return ERR_OK;
+ }
+#if ASYNC_TCP_SSL_ENABLED
+ }
+#endif
+ }
+ if(tcp_close(pcb) != ERR_OK){
+ tcp_abort(pcb);
+ }
+ return ERR_OK;
+}
+
+ long AsyncServer::_s_accept(void *arg, tcp_pcb* pcb, long err){
+ return reinterpret_cast(arg)->_accept(pcb, err);
+ }
+
+#if ASYNC_TCP_SSL_ENABLED
+long AsyncServer::_poll(tcp_pcb* pcb){
+ if(!tcp_ssl_has_client() && _pending){
+ struct pending_pcb * p = _pending;
+ if(p->pcb == pcb){
+ _pending = _pending->next;
+ } else {
+ while(p->next && p->next->pcb != pcb) p = p->next;
+ if(!p->next) return 0;
+ struct pending_pcb * b = p->next;
+ p->next = b->next;
+ p = b;
+ }
+ ASYNC_TCP_DEBUG("### remove from wait: %d\n", _clients_waiting);
+ AsyncClient *c = new AsyncClient(pcb, _ssl_ctx);
+ if(c){
+ c->onConnect([this](void * arg, AsyncClient *c){
+ _connect_cb(_connect_cb_arg, c);
+ }, this);
+ if(p->pb)
+ c->_recv(pcb, p->pb, 0);
+ }
+ free(p);
+ }
+ return ERR_OK;
+}
+
+long AsyncServer::_recv(struct tcp_pcb *pcb, struct pbuf *pb, long err){
+ if(!_pending)
+ return ERR_OK;
+
+ struct pending_pcb * p;
+
+ if(!pb){
+ ASYNC_TCP_DEBUG("### close from wait: %d\n", _clients_waiting);
+ p = _pending;
+ if(p->pcb == pcb){
+ _pending = _pending->next;
+ } else {
+ while(p->next && p->next->pcb != pcb) p = p->next;
+ if(!p->next) return 0;
+ struct pending_pcb * b = p->next;
+ p->next = b->next;
+ p = b;
+ }
+ if(p->pb){
+ pbuf_free(p->pb);
+ }
+ free(p);
+ tcp_close(pcb);
+ tcp_abort(pcb);
+ } else {
+ ASYNC_TCP_DEBUG("### wait _recv: %u %d\n", pb->tot_len, _clients_waiting);
+ p = _pending;
+ while(p && p->pcb != pcb)
+ p = p->next;
+ if(p){
+ if(p->pb){
+ pbuf_chain(p->pb, pb);
+ } else {
+ p->pb = pb;
+ }
+ }
+ }
+ return ERR_OK;
+}
+
+int AsyncServer::_cert(const char *filename, uint8_t **buf){
+ if(_file_cb){
+ return _file_cb(_file_cb_arg, filename, buf);
+ }
+ *buf = 0;
+ return 0;
+}
+
+int AsyncServer::_s_cert(void *arg, const char *filename, uint8_t **buf){
+ return reinterpret_cast(arg)->_cert(filename, buf);
+}
+
+long AsyncServer::_s_poll(void *arg, struct tcp_pcb *pcb){
+ return reinterpret_cast(arg)->_poll(pcb);
+}
+
+long AsyncServer::_s_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *pb, long err){
+ return reinterpret_cast(arg)->_recv(pcb, pb, err);
+}
+#endif
diff --git a/libraries/ESPAsyncTCP/src/ESPAsyncTCP.h b/libraries/ESPAsyncTCP/src/ESPAsyncTCP.h
new file mode 100644
index 00000000..1e72dfd5
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/ESPAsyncTCP.h
@@ -0,0 +1,249 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef ASYNCTCP_H_
+#define ASYNCTCP_H_
+
+#include
+#include "IPAddress.h"
+#include
+#include "lwip/init.h"
+
+class AsyncClient;
+
+#define ASYNC_MAX_ACK_TIME 5000
+#define ASYNC_WRITE_FLAG_COPY 0x01 //will allocate new buffer to hold the data while sending (else will hold reference to the data given)
+#define ASYNC_WRITE_FLAG_MORE 0x02 //will not send PSH flag, meaning that there should be more data to be sent before the application should react.
+
+typedef std::function AcConnectHandler;
+typedef std::function AcAckHandler;
+typedef std::function AcErrorHandler;
+typedef std::function AcDataHandler;
+typedef std::function AcTimeoutHandler;
+
+struct tcp_pcb;
+struct pbuf;
+struct ip_addr;
+#if ASYNC_TCP_SSL_ENABLED
+struct SSL_;
+typedef struct SSL_ SSL;
+struct SSL_CTX_;
+typedef struct SSL_CTX_ SSL_CTX;
+#endif
+
+class AsyncClient {
+ protected:
+ friend class AsyncTCPbuffer;
+ tcp_pcb* _pcb;
+ AcConnectHandler _connect_cb;
+ void* _connect_cb_arg;
+ AcConnectHandler _discard_cb;
+ void* _discard_cb_arg;
+ AcAckHandler _sent_cb;
+ void* _sent_cb_arg;
+ AcErrorHandler _error_cb;
+ void* _error_cb_arg;
+ AcDataHandler _recv_cb;
+ void* _recv_cb_arg;
+ AcTimeoutHandler _timeout_cb;
+ void* _timeout_cb_arg;
+ AcConnectHandler _poll_cb;
+ void* _poll_cb_arg;
+ bool _pcb_busy;
+#if ASYNC_TCP_SSL_ENABLED
+ bool _pcb_secure;
+ bool _handshake_done;
+#endif
+ uint32_t _pcb_sent_at;
+ bool _close_pcb;
+ bool _ack_pcb;
+ uint32_t _tx_unacked_len;
+ uint32_t _tx_acked_len;
+ uint32_t _tx_unsent_len;
+ uint32_t _rx_ack_len;
+ uint32_t _rx_last_packet;
+ uint32_t _rx_since_timeout;
+ uint32_t _ack_timeout;
+ uint16_t _connect_port;
+
+ int8_t _close();
+ long _connected(void* pcb, long err);
+ void _error(long err);
+#if ASYNC_TCP_SSL_ENABLED
+ void _ssl_error(int8_t err);
+#endif
+ long _poll(tcp_pcb* pcb);
+ long _sent(tcp_pcb* pcb, uint16_t len);
+#if LWIP_VERSION_MAJOR == 1
+ void _dns_found(struct ip_addr *ipaddr);
+#else
+ void _dns_found(const ip_addr *ipaddr);
+#endif
+ static long _s_poll(void *arg, struct tcp_pcb *tpcb);
+ static long _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err);
+ static void _s_error(void *arg, long err);
+ static long _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len);
+ static long _s_connected(void* arg, void* tpcb, long err);
+#if LWIP_VERSION_MAJOR == 1
+ static void _s_dns_found(const char *name, struct ip_addr *ipaddr, void *arg);
+#else
+ static void _s_dns_found(const char *name, const ip_addr *ipaddr, void *arg);
+#endif
+#if ASYNC_TCP_SSL_ENABLED
+ static void _s_data(void *arg, struct tcp_pcb *tcp, uint8_t * data, size_t len);
+ static void _s_handshake(void *arg, struct tcp_pcb *tcp, SSL *ssl);
+ static void _s_ssl_error(void *arg, struct tcp_pcb *tcp, int8_t err);
+#endif
+
+ public:
+ AsyncClient* prev;
+ AsyncClient* next;
+
+#if ASYNC_TCP_SSL_ENABLED
+ AsyncClient(tcp_pcb* pcb = 0, SSL_CTX * ssl_ctx = NULL);
+#else
+ AsyncClient(tcp_pcb* pcb = 0);
+#endif
+ ~AsyncClient();
+
+ AsyncClient & operator=(const AsyncClient &other);
+ AsyncClient & operator+=(const AsyncClient &other);
+
+ bool operator==(const AsyncClient &other);
+
+ bool operator!=(const AsyncClient &other) {
+ return !(*this == other);
+ }
+#if ASYNC_TCP_SSL_ENABLED
+ bool connect(IPAddress ip, uint16_t port, bool secure=false);
+ bool connect(const char* host, uint16_t port, bool secure=false);
+#else
+ bool connect(IPAddress ip, uint16_t port);
+ bool connect(const char* host, uint16_t port);
+#endif
+ void close(bool now = false);
+ void stop();
+ int8_t abort();
+ bool free();
+
+ bool canSend();//ack is not pending
+ size_t space();
+ size_t add(const char* data, size_t size, uint8_t apiflags=0);//add for sending
+ bool send();//send all data added with the method above
+ size_t ack(size_t len); //ack data that you have not acked using the method below
+ void ackLater(){ _ack_pcb = false; } //will not ack the current packet. Call from onData
+
+#if ASYNC_TCP_SSL_ENABLED
+ SSL *getSSL();
+#endif
+
+ size_t write(const char* data);
+ size_t write(const char* data, size_t size, uint8_t apiflags=0); //only when canSend() == true
+
+ uint8_t state();
+ bool connecting();
+ bool connected();
+ bool disconnecting();
+ bool disconnected();
+ bool freeable();//disconnected or disconnecting
+
+ uint16_t getMss();
+ uint32_t getRxTimeout();
+ void setRxTimeout(uint32_t timeout);//no RX data timeout for the connection in seconds
+ uint32_t getAckTimeout();
+ void setAckTimeout(uint32_t timeout);//no ACK timeout for the last sent packet in milliseconds
+ void setNoDelay(bool nodelay);
+ bool getNoDelay();
+ uint32_t getRemoteAddress();
+ uint16_t getRemotePort();
+ uint32_t getLocalAddress();
+ uint16_t getLocalPort();
+
+ IPAddress remoteIP();
+ uint16_t remotePort();
+ IPAddress localIP();
+ uint16_t localPort();
+
+ void onConnect(AcConnectHandler cb, void* arg = 0); //on successful connect
+ void onDisconnect(AcConnectHandler cb, void* arg = 0); //disconnected
+ void onAck(AcAckHandler cb, void* arg = 0); //ack received
+ void onError(AcErrorHandler cb, void* arg = 0); //unsuccessful connect or error
+ void onData(AcDataHandler cb, void* arg = 0); //data received
+ void onTimeout(AcTimeoutHandler cb, void* arg = 0); //ack timeout
+ void onPoll(AcConnectHandler cb, void* arg = 0); //every 125ms when connected
+
+ const char * errorToString(int8_t error);
+ const char * stateToString();
+
+ long _recv(tcp_pcb* pcb, pbuf* pb, long err);
+};
+
+#if ASYNC_TCP_SSL_ENABLED
+typedef std::function AcSSlFileHandler;
+struct pending_pcb;
+#endif
+
+class AsyncServer {
+ protected:
+ uint16_t _port;
+ IPAddress _addr;
+ bool _noDelay;
+ tcp_pcb* _pcb;
+ AcConnectHandler _connect_cb;
+ void* _connect_cb_arg;
+#if ASYNC_TCP_SSL_ENABLED
+ struct pending_pcb * _pending;
+ SSL_CTX * _ssl_ctx;
+ AcSSlFileHandler _file_cb;
+ void* _file_cb_arg;
+#endif
+
+ public:
+
+ AsyncServer(IPAddress addr, uint16_t port);
+ AsyncServer(uint16_t port);
+ ~AsyncServer();
+ void onClient(AcConnectHandler cb, void* arg);
+#if ASYNC_TCP_SSL_ENABLED
+ void onSslFileRequest(AcSSlFileHandler cb, void* arg);
+ void beginSecure(const char *cert, const char *private_key_file, const char *password);
+#endif
+ void begin();
+ void end();
+ void setNoDelay(bool nodelay);
+ bool getNoDelay();
+ uint8_t status();
+
+ protected:
+ long _accept(tcp_pcb* newpcb, long err);
+ static long _s_accept(void *arg, tcp_pcb* newpcb, long err);
+#if ASYNC_TCP_SSL_ENABLED
+ int _cert(const char *filename, uint8_t **buf);
+ long _poll(tcp_pcb* pcb);
+ long _recv(tcp_pcb *pcb, struct pbuf *pb, long err);
+ static int _s_cert(void *arg, const char *filename, uint8_t **buf);
+ static long _s_poll(void *arg, struct tcp_pcb *tpcb);
+ static long _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, long err);
+#endif
+};
+
+
+#endif /* ASYNCTCP_H_ */
diff --git a/libraries/ESPAsyncTCP/src/ESPAsyncTCPbuffer.cpp b/libraries/ESPAsyncTCP/src/ESPAsyncTCPbuffer.cpp
new file mode 100644
index 00000000..7bca134f
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/ESPAsyncTCPbuffer.cpp
@@ -0,0 +1,541 @@
+/**
+ * @file ESPAsyncTCPbuffer.cpp
+ * @date 22.01.2016
+ * @author Markus Sattler
+ *
+ * Copyright (c) 2015 Markus Sattler. All rights reserved.
+ * This file is part of the Asynv TCP for ESP.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+
+#include
+#include
+
+#include "ESPAsyncTCPbuffer.h"
+
+
+AsyncTCPbuffer::AsyncTCPbuffer(AsyncClient* client) {
+ if(client == NULL) {
+ DEBUG_ASYNC_TCP("[A-TCP] client is null!!!\n");
+ panic();
+ }
+
+ _client = client;
+ _TXbufferWrite = new cbuf(1460);
+ _TXbufferRead = _TXbufferWrite;
+ _RXbuffer = new cbuf(100);
+ _RXmode = ATB_RX_MODE_FREE;
+ _rxSize = 0;
+ _rxTerminator = 0x00;
+ _rxReadBytesPtr = NULL;
+ _rxReadStringPtr = NULL;
+ _cbDisconnect = NULL;
+
+ _cbRX = NULL;
+ _cbDone = NULL;
+ _attachCallbacks();
+}
+
+AsyncTCPbuffer::~AsyncTCPbuffer() {
+ if(_client) {
+ _client->close();
+ }
+
+ if(_RXbuffer) {
+ delete _RXbuffer;
+ _RXbuffer = NULL;
+ }
+
+ if(_TXbufferWrite) {
+ // will be deleted in _TXbufferRead chain
+ _TXbufferWrite = NULL;
+ }
+
+ if(_TXbufferRead) {
+ cbuf * next = _TXbufferRead->next;
+ delete _TXbufferRead;
+ while(next != NULL) {
+ _TXbufferRead = next;
+ next = _TXbufferRead->next;
+ delete _TXbufferRead;
+ }
+ _TXbufferRead = NULL;
+ }
+}
+
+size_t AsyncTCPbuffer::write(String & data) {
+ return write(data.c_str(), data.length());
+}
+
+size_t AsyncTCPbuffer::write(uint8_t data) {
+ return write(&data, 1);
+}
+
+size_t AsyncTCPbuffer::write(const char* data) {
+ return write((const uint8_t *) data, strlen(data));
+}
+
+size_t AsyncTCPbuffer::write(const char *data, size_t len) {
+ return write((const uint8_t *) data, len);
+}
+
+/**
+ * write data in to buffer and try to send the data
+ * @param data
+ * @param len
+ * @return
+ */
+size_t AsyncTCPbuffer::write(const uint8_t *data, size_t len) {
+ if(_TXbufferWrite == NULL || _client == NULL || !_client->connected() || data == NULL || len == 0) {
+ return 0;
+ }
+
+ size_t bytesLeft = len;
+ while(bytesLeft) {
+ size_t w = _TXbufferWrite->write((const char*) data, bytesLeft);
+ bytesLeft -= w;
+ data += w;
+ _sendBuffer();
+
+ // add new buffer since we have more data
+ if(_TXbufferWrite->full() && bytesLeft > 0) {
+
+ // to less ram!!!
+ if(ESP.getFreeHeap() < 4096) {
+ DEBUG_ASYNC_TCP("[A-TCP] run out of Heap can not send all Data!\n");
+ return (len - bytesLeft);
+ }
+
+ cbuf * next = new cbuf(1460);
+
+ if(next == NULL) {
+ DEBUG_ASYNC_TCP("[A-TCP] run out of Heap!\n");
+ panic();
+ } else {
+ DEBUG_ASYNC_TCP("[A-TCP] new cbuf\n");
+ }
+
+ // add new buffer to chain (current cbuf)
+ _TXbufferWrite->next = next;
+
+ // move ptr for next data
+ _TXbufferWrite = next;
+ }
+ }
+
+ return len;
+
+}
+
+/**
+ * wait until all data has send out
+ */
+void AsyncTCPbuffer::flush() {
+ while(!_TXbufferWrite->empty()) {
+ while(!_client->canSend()) {
+ delay(0);
+ }
+ _sendBuffer();
+ }
+}
+
+void AsyncTCPbuffer::noCallback() {
+ _RXmode = ATB_RX_MODE_NONE;
+}
+
+void AsyncTCPbuffer::readStringUntil(char terminator, String * str, AsyncTCPbufferDoneCb done) {
+ if(_client == NULL) {
+ return;
+ }
+ DEBUG_ASYNC_TCP("[A-TCP] readStringUntil terminator: %02X\n", terminator);
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone = done;
+ _rxReadStringPtr = str;
+ _rxTerminator = terminator;
+ _rxSize = 0;
+ _RXmode = ATB_RX_MODE_TERMINATOR_STRING;
+}
+
+/*
+ void AsyncTCPbuffer::readBytesUntil(char terminator, char *buffer, size_t length, AsyncTCPbufferDoneCb done) {
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone = done;
+ _rxReadBytesPtr = (uint8_t *) buffer;
+ _rxTerminator = terminator;
+ _rxSize = length;
+ _RXmode = ATB_RX_MODE_TERMINATOR;
+ _handleRxBuffer(NULL, 0);
+ }
+
+ void AsyncTCPbuffer::readBytesUntil(char terminator, uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done) {
+ readBytesUntil(terminator, (char *) buffer, length, done);
+ }
+ */
+
+void AsyncTCPbuffer::readBytes(char *buffer, size_t length, AsyncTCPbufferDoneCb done) {
+ if(_client == NULL) {
+ return;
+ }
+ DEBUG_ASYNC_TCP("[A-TCP] readBytes length: %d\n", length);
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone = done;
+ _rxReadBytesPtr = (uint8_t *) buffer;
+ _rxSize = length;
+ _RXmode = ATB_RX_MODE_READ_BYTES;
+}
+
+void AsyncTCPbuffer::readBytes(uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done) {
+ readBytes((char *) buffer, length, done);
+}
+
+void AsyncTCPbuffer::onData(AsyncTCPbufferDataCb cb) {
+ if(_client == NULL) {
+ return;
+ }
+ DEBUG_ASYNC_TCP("[A-TCP] onData\n");
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone = NULL;
+ _cbRX = cb;
+ _RXmode = ATB_RX_MODE_FREE;
+}
+
+void AsyncTCPbuffer::onDisconnect(AsyncTCPbufferDisconnectCb cb) {
+ _cbDisconnect = cb;
+}
+
+IPAddress AsyncTCPbuffer::remoteIP() {
+ if(!_client) {
+ return IPAddress(0U);
+ }
+ return _client->remoteIP();
+}
+
+uint16_t AsyncTCPbuffer::remotePort() {
+ if(!_client) {
+ return 0;
+ }
+ return _client->remotePort();
+}
+
+bool AsyncTCPbuffer::connected() {
+ if(!_client) {
+ return false;
+ }
+ return _client->connected();
+}
+
+void AsyncTCPbuffer::stop() {
+
+ if(!_client) {
+ return;
+ }
+ _client->stop();
+ _client = NULL;
+
+ if(_cbDone) {
+ switch(_RXmode) {
+ case ATB_RX_MODE_READ_BYTES:
+ case ATB_RX_MODE_TERMINATOR:
+ case ATB_RX_MODE_TERMINATOR_STRING:
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone(false, NULL);
+ break;
+ default:
+ break;
+ }
+ }
+ _RXmode = ATB_RX_MODE_NONE;
+}
+
+void AsyncTCPbuffer::close() {
+ stop();
+}
+
+
+///--------------------------------
+
+/**
+ * attachCallbacks to AsyncClient class
+ */
+void AsyncTCPbuffer::_attachCallbacks() {
+ if(!_client) {
+ return;
+ }
+ DEBUG_ASYNC_TCP("[A-TCP] attachCallbacks\n");
+
+ _client->onPoll([](void *obj, AsyncClient* c) {
+ AsyncTCPbuffer* b = ((AsyncTCPbuffer*)(obj));
+ if((b->_TXbufferRead != NULL) && !b->_TXbufferRead->empty()) {
+ b->_sendBuffer();
+ }
+ // if(!b->_RXbuffer->empty()) {
+ // b->_handleRxBuffer(NULL, 0);
+ // }
+ }, this);
+
+ _client->onAck([](void *obj, AsyncClient* c, size_t len, uint32_t time) {
+ DEBUG_ASYNC_TCP("[A-TCP] onAck\n");
+ ((AsyncTCPbuffer*)(obj))->_sendBuffer();
+ }, this);
+
+ _client->onDisconnect([](void *obj, AsyncClient* c) {
+ DEBUG_ASYNC_TCP("[A-TCP] onDisconnect\n");
+ AsyncTCPbuffer* b = ((AsyncTCPbuffer*)(obj));
+ b->_client = NULL;
+ bool del = true;
+ if(b->_cbDisconnect) {
+ del = b->_cbDisconnect(b);
+ }
+ delete c;
+ if(del) {
+ delete b;
+ }
+ }, this);
+
+ _client->onData([](void *obj, AsyncClient* c, void *buf, size_t len) {
+ AsyncTCPbuffer* b = ((AsyncTCPbuffer*)(obj));
+ b->_rxData((uint8_t *)buf, len);
+ }, this);
+
+ _client->onTimeout([](void *obj, AsyncClient* c, uint32_t time){
+ DEBUG_ASYNC_TCP("[A-TCP] onTimeout\n");
+ c->close();
+ }, this);
+
+ DEBUG_ASYNC_TCP("[A-TCP] attachCallbacks Done.\n");
+}
+
+/**
+ * send TX buffer if possible
+ */
+void AsyncTCPbuffer::_sendBuffer() {
+ //DEBUG_ASYNC_TCP("[A-TCP] _sendBuffer...\n");
+ size_t available = _TXbufferRead->available();
+ if(available == 0 || _client == NULL || !_client->connected() || !_client->canSend()) {
+ return;
+ }
+
+ while((_client->space() > 0) && (_TXbufferRead->available() > 0) && _client->canSend()) {
+
+ available = _TXbufferRead->available();
+
+ if(available > _client->space()) {
+ available = _client->space();
+ }
+
+ char *out = new char[available];
+ if(out == NULL) {
+ DEBUG_ASYNC_TCP("[A-TCP] to less heap, try later.\n");
+ return;
+ }
+
+ // read data from buffer
+ _TXbufferRead->peek(out, available);
+
+ // send data
+ size_t send = _client->write((const char*) out, available);
+ if(send != available) {
+ DEBUG_ASYNC_TCP("[A-TCP] write failed send: %d available: %d \n", send, available);
+ }
+
+ // remove really send data from buffer
+ _TXbufferRead->remove(send);
+
+ // if buffer is empty and there is a other buffer in chain delete the empty one
+ if(_TXbufferRead->available() == 0 && _TXbufferRead->next != NULL) {
+ cbuf * old = _TXbufferRead;
+ _TXbufferRead = _TXbufferRead->next;
+ delete old;
+ DEBUG_ASYNC_TCP("[A-TCP] delete cbuf\n");
+ }
+
+ delete out;
+ }
+
+}
+
+/**
+ * called on incoming data
+ * @param buf
+ * @param len
+ */
+void AsyncTCPbuffer::_rxData(uint8_t *buf, size_t len) {
+ if(!_client || !_client->connected()) {
+ DEBUG_ASYNC_TCP("[A-TCP] not connected!\n");
+ return;
+ }
+ if(!_RXbuffer) {
+ DEBUG_ASYNC_TCP("[A-TCP] _rxData no _RXbuffer!\n");
+ return;
+ }
+ DEBUG_ASYNC_TCP("[A-TCP] _rxData len: %d RXmode: %d\n", len, _RXmode);
+
+ size_t handled = 0;
+
+ if(_RXmode != ATB_RX_MODE_NONE) {
+ handled = _handleRxBuffer((uint8_t *) buf, len);
+ buf += handled;
+ len -= handled;
+
+ // handle as much as possible before using the buffer
+ if(_RXbuffer->empty()) {
+ while(_RXmode != ATB_RX_MODE_NONE && handled != 0 && len > 0) {
+ handled = _handleRxBuffer(buf, len);
+ buf += handled;
+ len -= handled;
+ }
+ }
+ }
+
+ if(len > 0) {
+
+ if(_RXbuffer->room() < len) {
+ // to less space
+ DEBUG_ASYNC_TCP("[A-TCP] _rxData buffer full try resize\n");
+ _RXbuffer->resizeAdd((len + _RXbuffer->room()));
+
+ if(_RXbuffer->room() < len) {
+ DEBUG_ASYNC_TCP("[A-TCP] _rxData buffer to full can only handle %d!!!\n", _RXbuffer->room());
+ }
+ }
+
+ _RXbuffer->write((const char *) (buf), len);
+ }
+
+ if(!_RXbuffer->empty() && _RXmode != ATB_RX_MODE_NONE) {
+ // handle as much as possible data in buffer
+ handled = _handleRxBuffer(NULL, 0);
+ while(_RXmode != ATB_RX_MODE_NONE && handled != 0) {
+ handled = _handleRxBuffer(NULL, 0);
+ }
+ }
+
+ // clean up ram
+ if(_RXbuffer->empty() && _RXbuffer->room() != 100) {
+ _RXbuffer->resize(100);
+ }
+
+}
+
+/**
+ *
+ */
+size_t AsyncTCPbuffer::_handleRxBuffer(uint8_t *buf, size_t len) {
+ if(!_client || !_client->connected() || _RXbuffer == NULL) {
+ return 0;
+ }
+
+ DEBUG_ASYNC_TCP("[A-TCP] _handleRxBuffer len: %d RXmode: %d\n", len, _RXmode);
+
+ size_t BufferAvailable = _RXbuffer->available();
+ size_t r = 0;
+
+ if(_RXmode == ATB_RX_MODE_NONE) {
+ return 0;
+ } else if(_RXmode == ATB_RX_MODE_FREE) {
+ if(_cbRX == NULL) {
+ return 0;
+ }
+
+ if(BufferAvailable > 0) {
+ uint8_t * b = new uint8_t[BufferAvailable];
+ _RXbuffer->peek((char *) b, BufferAvailable);
+ r = _cbRX(b, BufferAvailable);
+ _RXbuffer->remove(r);
+ }
+
+ if(r == BufferAvailable && buf && (len > 0)) {
+ return _cbRX(buf, len);
+ } else {
+ return 0;
+ }
+
+ } else if(_RXmode == ATB_RX_MODE_READ_BYTES) {
+ if(_rxReadBytesPtr == NULL || _cbDone == NULL) {
+ return 0;
+ }
+
+ size_t newReadCount = 0;
+
+ if(BufferAvailable) {
+ r = _RXbuffer->read((char *) _rxReadBytesPtr, _rxSize);
+ _rxSize -= r;
+ _rxReadBytesPtr += r;
+ }
+
+ if(_RXbuffer->empty() && (len > 0) && buf) {
+ r = len;
+ if(r > _rxSize) {
+ r = _rxSize;
+ }
+ memcpy(_rxReadBytesPtr, buf, r);
+ _rxReadBytesPtr += r;
+ _rxSize -= r;
+ newReadCount += r;
+ }
+
+ if(_rxSize == 0) {
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone(true, NULL);
+ }
+
+ // add left over bytes to Buffer
+ return newReadCount;
+
+ } else if(_RXmode == ATB_RX_MODE_TERMINATOR) {
+ // TODO implement read terminator non string
+
+ } else if(_RXmode == ATB_RX_MODE_TERMINATOR_STRING) {
+ if(_rxReadStringPtr == NULL || _cbDone == NULL) {
+ return 0;
+ }
+
+ // handle Buffer
+ if(BufferAvailable > 0) {
+ while(!_RXbuffer->empty()) {
+ char c = _RXbuffer->read();
+ if(c == _rxTerminator || c == 0x00) {
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone(true, _rxReadStringPtr);
+ return 0;
+ } else {
+ (*_rxReadStringPtr) += c;
+ }
+ }
+ }
+
+ if(_RXbuffer->empty() && (len > 0) && buf) {
+ size_t newReadCount = 0;
+ while(newReadCount < len) {
+ char c = (char) *buf;
+ buf++;
+ newReadCount++;
+ if(c == _rxTerminator || c == 0x00) {
+ _RXmode = ATB_RX_MODE_NONE;
+ _cbDone(true, _rxReadStringPtr);
+ return newReadCount;
+ } else {
+ (*_rxReadStringPtr) += c;
+ }
+ }
+ return newReadCount;
+ }
+ }
+
+ return 0;
+}
diff --git a/libraries/ESPAsyncTCP/src/ESPAsyncTCPbuffer.h b/libraries/ESPAsyncTCP/src/ESPAsyncTCPbuffer.h
new file mode 100644
index 00000000..374364e5
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/ESPAsyncTCPbuffer.h
@@ -0,0 +1,118 @@
+/**
+ * @file ESPAsyncTCPbuffer.h
+ * @date 22.01.2016
+ * @author Markus Sattler
+ *
+ * Copyright (c) 2015 Markus Sattler. All rights reserved.
+ * This file is part of the Asynv TCP for ESP.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef ESPASYNCTCPBUFFER_H_
+#define ESPASYNCTCPBUFFER_H_
+
+//#define DEBUG_ASYNC_TCP(...) while(((U0S >> USTXC) & 0x7F) != 0x00); os_printf( __VA_ARGS__ ); while(((U0S >> USTXC) & 0x7F) != 0x00)
+
+#ifndef DEBUG_ASYNC_TCP
+#define DEBUG_ASYNC_TCP(...)
+#endif
+
+#include
+#include
+
+#include "ESPAsyncTCP.h"
+
+
+
+typedef enum {
+ ATB_RX_MODE_NONE,
+ ATB_RX_MODE_FREE,
+ ATB_RX_MODE_READ_BYTES,
+ ATB_RX_MODE_TERMINATOR,
+ ATB_RX_MODE_TERMINATOR_STRING
+} atbRxMode_t;
+
+class AsyncTCPbuffer: public Print {
+
+ public:
+
+ typedef std::function AsyncTCPbufferDataCb;
+ typedef std::function AsyncTCPbufferDoneCb;
+ typedef std::function AsyncTCPbufferDisconnectCb;
+
+ AsyncTCPbuffer(AsyncClient* c);
+ virtual ~AsyncTCPbuffer();
+
+ size_t write(String & data);
+ size_t write(uint8_t data);
+ size_t write(const char* data);
+ size_t write(const char *data, size_t len);
+ size_t write(const uint8_t *data, size_t len);
+
+ void flush();
+
+ void noCallback();
+
+ void readStringUntil(char terminator, String * str, AsyncTCPbufferDoneCb done);
+
+ // TODO implement read terminator non string
+ //void readBytesUntil(char terminator, char *buffer, size_t length, AsyncTCPbufferDoneCb done);
+ //void readBytesUntil(char terminator, uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done);
+
+ void readBytes(char *buffer, size_t length, AsyncTCPbufferDoneCb done);
+ void readBytes(uint8_t *buffer, size_t length, AsyncTCPbufferDoneCb done);
+
+ // TODO implement
+ // void setTimeout(size_t timeout);
+
+ void onData(AsyncTCPbufferDataCb cb);
+ void onDisconnect(AsyncTCPbufferDisconnectCb cb);
+
+ IPAddress remoteIP();
+ uint16_t remotePort();
+ IPAddress localIP();
+ uint16_t localPort();
+
+ bool connected();
+
+ void stop();
+ void close();
+
+ protected:
+ AsyncClient* _client;
+ cbuf * _TXbufferRead;
+ cbuf * _TXbufferWrite;
+ cbuf * _RXbuffer;
+ atbRxMode_t _RXmode;
+ size_t _rxSize;
+ char _rxTerminator;
+ uint8_t * _rxReadBytesPtr;
+ String * _rxReadStringPtr;
+
+ AsyncTCPbufferDataCb _cbRX;
+ AsyncTCPbufferDoneCb _cbDone;
+ AsyncTCPbufferDisconnectCb _cbDisconnect;
+
+ void _attachCallbacks();
+ void _sendBuffer();
+ void _on_close();
+ void _rxData(uint8_t *buf, size_t len);
+ size_t _handleRxBuffer(uint8_t *buf, size_t len);
+
+};
+
+#endif /* ESPASYNCTCPBUFFER_H_ */
diff --git a/libraries/ESPAsyncTCP/src/SyncClient.cpp b/libraries/ESPAsyncTCP/src/SyncClient.cpp
new file mode 100644
index 00000000..df9489f7
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/SyncClient.cpp
@@ -0,0 +1,286 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#include "SyncClient.h"
+#include "Arduino.h"
+#include "ESPAsyncTCP.h"
+#include "cbuf.h"
+
+
+SyncClient::SyncClient(size_t txBufLen)
+ : _client(NULL)
+ , _tx_buffer(NULL)
+ , _tx_buffer_size(txBufLen)
+ , _rx_buffer(NULL)
+{}
+
+SyncClient::SyncClient(AsyncClient *client, size_t txBufLen)
+ : _client(client)
+ , _tx_buffer(new cbuf(txBufLen))
+ , _tx_buffer_size(txBufLen)
+ , _rx_buffer(NULL)
+{
+ _attachCallbacks();
+}
+
+SyncClient::~SyncClient(){
+ if(_tx_buffer != NULL){
+ cbuf *b = _tx_buffer;
+ _tx_buffer = NULL;
+ delete b;
+ }
+ while(_rx_buffer != NULL){
+ cbuf *b = _rx_buffer;
+ _rx_buffer = _rx_buffer->next;
+ delete b;
+ }
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+int SyncClient::connect(IPAddress ip, uint16_t port, bool secure){
+#else
+int SyncClient::connect(IPAddress ip, uint16_t port){
+#endif
+ if(_client != NULL && connected())
+ return 0;
+ _client = new AsyncClient();
+ _client->onConnect([](void *obj, AsyncClient *c){ ((SyncClient*)(obj))->_onConnect(c); }, this);
+ _attachCallbacks_Disconnect();
+#if ASYNC_TCP_SSL_ENABLED
+ if(_client->connect(ip, port, secure)){
+#else
+ if(_client->connect(ip, port)){
+#endif
+ while(_client != NULL && !_client->connected() && !_client->disconnecting())
+ delay(1);
+ return connected();
+ }
+ return 0;
+}
+
+#if ASYNC_TCP_SSL_ENABLED
+int SyncClient::connect(const char *host, uint16_t port, bool secure){
+#else
+int SyncClient::connect(const char *host, uint16_t port){
+#endif
+ if(_client != NULL && connected()){
+ return 0;
+ }
+ _client = new AsyncClient();
+ _client->onConnect([](void *obj, AsyncClient *c){ ((SyncClient*)(obj))->_onConnect(c); }, this);
+ _attachCallbacks_Disconnect();
+#if ASYNC_TCP_SSL_ENABLED
+ if(_client->connect(host, port, secure)){
+#else
+ if(_client->connect(host, port)){
+#endif
+ while(_client != NULL && !_client->connected() && !_client->disconnecting())
+ delay(1);
+ return connected();
+ }
+ return 0;
+}
+
+SyncClient & SyncClient::operator=(const SyncClient &other){
+ if(_client != NULL){
+ _client->abort();
+ _client->free();
+ _client = NULL;
+ }
+ _tx_buffer_size = other._tx_buffer_size;
+ if(_tx_buffer != NULL){
+ cbuf *b = _tx_buffer;
+ _tx_buffer = NULL;
+ delete b;
+ }
+ while(_rx_buffer != NULL){
+ cbuf *b = _rx_buffer;
+ _rx_buffer = b->next;
+ delete b;
+ }
+ _tx_buffer = new cbuf(other._tx_buffer_size);
+ _client = other._client;
+ _attachCallbacks();
+ return *this;
+}
+
+void SyncClient::setTimeout(uint32_t seconds){
+ if(_client != NULL)
+ _client->setRxTimeout(seconds);
+}
+
+uint8_t SyncClient::status(){
+ if(_client == NULL)
+ return 0;
+ return _client->state();
+}
+
+uint8_t SyncClient::connected(){
+ return (_client != NULL && _client->connected());
+}
+
+void SyncClient::stop(){
+ if(_client != NULL)
+ _client->close(true);
+}
+
+size_t SyncClient::_sendBuffer(){
+ size_t available = _tx_buffer->available();
+ if(!connected() || !_client->canSend() || available == 0)
+ return 0;
+ size_t sendable = _client->space();
+ if(sendable < available)
+ available= sendable;
+ char *out = new char[available];
+ _tx_buffer->read(out, available);
+ size_t sent = _client->write(out, available);
+ delete[] out;
+ return sent;
+}
+
+void SyncClient::_onData(void *data, size_t len){
+ _client->ackLater();
+ cbuf *b = new cbuf(len+1);
+ if(b != NULL){
+ b->write((const char *)data, len);
+ if(_rx_buffer == NULL)
+ _rx_buffer = b;
+ else {
+ cbuf *p = _rx_buffer;
+ while(p->next != NULL)
+ p = p->next;
+ p->next = b;
+ }
+ }
+}
+
+void SyncClient::_onDisconnect(){
+ if(_client != NULL){
+ _client = NULL;
+ }
+ if(_tx_buffer != NULL){
+ cbuf *b = _tx_buffer;
+ _tx_buffer = NULL;
+ delete b;
+ }
+}
+
+void SyncClient::_onConnect(AsyncClient *c){
+ _client = c;
+ if(_tx_buffer != NULL){
+ cbuf *b = _tx_buffer;
+ _tx_buffer = NULL;
+ delete b;
+ }
+ _tx_buffer = new cbuf(_tx_buffer_size);
+ _attachCallbacks_AfterConnected();
+}
+
+void SyncClient::_attachCallbacks(){
+ _attachCallbacks_Disconnect();
+ _attachCallbacks_AfterConnected();
+}
+
+void SyncClient::_attachCallbacks_AfterConnected(){
+ _client->onAck([](void *obj, AsyncClient* c, size_t len, uint32_t time){ ((SyncClient*)(obj))->_sendBuffer(); }, this);
+ _client->onData([](void *obj, AsyncClient* c, void *data, size_t len){ ((SyncClient*)(obj))->_onData(data, len); }, this);
+ _client->onTimeout([](void *obj, AsyncClient* c, uint32_t time){ c->close(); }, this);
+}
+
+void SyncClient::_attachCallbacks_Disconnect(){
+ _client->onDisconnect([](void *obj, AsyncClient* c){ ((SyncClient*)(obj))->_onDisconnect(); delete c; }, this);
+}
+
+size_t SyncClient::write(uint8_t data){
+ return write(&data, 1);
+}
+
+size_t SyncClient::write(const uint8_t *data, size_t len){
+ if(_tx_buffer == NULL || !connected()){
+ return 0;
+ }
+ size_t toWrite = 0;
+ size_t toSend = len;
+ while(_tx_buffer->room() < toSend){
+ toWrite = _tx_buffer->room();
+ _tx_buffer->write((const char*)data, toWrite);
+ while(!_client->canSend() && connected())
+ delay(0);
+ _sendBuffer();
+ toSend -= toWrite;
+ }
+ _tx_buffer->write((const char*)(data+(len - toSend)), toSend);
+ if(_client->canSend() && connected())
+ _sendBuffer();
+ return len;
+}
+
+int SyncClient::available(){
+ if(_rx_buffer == NULL) return 0;
+ size_t a = 0;
+ cbuf *b = _rx_buffer;
+ while(b != NULL){
+ a += b->available();
+ b = b->next;
+ }
+ return a;
+}
+
+int SyncClient::peek(){
+ if(_rx_buffer == NULL) return -1;
+ return _rx_buffer->peek();
+}
+
+int SyncClient::read(uint8_t *data, size_t len){
+ if(_rx_buffer == NULL) return -1;
+
+ size_t readSoFar = 0;
+ while(_rx_buffer != NULL && (len - readSoFar) >= _rx_buffer->available()){
+ cbuf *b = _rx_buffer;
+ _rx_buffer = _rx_buffer->next;
+ size_t toRead = b->available();
+ readSoFar += b->read((char*)(data+readSoFar), toRead);
+ if(connected()){
+ _client->ack(b->size() - 1);
+ }
+ delete b;
+ }
+ if(_rx_buffer != NULL && readSoFar < len){
+ readSoFar += _rx_buffer->read((char*)(data+readSoFar), (len - readSoFar));
+ }
+ return readSoFar;
+}
+
+int SyncClient::read(){
+ uint8_t res = 0;
+ if(read(&res, 1) != 1)
+ return -1;
+ return res;
+}
+
+void SyncClient::flush(){
+ if(_tx_buffer == NULL || !connected())
+ return;
+ if(_tx_buffer->available()){
+ while(!_client->canSend() && connected())
+ delay(0);
+ _sendBuffer();
+ }
+}
diff --git a/libraries/ESPAsyncTCP/src/SyncClient.h b/libraries/ESPAsyncTCP/src/SyncClient.h
new file mode 100644
index 00000000..e46f4e48
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/SyncClient.h
@@ -0,0 +1,82 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef SYNCCLIENT_H_
+#define SYNCCLIENT_H_
+
+#include "Client.h"
+#include
+class cbuf;
+class AsyncClient;
+
+class SyncClient: public Client {
+ private:
+ AsyncClient *_client;
+ cbuf *_tx_buffer;
+ size_t _tx_buffer_size;
+ cbuf *_rx_buffer;
+
+ size_t _sendBuffer();
+ void _onData(void *data, size_t len);
+ void _onConnect(AsyncClient *c);
+ void _onDisconnect();
+ void _attachCallbacks();
+ void _attachCallbacks_Disconnect();
+ void _attachCallbacks_AfterConnected();
+
+ public:
+ SyncClient(size_t txBufLen = 1460);
+ SyncClient(AsyncClient *client, size_t txBufLen = 1460);
+ virtual ~SyncClient();
+
+ operator bool(){ return connected(); }
+ SyncClient & operator=(const SyncClient &other);
+
+#if ASYNC_TCP_SSL_ENABLED
+ int connect(IPAddress ip, uint16_t port, bool secure);
+ int connect(const char *host, uint16_t port, bool secure);
+ int connect(IPAddress ip, uint16_t port){
+ return connect(ip, port, false);
+ }
+ int connect(const char *host, uint16_t port){
+ return connect(host, port, false);
+ }
+#else
+ int connect(IPAddress ip, uint16_t port);
+ int connect(const char *host, uint16_t port);
+#endif
+ void setTimeout(uint32_t seconds);
+
+ uint8_t status();
+ uint8_t connected();
+ void stop();
+
+ size_t write(uint8_t data);
+ size_t write(const uint8_t *data, size_t len);
+
+ int available();
+ int peek();
+ int read();
+ int read(uint8_t *data, size_t len);
+ void flush();
+};
+
+#endif /* SYNCCLIENT_H_ */
diff --git a/libraries/ESPAsyncTCP/src/async_config.h b/libraries/ESPAsyncTCP/src/async_config.h
new file mode 100644
index 00000000..61cfc25d
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/async_config.h
@@ -0,0 +1,11 @@
+#ifndef LIBRARIES_ESPASYNCTCP_SRC_ASYNC_CONFIG_H_
+#define LIBRARIES_ESPASYNCTCP_SRC_ASYNC_CONFIG_H_
+
+#ifndef ASYNC_TCP_SSL_ENABLED
+#define ASYNC_TCP_SSL_ENABLED 0
+#endif
+
+#define ASYNC_TCP_DEBUG(...) //ets_printf(__VA_ARGS__)
+#define TCP_SSL_DEBUG(...) //ets_printf(__VA_ARGS__)
+
+#endif /* LIBRARIES_ESPASYNCTCP_SRC_ASYNC_CONFIG_H_ */
diff --git a/libraries/ESPAsyncTCP/src/tcp_axtls.c b/libraries/ESPAsyncTCP/src/tcp_axtls.c
new file mode 100644
index 00000000..2a7b9663
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/tcp_axtls.c
@@ -0,0 +1,586 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+/*
+ * Compatibility for AxTLS with LWIP raw tcp mode (http://lwip.wikia.com/wiki/Raw/TCP)
+ * Original Code and Inspiration: Slavey Karadzhov
+ */
+#include
+#if ASYNC_TCP_SSL_ENABLED
+
+#include "lwip/opt.h"
+#include "lwip/tcp.h"
+#include "lwip/inet.h"
+#include
+#include
+#include
+#include
+
+uint8_t * default_private_key = NULL;
+uint16_t default_private_key_len = 0;
+
+uint8_t * default_certificate = NULL;
+uint16_t default_certificate_len = 0;
+
+static uint8_t _tcp_ssl_has_client = 0;
+
+SSL_CTX * tcp_ssl_new_server_ctx(const char *cert, const char *private_key_file, const char *password){
+ uint32_t options = SSL_CONNECT_IN_PARTS;
+ SSL_CTX *ssl_ctx;
+
+ if(private_key_file){
+ options |= SSL_NO_DEFAULT_KEY;
+ }
+
+ if ((ssl_ctx = ssl_ctx_new(options, SSL_DEFAULT_SVR_SESS)) == NULL){
+ TCP_SSL_DEBUG("tcp_ssl_new_server_ctx: failed to allocate context\n");
+ return NULL;
+ }
+
+ if (private_key_file){
+ int obj_type = SSL_OBJ_RSA_KEY;
+ if (strstr(private_key_file, ".p8"))
+ obj_type = SSL_OBJ_PKCS8;
+ else if (strstr(private_key_file, ".p12"))
+ obj_type = SSL_OBJ_PKCS12;
+
+ if (ssl_obj_load(ssl_ctx, obj_type, private_key_file, password)){
+ TCP_SSL_DEBUG("tcp_ssl_new_server_ctx: load private key '%s' failed\n", private_key_file);
+ return NULL;
+ }
+ }
+
+ if (cert){
+ if (ssl_obj_load(ssl_ctx, SSL_OBJ_X509_CERT, cert, NULL)){
+ TCP_SSL_DEBUG("tcp_ssl_new_server_ctx: load certificate '%s' failed\n", cert);
+ return NULL;
+ }
+ }
+ return ssl_ctx;
+}
+
+struct tcp_ssl_pcb {
+ struct tcp_pcb *tcp;
+ int fd;
+ SSL_CTX* ssl_ctx;
+ SSL *ssl;
+ uint8_t type;
+ int handshake;
+ void * arg;
+ tcp_ssl_data_cb_t on_data;
+ tcp_ssl_handshake_cb_t on_handshake;
+ tcp_ssl_error_cb_t on_error;
+ int last_wr;
+ struct pbuf *tcp_pbuf;
+ int pbuf_offset;
+ struct tcp_ssl_pcb * next;
+};
+
+typedef struct tcp_ssl_pcb tcp_ssl_t;
+
+static tcp_ssl_t * tcp_ssl_array = NULL;
+static int tcp_ssl_next_fd = 0;
+
+uint8_t tcp_ssl_has_client(){
+ return _tcp_ssl_has_client;
+}
+
+tcp_ssl_t * tcp_ssl_new(struct tcp_pcb *tcp) {
+
+ if(tcp_ssl_next_fd < 0){
+ tcp_ssl_next_fd = 0;//overflow
+ }
+
+ tcp_ssl_t * new_item = (tcp_ssl_t*)malloc(sizeof(tcp_ssl_t));
+ if(!new_item){
+ TCP_SSL_DEBUG("tcp_ssl_new: failed to allocate tcp_ssl\n");
+ return NULL;
+ }
+
+ new_item->tcp = tcp;
+ new_item->handshake = SSL_NOT_OK;
+ new_item->arg = NULL;
+ new_item->on_data = NULL;
+ new_item->on_handshake = NULL;
+ new_item->on_error = NULL;
+ new_item->tcp_pbuf = NULL;
+ new_item->pbuf_offset = 0;
+ new_item->next = NULL;
+ new_item->ssl_ctx = NULL;
+ new_item->ssl = NULL;
+ new_item->type = TCP_SSL_TYPE_CLIENT;
+ new_item->fd = tcp_ssl_next_fd++;
+
+ if(tcp_ssl_array == NULL){
+ tcp_ssl_array = new_item;
+ } else {
+ tcp_ssl_t * item = tcp_ssl_array;
+ while(item->next != NULL)
+ item = item->next;
+ item->next = new_item;
+ }
+
+ TCP_SSL_DEBUG("tcp_ssl_new: %d\n", new_item->fd);
+ return new_item;
+}
+
+tcp_ssl_t* tcp_ssl_get(struct tcp_pcb *tcp) {
+ if(tcp == NULL) {
+ return NULL;
+ }
+ tcp_ssl_t * item = tcp_ssl_array;
+ while(item && item->tcp != tcp){
+ item = item->next;
+ }
+ return item;
+}
+
+int tcp_ssl_new_client(struct tcp_pcb *tcp){
+ SSL_CTX* ssl_ctx;
+ tcp_ssl_t * tcp_ssl;
+
+ if(tcp == NULL) {
+ return -1;
+ }
+
+ if(tcp_ssl_get(tcp) != NULL){
+ TCP_SSL_DEBUG("tcp_ssl_new_client: tcp_ssl already exists\n");
+ return -1;
+ }
+
+ ssl_ctx = ssl_ctx_new(SSL_CONNECT_IN_PARTS | SSL_SERVER_VERIFY_LATER, 1);
+ if(ssl_ctx == NULL){
+ TCP_SSL_DEBUG("tcp_ssl_new_client: failed to allocate ssl context\n");
+ return -1;
+ }
+
+ tcp_ssl = tcp_ssl_new(tcp);
+ if(tcp_ssl == NULL){
+ ssl_ctx_free(ssl_ctx);
+ return -1;
+ }
+
+ tcp_ssl->ssl_ctx = ssl_ctx;
+
+ tcp_ssl->ssl = ssl_client_new(ssl_ctx, tcp_ssl->fd, NULL, 0, NULL);
+ if(tcp_ssl->ssl == NULL){
+ TCP_SSL_DEBUG("tcp_ssl_new_client: failed to allocate ssl\n");
+ tcp_ssl_free(tcp);
+ return -1;
+ }
+
+ return tcp_ssl->fd;
+}
+
+int tcp_ssl_new_server(struct tcp_pcb *tcp, SSL_CTX* ssl_ctx){
+ tcp_ssl_t * tcp_ssl;
+
+ if(tcp == NULL) {
+ return -1;
+ }
+
+ if(ssl_ctx == NULL){
+ return -1;
+ }
+
+ if(tcp_ssl_get(tcp) != NULL){
+ TCP_SSL_DEBUG("tcp_ssl_new_server: tcp_ssl already exists\n");
+ return -1;
+ }
+
+ tcp_ssl = tcp_ssl_new(tcp);
+ if(tcp_ssl == NULL){
+ return -1;
+ }
+
+ tcp_ssl->type = TCP_SSL_TYPE_SERVER;
+ tcp_ssl->ssl_ctx = ssl_ctx;
+
+ _tcp_ssl_has_client = 1;
+ tcp_ssl->ssl = ssl_server_new(ssl_ctx, tcp_ssl->fd);
+ if(tcp_ssl->ssl == NULL){
+ TCP_SSL_DEBUG("tcp_ssl_new_server: failed to allocate ssl\n");
+ tcp_ssl_free(tcp);
+ return -1;
+ }
+
+ return tcp_ssl->fd;
+}
+
+int tcp_ssl_free(struct tcp_pcb *tcp) {
+
+ if(tcp == NULL) {
+ return -1;
+ }
+
+ tcp_ssl_t * item = tcp_ssl_array;
+
+ if(item->tcp == tcp){
+ tcp_ssl_array = tcp_ssl_array->next;
+ if(item->tcp_pbuf != NULL){
+ pbuf_free(item->tcp_pbuf);
+ }
+ TCP_SSL_DEBUG("tcp_ssl_free: %d\n", item->fd);
+ if(item->ssl)
+ ssl_free(item->ssl);
+ if(item->type == TCP_SSL_TYPE_CLIENT && item->ssl_ctx)
+ ssl_ctx_free(item->ssl_ctx);
+ if(item->type == TCP_SSL_TYPE_SERVER)
+ _tcp_ssl_has_client = 0;
+ free(item);
+ return 0;
+ }
+
+ while(item->next && item->next->tcp != tcp)
+ item = item->next;
+
+ if(item->next == NULL){
+ return ERR_TCP_SSL_INVALID_CLIENTFD_DATA;//item not found
+ }
+
+ tcp_ssl_t * i = item->next;
+ item->next = i->next;
+ if(i->tcp_pbuf != NULL){
+ pbuf_free(i->tcp_pbuf);
+ }
+ TCP_SSL_DEBUG("tcp_ssl_free: %d\n", i->fd);
+ if(i->ssl)
+ ssl_free(i->ssl);
+ if(i->type == TCP_SSL_TYPE_CLIENT && i->ssl_ctx)
+ ssl_ctx_free(i->ssl_ctx);
+ if(i->type == TCP_SSL_TYPE_SERVER)
+ _tcp_ssl_has_client = 0;
+ free(i);
+ return 0;
+}
+
+#ifdef AXTLS_2_0_0_SNDBUF
+int tcp_ssl_sndbuf(struct tcp_pcb *tcp){
+ int expected;
+ int available;
+ int result = -1;
+
+ if(tcp == NULL) {
+ return result;
+ }
+ tcp_ssl_t * tcp_ssl = tcp_ssl_get(tcp);
+ if(!tcp_ssl){
+ TCP_SSL_DEBUG("tcp_ssl_sndbuf: tcp_ssl is NULL\n");
+ return result;
+ }
+ available = tcp_sndbuf(tcp);
+ if(!available){
+ TCP_SSL_DEBUG("tcp_ssl_sndbuf: tcp_sndbuf is zero\n");
+ return 0;
+ }
+ result = available;
+ while((expected = ssl_calculate_write_length(tcp_ssl->ssl, result)) > available){
+ result -= (expected - available) + 4;
+ }
+
+ if(expected > 0){
+ //TCP_SSL_DEBUG("tcp_ssl_sndbuf: tcp_sndbuf is %d from %d\n", result, available);
+ return result;
+ }
+
+ return 0;
+}
+#endif
+
+int tcp_ssl_write(struct tcp_pcb *tcp, uint8_t *data, size_t len) {
+ if(tcp == NULL) {
+ return -1;
+ }
+ tcp_ssl_t * tcp_ssl = tcp_ssl_get(tcp);
+ if(!tcp_ssl){
+ TCP_SSL_DEBUG("tcp_ssl_write: tcp_ssl is NULL\n");
+ return 0;
+ }
+ tcp_ssl->last_wr = 0;
+
+#ifdef AXTLS_2_0_0_SNDBUF
+ int expected_len = ssl_calculate_write_length(tcp_ssl->ssl, len);
+ int available_len = tcp_sndbuf(tcp);
+ if(expected_len < 0 || expected_len > available_len){
+ TCP_SSL_DEBUG("tcp_ssl_write: data will not fit! %u < %d(%u)\r\n", available_len, expected_len, len);
+ return -1;
+ }
+#endif
+
+ int rc = ssl_write(tcp_ssl->ssl, data, len);
+
+ //TCP_SSL_DEBUG("tcp_ssl_write: %u -> %d (%d)\r\n", len, tcp_ssl->last_wr, rc);
+
+ if (rc < 0){
+ if(rc != SSL_CLOSE_NOTIFY) {
+ TCP_SSL_DEBUG("tcp_ssl_write error: %d\r\n", rc);
+ }
+ return rc;
+ }
+
+ return tcp_ssl->last_wr;
+}
+
+/**
+ * Reads data from the SSL over TCP stream. Returns decrypted data.
+ * @param tcp_pcb *tcp - pointer to the raw tcp object
+ * @param pbuf *p - pointer to the buffer with the TCP packet data
+ *
+ * @return int
+ * 0 - when everything is fine but there are no symbols to process yet
+ * < 0 - when there is an error
+ * > 0 - the length of the clear text characters that were read
+ */
+int tcp_ssl_read(struct tcp_pcb *tcp, struct pbuf *p) {
+ if(tcp == NULL) {
+ return -1;
+ }
+ tcp_ssl_t* fd_data = NULL;
+
+ int read_bytes = 0;
+ int total_bytes = 0;
+ uint8_t *read_buf;
+
+ fd_data = tcp_ssl_get(tcp);
+ if(fd_data == NULL) {
+ TCP_SSL_DEBUG("tcp_ssl_read: tcp_ssl is NULL\n");
+ return ERR_TCP_SSL_INVALID_CLIENTFD_DATA;
+ }
+
+ if(p == NULL) {
+ TCP_SSL_DEBUG("tcp_ssl_read:p == NULL\n");
+ return ERR_TCP_SSL_INVALID_DATA;
+ }
+
+ //TCP_SSL_DEBUG("READY TO READ SOME DATA\n");
+
+ fd_data->tcp_pbuf = p;
+ fd_data->pbuf_offset = 0;
+
+ do {
+ read_bytes = ssl_read(fd_data->ssl, &read_buf);
+ //TCP_SSL_DEBUG("tcp_ssl_ssl_read: %d\n", read_bytes);
+ if(read_bytes < SSL_OK) {
+ if(read_bytes != SSL_CLOSE_NOTIFY) {
+ TCP_SSL_DEBUG("tcp_ssl_read: read error: %d\n", read_bytes);
+ }
+ total_bytes = read_bytes;
+ break;
+ } else if(read_bytes > 0){
+ if(fd_data->on_data){
+ fd_data->on_data(fd_data->arg, tcp, read_buf, read_bytes);
+ }
+ total_bytes+= read_bytes;
+ } else {
+ if(fd_data->handshake != SSL_OK) {
+ fd_data->handshake = ssl_handshake_status(fd_data->ssl);
+ if(fd_data->handshake == SSL_OK){
+ //TCP_SSL_DEBUG("tcp_ssl_read: handshake OK\n");
+ if(fd_data->on_handshake)
+ fd_data->on_handshake(fd_data->arg, fd_data->tcp, fd_data->ssl);
+ } else if(fd_data->handshake != SSL_NOT_OK){
+ TCP_SSL_DEBUG("tcp_ssl_read: handshake error: %d\n", fd_data->handshake);
+ if(fd_data->on_error)
+ fd_data->on_error(fd_data->arg, fd_data->tcp, fd_data->handshake);
+ return fd_data->handshake;
+ }
+ }
+ }
+ } while (p->tot_len - fd_data->pbuf_offset > 0);
+
+ tcp_recved(tcp, p->tot_len);
+ pbuf_free(p);
+
+ return total_bytes;
+}
+
+SSL * tcp_ssl_get_ssl(struct tcp_pcb *tcp){
+ tcp_ssl_t * tcp_ssl = tcp_ssl_get(tcp);
+ if(tcp_ssl){
+ return tcp_ssl->ssl;
+ }
+ return NULL;
+}
+
+bool tcp_ssl_has(struct tcp_pcb *tcp){
+ return tcp_ssl_get(tcp) != NULL;
+}
+
+int tcp_ssl_is_server(struct tcp_pcb *tcp){
+ tcp_ssl_t * tcp_ssl = tcp_ssl_get(tcp);
+ if(tcp_ssl){
+ return tcp_ssl->type;
+ }
+ return -1;
+}
+
+void tcp_ssl_arg(struct tcp_pcb *tcp, void * arg){
+ tcp_ssl_t * item = tcp_ssl_get(tcp);
+ if(item) {
+ item->arg = arg;
+ }
+}
+
+void tcp_ssl_data(struct tcp_pcb *tcp, tcp_ssl_data_cb_t arg){
+ tcp_ssl_t * item = tcp_ssl_get(tcp);
+ if(item) {
+ item->on_data = arg;
+ }
+}
+
+void tcp_ssl_handshake(struct tcp_pcb *tcp, tcp_ssl_handshake_cb_t arg){
+ tcp_ssl_t * item = tcp_ssl_get(tcp);
+ if(item) {
+ item->on_handshake = arg;
+ }
+}
+
+void tcp_ssl_err(struct tcp_pcb *tcp, tcp_ssl_error_cb_t arg){
+ tcp_ssl_t * item = tcp_ssl_get(tcp);
+ if(item) {
+ item->on_error = arg;
+ }
+}
+
+static tcp_ssl_file_cb_t _tcp_ssl_file_cb = NULL;
+static void * _tcp_ssl_file_arg = NULL;
+
+void tcp_ssl_file(tcp_ssl_file_cb_t cb, void * arg){
+ _tcp_ssl_file_cb = cb;
+ _tcp_ssl_file_arg = arg;
+}
+
+int ax_get_file(const char *filename, uint8_t **buf) {
+ //TCP_SSL_DEBUG("ax_get_file: %s\n", filename);
+ if(_tcp_ssl_file_cb){
+ return _tcp_ssl_file_cb(_tcp_ssl_file_arg, filename, buf);
+ }
+ *buf = 0;
+ return 0;
+}
+
+tcp_ssl_t* tcp_ssl_get_by_fd(int fd) {
+ tcp_ssl_t * item = tcp_ssl_array;
+ while(item && item->fd != fd){
+ item = item->next;
+ }
+ return item;
+}
+/*
+ * The LWIP tcp raw version of the SOCKET_WRITE(A, B, C)
+ */
+int ax_port_write(int fd, uint8_t *data, uint16_t len) {
+ tcp_ssl_t *fd_data = NULL;
+ int tcp_len = 0;
+ err_t err = ERR_OK;
+
+ //TCP_SSL_DEBUG("ax_port_write: %d, %d\n", fd, len);
+
+ fd_data = tcp_ssl_get_by_fd(fd);
+ if(fd_data == NULL) {
+ //TCP_SSL_DEBUG("ax_port_write: tcp_ssl[%d] is NULL\n", fd);
+ return ERR_MEM;
+ }
+
+ if (data == NULL || len == 0) {
+ return 0;
+ }
+
+ if (tcp_sndbuf(fd_data->tcp) < len) {
+ tcp_len = tcp_sndbuf(fd_data->tcp);
+ if(tcp_len == 0) {
+ TCP_SSL_DEBUG("ax_port_write: tcp_sndbuf is zero: %d\n", len);
+ return ERR_MEM;
+ }
+ } else {
+ tcp_len = len;
+ }
+
+ if (tcp_len > 2 * fd_data->tcp->mss) {
+ tcp_len = 2 * fd_data->tcp->mss;
+ }
+
+ err = tcp_write(fd_data->tcp, data, tcp_len, TCP_WRITE_FLAG_COPY);
+ if(err < ERR_OK) {
+ if (err == ERR_MEM) {
+ TCP_SSL_DEBUG("ax_port_write: No memory %d (%d)\n", tcp_len, len);
+ return err;
+ }
+ TCP_SSL_DEBUG("ax_port_write: tcp_write error: %d\n", err);
+ return err;
+ } else if (err == ERR_OK) {
+ //TCP_SSL_DEBUG("ax_port_write: tcp_output: %d / %d\n", tcp_len, len);
+ err = tcp_output(fd_data->tcp);
+ if(err != ERR_OK) {
+ TCP_SSL_DEBUG("ax_port_write: tcp_output err: %d\n", err);
+ return err;
+ }
+ }
+
+ fd_data->last_wr += tcp_len;
+
+ return tcp_len;
+}
+
+/*
+ * The LWIP tcp raw version of the SOCKET_READ(A, B, C)
+ */
+int ax_port_read(int fd, uint8_t *data, int len) {
+ tcp_ssl_t *fd_data = NULL;
+ uint8_t *read_buf = NULL;
+ uint8_t *pread_buf = NULL;
+ u16_t recv_len = 0;
+
+ //TCP_SSL_DEBUG("ax_port_read: %d, %d\n", fd, len);
+
+ fd_data = tcp_ssl_get_by_fd(fd);
+ if (fd_data == NULL) {
+ TCP_SSL_DEBUG("ax_port_read: tcp_ssl[%d] is NULL\n", fd);
+ return ERR_TCP_SSL_INVALID_CLIENTFD_DATA;
+ }
+
+ if(fd_data->tcp_pbuf == NULL || fd_data->tcp_pbuf->tot_len == 0) {
+ return 0;
+ }
+
+ read_buf =(uint8_t*)calloc(fd_data->tcp_pbuf->len + 1, sizeof(uint8_t));
+ pread_buf = read_buf;
+ if (pread_buf != NULL){
+ recv_len = pbuf_copy_partial(fd_data->tcp_pbuf, read_buf, len, fd_data->pbuf_offset);
+ fd_data->pbuf_offset += recv_len;
+ }
+
+ if (recv_len != 0) {
+ memcpy(data, read_buf, recv_len);
+ }
+
+ if(len < recv_len) {
+ TCP_SSL_DEBUG("ax_port_read: got %d bytes more than expected\n", recv_len - len);
+ }
+
+ free(pread_buf);
+ pread_buf = NULL;
+
+ return recv_len;
+}
+
+void ax_wdt_feed() {}
+
+#endif
diff --git a/libraries/ESPAsyncTCP/src/tcp_axtls.h b/libraries/ESPAsyncTCP/src/tcp_axtls.h
new file mode 100644
index 00000000..57a0e52c
--- /dev/null
+++ b/libraries/ESPAsyncTCP/src/tcp_axtls.h
@@ -0,0 +1,97 @@
+/*
+ Asynchronous TCP library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+/*
+ * Compatibility for AxTLS with LWIP raw tcp mode (http://lwip.wikia.com/wiki/Raw/TCP)
+ * Original Code and Inspiration: Slavey Karadzhov
+ */
+
+#ifndef LWIPR_COMPAT_H
+#define LWIPR_COMPAT_H
+
+#include
+
+#if ASYNC_TCP_SSL_ENABLED
+
+#include "lwipopts.h"
+/*
+ * All those functions will run only if LWIP tcp raw mode is used
+ */
+#if LWIP_RAW==1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "include/ssl.h"
+
+#define ERR_TCP_SSL_INVALID_SSL -101
+#define ERR_TCP_SSL_INVALID_TCP -102
+#define ERR_TCP_SSL_INVALID_CLIENTFD -103
+#define ERR_TCP_SSL_INVALID_CLIENTFD_DATA -104
+#define ERR_TCP_SSL_INVALID_DATA -105
+
+#define TCP_SSL_TYPE_CLIENT 0
+#define TCP_SSL_TYPE_SERVER 1
+
+#define tcp_ssl_ssl_write(A, B, C) tcp_ssl_write(A, B, C)
+#define tcp_ssl_ssl_read(A, B) tcp_ssl_read(A, B)
+
+typedef void (* tcp_ssl_data_cb_t)(void *arg, struct tcp_pcb *tcp, uint8_t * data, size_t len);
+typedef void (* tcp_ssl_handshake_cb_t)(void *arg, struct tcp_pcb *tcp, SSL *ssl);
+typedef void (* tcp_ssl_error_cb_t)(void *arg, struct tcp_pcb *tcp, int8_t error);
+typedef int (* tcp_ssl_file_cb_t)(void *arg, const char *filename, uint8_t **buf);
+
+uint8_t tcp_ssl_has_client();
+
+int tcp_ssl_new_client(struct tcp_pcb *tcp);
+
+SSL_CTX * tcp_ssl_new_server_ctx(const char *cert, const char *private_key_file, const char *password);
+int tcp_ssl_new_server(struct tcp_pcb *tcp, SSL_CTX* ssl_ctx);
+int tcp_ssl_is_server(struct tcp_pcb *tcp);
+
+int tcp_ssl_free(struct tcp_pcb *tcp);
+int tcp_ssl_read(struct tcp_pcb *tcp, struct pbuf *p);
+
+#ifdef AXTLS_2_0_0_SNDBUF
+int tcp_ssl_sndbuf(struct tcp_pcb *tcp);
+#endif
+
+int tcp_ssl_write(struct tcp_pcb *tcp, uint8_t *data, size_t len);
+
+void tcp_ssl_file(tcp_ssl_file_cb_t cb, void * arg);
+
+void tcp_ssl_arg(struct tcp_pcb *tcp, void * arg);
+void tcp_ssl_data(struct tcp_pcb *tcp, tcp_ssl_data_cb_t arg);
+void tcp_ssl_handshake(struct tcp_pcb *tcp, tcp_ssl_handshake_cb_t arg);
+void tcp_ssl_err(struct tcp_pcb *tcp, tcp_ssl_error_cb_t arg);
+
+SSL * tcp_ssl_get_ssl(struct tcp_pcb *tcp);
+bool tcp_ssl_has(struct tcp_pcb *tcp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LWIP_RAW==1 */
+
+#endif /* ASYNC_TCP_SSL_ENABLED */
+
+#endif /* LWIPR_COMPAT_H */
diff --git a/libraries/ESPAsyncTCP/ssl/gen_server_cert.sh b/libraries/ESPAsyncTCP/ssl/gen_server_cert.sh
new file mode 100644
index 00000000..fd749ed4
--- /dev/null
+++ b/libraries/ESPAsyncTCP/ssl/gen_server_cert.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+cat > ca_cert.conf << EOF
+[ req ]
+distinguished_name = req_distinguished_name
+prompt = no
+
+[ req_distinguished_name ]
+ O = Espressif Systems
+EOF
+
+openssl genrsa -out axTLS.ca_key.pem 2048
+openssl req -new -config ./ca_cert.conf -key axTLS.ca_key.pem -out axTLS.ca_x509.req
+openssl x509 -req -sha1 -days 5000 -signkey axTLS.ca_key.pem -CAkey axTLS.ca_key.pem -in axTLS.ca_x509.req -out axTLS.ca_x509.pem
+
+cat > certs.conf << EOF
+[ req ]
+distinguished_name = req_distinguished_name
+prompt = no
+
+[ req_distinguished_name ]
+ O = axTLS on ESP8266
+ CN = esp8266.local
+EOF
+
+openssl genrsa -out axTLS.key_1024.pem 1024
+openssl req -new -config ./certs.conf -key axTLS.key_1024.pem -out axTLS.x509_1024.req
+openssl x509 -req -sha1 -CAcreateserial -days 5000 -CA axTLS.ca_x509.pem -CAkey axTLS.ca_key.pem -in axTLS.x509_1024.req -out axTLS.x509_1024.pem
+
+openssl rsa -outform DER -in axTLS.key_1024.pem -out axTLS.key_1024
+openssl x509 -outform DER -in axTLS.x509_1024.pem -out axTLS.x509_1024.cer
+
+cat axTLS.key_1024 > server.key
+cat axTLS.x509_1024.cer > server.cer
+
+rm axTLS.* ca_cert.conf certs.conf
diff --git a/libraries/ESPAsyncTCP/ssl/server.cer b/libraries/ESPAsyncTCP/ssl/server.cer
new file mode 100644
index 00000000..b5e5f248
Binary files /dev/null and b/libraries/ESPAsyncTCP/ssl/server.cer differ
diff --git a/libraries/ESPAsyncTCP/ssl/server.key b/libraries/ESPAsyncTCP/ssl/server.key
new file mode 100644
index 00000000..1b7095f9
Binary files /dev/null and b/libraries/ESPAsyncTCP/ssl/server.key differ
diff --git a/libraries/ESPAsyncTCP/travis/common.sh b/libraries/ESPAsyncTCP/travis/common.sh
new file mode 100644
index 00000000..57bede34
--- /dev/null
+++ b/libraries/ESPAsyncTCP/travis/common.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+function build_sketches()
+{
+ local arduino=$1
+ local srcpath=$2
+ local platform=$3
+ local sketches=$(find $srcpath -name *.ino)
+ for sketch in $sketches; do
+ local sketchdir=$(dirname $sketch)
+ if [[ -f "$sketchdir/.$platform.skip" ]]; then
+ echo -e "\n\n ------------ Skipping $sketch ------------ \n\n";
+ continue
+ fi
+ echo -e "\n\n ------------ Building $sketch ------------ \n\n";
+ $arduino --verify $sketch;
+ local result=$?
+ if [ $result -ne 0 ]; then
+ echo "Build failed ($1)"
+ return $result
+ fi
+ done
+}
diff --git a/libraries/ESPAsyncWebServer/.travis.yml b/libraries/ESPAsyncWebServer/.travis.yml
new file mode 100644
index 00000000..ce0228f4
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/.travis.yml
@@ -0,0 +1,39 @@
+sudo: false
+language: bash
+os:
+ - linux
+
+script:
+ - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
+ - sleep 3
+ - export DISPLAY=:1.0
+ - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
+ - tar xf arduino-1.6.5-linux64.tar.xz
+ - mv arduino-1.6.5 $HOME/arduino_ide
+ - export PATH="$HOME/arduino_ide:$PATH"
+ - which arduino
+ - mkdir -p $HOME/Arduino/libraries
+ - cp -r $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/ESPAsyncWebServer
+ - git clone https://github.com/bblanchon/ArduinoJson $HOME/Arduino/libraries/ArduinoJson
+ - git clone https://github.com/me-no-dev/ESPAsyncTCP $HOME/Arduino/libraries/ESPAsyncTCP
+ - cd $HOME/arduino_ide/hardware
+ - mkdir esp8266com
+ - cd esp8266com
+ - git clone https://github.com/esp8266/Arduino.git esp8266
+ - cd esp8266/tools
+ - python get.py
+ - source $TRAVIS_BUILD_DIR/travis/common.sh
+ - arduino --board esp8266com:esp8266:generic --save-prefs
+ - arduino --get-pref sketchbook.path
+ - build_sketches arduino $HOME/Arduino/libraries/ESPAsyncWebServer esp8266
+
+notifications:
+ email:
+ on_success: change
+ on_failure: change
+ webhooks:
+ urls:
+ - https://webhooks.gitter.im/e/60e65d0c78ea0a920347
+ on_success: change # options: [always|never|change] default: always
+ on_failure: always # options: [always|never|change] default: always
+ on_start: false # default: false
diff --git a/libraries/ESPAsyncWebServer/README.md b/libraries/ESPAsyncWebServer/README.md
new file mode 100644
index 00000000..b58a9021
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/README.md
@@ -0,0 +1,1368 @@
+# ESPAsyncWebServer [](https://travis-ci.org/me-no-dev/ESPAsyncWebServer)
+
+For help and support [](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+
+Async HTTP and WebSocket Server for ESP8266 Arduino
+
+For ESP8266 it requires [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP)
+To use this library you might need to have the latest git versions of [ESP8266](https://github.com/esp8266/Arduino) Arduino Core
+
+For ESP32 it requires [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) to work
+To use this library you might need to have the latest git versions of [ESP32](https://github.com/espressif/arduino-esp32) Arduino Core
+
+## Table of contents
+- [ESPAsyncWebServer ](#espasyncwebserver-)
+ - [Why should you care](#why-should-you-care)
+ - [Important things to remember](#important-things-to-remember)
+ - [Principles of operation](#principles-of-operation)
+ - [The Async Web server](#the-async-web-server)
+ - [Request Life Cycle](#request-life-cycle)
+ - [Rewrites and how do they work](#rewrites-and-how-do-they-work)
+ - [Handlers and how do they work](#handlers-and-how-do-they-work)
+ - [Responses and how do they work](#responses-and-how-do-they-work)
+ - [Template processing](#template-processing)
+ - [Libraries and projects that use AsyncWebServer](#libraries-and-projects-that-use-asyncwebserver)
+ - [Request Variables](#request-variables)
+ - [Common Variables](#common-variables)
+ - [Headers](#headers)
+ - [GET, POST and FILE parameters](#get-post-and-file-parameters)
+ - [FILE Upload handling](#file-upload-handling)
+ - [Body data handling](#body-data-handling)
+ - [Responses](#responses)
+ - [Redirect to another URL](#redirect-to-another-url)
+ - [Basic response with HTTP Code](#basic-response-with-http-code)
+ - [Basic response with HTTP Code and extra headers](#basic-response-with-http-code-and-extra-headers)
+ - [Basic response with string content](#basic-response-with-string-content)
+ - [Basic response with string content and extra headers](#basic-response-with-string-content-and-extra-headers)
+ - [Send large webpage from PROGMEM](#send-large-webpage-from-progmem)
+ - [Send large webpage from PROGMEM and extra headers](#send-large-webpage-from-progmem-and-extra-headers)
+ - [Send large webpage from PROGMEM containing templates](#send-large-webpage-from-progmem-containing-templates)
+ - [Send large webpage from PROGMEM containing templates and extra headers](#send-large-webpage-from-progmem-containing-templates-and-extra-headers)
+ - [Send binary content from PROGMEM](#send-binary-content-from-progmem)
+ - [Respond with content coming from a Stream](#respond-with-content-coming-from-a-stream)
+ - [Respond with content coming from a Stream and extra headers](#respond-with-content-coming-from-a-stream-and-extra-headers)
+ - [Respond with content coming from a Stream containing templates](#respond-with-content-coming-from-a-stream-containing-templates)
+ - [Respond with content coming from a Stream containing templates and extra headers](#respond-with-content-coming-from-a-stream-containing-templates-and-extra-headers)
+ - [Respond with content coming from a File](#respond-with-content-coming-from-a-file)
+ - [Respond with content coming from a File and extra headers](#respond-with-content-coming-from-a-file-and-extra-headers)
+ - [Respond with content coming from a File containing templates](#respond-with-content-coming-from-a-file-containing-templates)
+ - [Respond with content using a callback](#respond-with-content-using-a-callback)
+ - [Respond with content using a callback and extra headers](#respond-with-content-using-a-callback-and-extra-headers)
+ - [Respond with content using a callback containing templates](#respond-with-content-using-a-callback-containing-templates)
+ - [Respond with content using a callback containing templates and extra headers](#respond-with-content-using-a-callback-containing-templates-and-extra-headers)
+ - [Chunked Response](#chunked-response)
+ - [Print to response](#print-to-response)
+ - [ArduinoJson Basic Response](#arduinojson-basic-response)
+ - [ArduinoJson Advanced Response](#arduinojson-advanced-response)
+ - [Serving static files](#serving-static-files)
+ - [Serving specific file by name](#serving-specific-file-by-name)
+ - [Serving files in directory](#serving-files-in-directory)
+ - [Specifying Cache-Control header](#specifying-cache-control-header)
+ - [Specifying Date-Modified header](#specifying-date-modified-header)
+ - [Specifying Template Processor callback](#specifying-template-processor-callback)
+ - [Using filters](#using-filters)
+ - [Serve different site files in AP mode](#serve-different-site-files-in-ap-mode)
+ - [Rewrite to different index on AP](#rewrite-to-different-index-on-ap)
+ - [Serving different hosts](#serving-different-hosts)
+ - [Bad Responses](#bad-responses)
+ - [Respond with content using a callback without content length to HTTP/1.0 clients](#respond-with-content-using-a-callback-without-content-length-to-http10-clients)
+ - [Async WebSocket Plugin](#async-websocket-plugin)
+ - [Async WebSocket Event](#async-websocket-event)
+ - [Methods for sending data to a socket client](#methods-for-sending-data-to-a-socket-client)
+ - [Async Event Source Plugin](#async-event-source-plugin)
+ - [Setup Event Source on the server](#setup-event-source-on-the-server)
+ - [Setup Event Source in the browser](#setup-event-source-in-the-browser)
+ - [Scanning for available WiFi Networks](#scanning-for-available-wifi-networks)
+ - [Remove handlers and rewrites](#remove-handlers-and-rewrites)
+ - [Setting up the server](#setting-up-the-server)
+ - [Setup global and class functions as request handlers](#setup-global-and-class-functions-as-request-handlers)
+ - [Methods for controlling websocket connections](#methods-for-controlling-websocket-connections)
+ - [Adding default headers to all responses](#adding-default-headers)
+## Why should you care
+- Using asynchronous network means that you can handle more than one connection at the same time
+- You are called once the request is ready and parsed
+- When you send the response, you are immediately ready to handle other connections
+ while the server is taking care of sending the response in the background
+- Speed is OMG
+- Easy to use API, HTTP Basic and Digest MD5 Authentication (default), ChunkedResponse
+- Easily extendible to handle any type of content
+- Supports Continue 100
+- Async WebSocket plugin offering different locations without extra servers or ports
+- Async EventSource (Server-Sent Events) plugin to send events to the browser
+- URL Rewrite plugin for conditional and permanent url rewrites
+- ServeStatic plugin that supports cache, Last-Modified, default index and more
+- Simple template processing engine to handle templates
+
+## Important things to remember
+- This is fully asynchronous server and as such does not run on the loop thread.
+- You can not use yield or delay or any function that uses them inside the callbacks
+- The server is smart enough to know when to close the connection and free resources
+- You can not send more than one response to a single request
+
+## Principles of operation
+
+### The Async Web server
+- Listens for connections
+- Wraps the new clients into ```Request```
+- Keeps track of clients and cleans memory
+- Manages ```Rewrites``` and apply them on the request url
+- Manages ```Handlers``` and attaches them to Requests
+
+### Request Life Cycle
+- TCP connection is received by the server
+- The connection is wrapped inside ```Request``` object
+- When the request head is received (type, url, get params, http version and host),
+ the server goes through all ```Rewrites``` (in the order they were added) to rewrite the url and inject query parameters,
+ next, it goes through all attached ```Handlers```(in the order they were added) trying to find one
+ that ```canHandle``` the given request. If none are found, the default(catch-all) handler is attached.
+- The rest of the request is received, calling the ```handleUpload``` or ```handleBody``` methods of the ```Handler``` if they are needed (POST+File/Body)
+- When the whole request is parsed, the result is given to the ```handleRequest``` method of the ```Handler``` and is ready to be responded to
+- In the ```handleRequest``` method, to the ```Request``` is attached a ```Response``` object (see below) that will serve the response data back to the client
+- When the ```Response``` is sent, the client is closed and freed from the memory
+
+### Rewrites and how do they work
+- The ```Rewrites``` are used to rewrite the request url and/or inject get parameters for a specific request url path.
+- All ```Rewrites``` are evaluated on the request in the order they have been added to the server.
+- The ```Rewrite``` will change the request url only if the request url (excluding get parameters) is fully match
+ the rewrite url, and when the optional ```Filter``` callback return true.
+- Setting a ```Filter``` to the ```Rewrite``` enables to control when to apply the rewrite, decision can be based on
+ request url, http version, request host/port/target host, get parameters or the request client's localIP or remoteIP.
+- Two filter callbacks are provided: ```ON_AP_FILTER``` to execute the rewrite when request is made to the AP interface,
+ ```ON_STA_FILTER``` to execute the rewrite when request is made to the STA interface.
+- The ```Rewrite``` can specify a target url with optional get parameters, e.g. ```/to-url?with=params```
+
+### Handlers and how do they work
+- The ```Handlers``` are used for executing specific actions to particular requests
+- One ```Handler``` instance can be attached to any request and lives together with the server
+- Setting a ```Filter``` to the ```Handler``` enables to control when to apply the handler, decision can be based on
+ request url, http version, request host/port/target host, get parameters or the request client's localIP or remoteIP.
+- Two filter callbacks are provided: ```ON_AP_FILTER``` to execute the rewrite when request is made to the AP interface,
+ ```ON_STA_FILTER``` to execute the rewrite when request is made to the STA interface.
+- The ```canHandle``` method is used for handler specific control on whether the requests can be handled
+ and for declaring any interesting headers that the ```Request``` should parse. Decision can be based on request
+ method, request url, http version, request host/port/target host and get parameters
+- Once a ```Handler``` is attached to given ```Request``` (```canHandle``` returned true)
+ that ```Handler``` takes care to receive any file/data upload and attach a ```Response```
+ once the ```Request``` has been fully parsed
+- ```Handlers``` are evaluated in the order they are attached to the server. The ```canHandle``` is called only
+ if the ```Filter``` that was set to the ```Handler``` return true.
+- The first ```Handler``` that can handle the request is selected, not further ```Filter``` and ```canHandle``` are called.
+
+### Responses and how do they work
+- The ```Response``` objects are used to send the response data back to the client
+- The ```Response``` object lives with the ```Request``` and is freed on end or disconnect
+- Different techniques are used depending on the response type to send the data in packets
+ returning back almost immediately and sending the next packet when this one is received.
+ Any time in between is spent to run the user loop and handle other network packets
+- Responding asynchronously is probably the most difficult thing for most to understand
+- Many different options exist for the user to make responding a background task
+
+### Template processing
+- ESPAsyncWebserver contains simple template processing engine.
+- Template processing can be added to most response types.
+- Currently it supports only replacing template placeholders with actual values. No conditional processing, cycles, etc.
+- Placeholders are delimited with ```%``` symbols. Like this: ```%TEMPLATE_PLACEHOLDER%```.
+- It works by extracting placeholder name from response text and passing it to user provided function which should return actual value to be used instead of placeholder.
+- Since it's user provided function, it is possible for library users to implement conditional processing and cycles themselves.
+- Since it's impossible to know the actual response size after template processing step in advance (and, therefore, to include it in response headers), the response becomes [chunked](#chunked-response).
+
+## Libraries and projects that use AsyncWebServer
+- [WebSocketToSerial](https://github.com/hallard/WebSocketToSerial) - Debug serial devices through the web browser
+- [Sattrack](https://github.com/Hopperpop/Sattrack) - Track the ISS with ESP8266
+- [ESP Radio](https://github.com/Edzelf/Esp-radio) - Icecast radio based on ESP8266 and VS1053
+- [VZero](https://github.com/andig/vzero) - the Wireless zero-config controller for volkszaehler.org
+- [ESPurna](https://bitbucket.org/xoseperez/espurna) - ESPurna ("spark" in Catalan) is a custom C firmware for ESP8266 based smart switches. It was originally developed with the ITead Sonoff in mind.
+- [fauxmoESP](https://bitbucket.org/xoseperez/fauxmoesp) - Belkin WeMo emulator library for ESP8266.
+- [ESP-RFID](https://github.com/omersiar/esp-rfid) - MFRC522 RFID Access Control Management project for ESP8266.
+
+## Request Variables
+
+### Common Variables
+```cpp
+request->version(); // uint8_t: 0 = HTTP/1.0, 1 = HTTP/1.1
+request->method(); // enum: HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT, HTTP_PATCH, HTTP_HEAD, HTTP_OPTIONS
+request->url(); // String: URL of the request (not including host, port or GET parameters)
+request->host(); // String: The requested host (can be used for virtual hosting)
+request->contentType(); // String: ContentType of the request (not avaiable in Handler::canHandle)
+request->contentLength(); // size_t: ContentLength of the request (not avaiable in Handler::canHandle)
+request->multipart(); // bool: True if the request has content type "multipart"
+```
+
+### Headers
+```cpp
+//List all collected headers
+int headers = request->headers();
+int i;
+for(i=0;igetHeader(i);
+ Serial.printf("HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str());
+}
+
+//get specific header by name
+if(request->hasHeader("MyHeader")){
+ AsyncWebHeader* h = request->getHeader("MyHeader");
+ Serial.printf("MyHeader: %s\n", h->value().c_str());
+}
+
+//List all collected headers (Compatibility)
+int headers = request->headers();
+int i;
+for(i=0;iheaderName(i).c_str(), request->header(i).c_str());
+}
+
+//get specific header by name (Compatibility)
+if(request->hasHeader("MyHeader")){
+ Serial.printf("MyHeader: %s\n", request->header("MyHeader").c_str());
+}
+```
+
+### GET, POST and FILE parameters
+```cpp
+//List all parameters
+int params = request->params();
+for(int i=0;igetParam(i);
+ if(p->isFile()){ //p->isPost() is also true
+ Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size());
+ } else if(p->isPost()){
+ Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
+ } else {
+ Serial.printf("GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
+ }
+}
+
+//Check if GET parameter exists
+if(request->hasParam("download"))
+ AsyncWebParameter* p = request->getParam("download");
+
+//Check if POST (but not File) parameter exists
+if(request->hasParam("download", true))
+ AsyncWebParameter* p = request->getParam("download", true);
+
+//Check if FILE was uploaded
+if(request->hasParam("download", true, true))
+ AsyncWebParameter* p = request->getParam("download", true, true);
+
+//List all parameters (Compatibility)
+int args = request->args();
+for(int i=0;iargName(i).c_str(), request->arg(i).c_str());
+}
+
+//Check if parameter exists (Compatibility)
+if(request->hasArg("download"))
+ String arg = request->arg("download");
+```
+
+### FILE Upload handling
+```cpp
+void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
+ if(!index){
+ Serial.printf("UploadStart: %s\n", filename.c_str());
+ }
+ for(size_t i=0; iredirect("/login");
+
+//to external url
+request->redirect("http://esp8266.com");
+```
+
+### Basic response with HTTP Code
+```cpp
+request->send(404); //Sends 404 File Not Found
+```
+
+### Basic response with HTTP Code and extra headers
+```cpp
+AsyncWebServerResponse *response = request->beginResponse(404); //Sends 404 File Not Found
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Basic response with string content
+```cpp
+request->send(200, "text/plain", "Hello World!");
+```
+
+### Basic response with string content and extra headers
+```cpp
+AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", "Hello World!");
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Send large webpage from PROGMEM
+```cpp
+const char index_html[] PROGMEM = "..."; // large char array, tested with 14k
+request->send_P(200, "text/html", index_html);
+```
+
+### Send large webpage from PROGMEM and extra headers
+```cpp
+const char index_html[] PROGMEM = "..."; // large char array, tested with 14k
+AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", index_html);
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Send large webpage from PROGMEM containing templates
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+const char index_html[] PROGMEM = "..."; // large char array, tested with 14k
+request->send_P(200, "text/html", index_html, processor);
+```
+
+### Send large webpage from PROGMEM containing templates and extra headers
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+const char index_html[] PROGMEM = "..."; // large char array, tested with 14k
+AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", index_html, processor);
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Send binary content from PROGMEM
+```cpp
+
+//File: favicon.ico.gz, Size: 726
+#define favicon_ico_gz_len 726
+const uint8_t favicon_ico_gz[] PROGMEM = {
+ 0x1F, 0x8B, 0x08, 0x08, 0x0B, 0x87, 0x90, 0x57, 0x00, 0x03, 0x66, 0x61, 0x76, 0x69, 0x63, 0x6F,
+ 0x6E, 0x2E, 0x69, 0x63, 0x6F, 0x00, 0xCD, 0x53, 0x5F, 0x48, 0x9A, 0x51, 0x14, 0xBF, 0x62, 0x6D,
+ 0x86, 0x96, 0xA9, 0x64, 0xD3, 0xFE, 0xA8, 0x99, 0x65, 0x1A, 0xB4, 0x8A, 0xA8, 0x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x33, 0x12, 0x34, 0xCC, 0xA0, 0x19, 0x54, 0x92, 0x56, 0x0E, 0xD2, 0xD9, 0x43, 0xF8,
+ 0xCF, 0x82, 0x56, 0xC2, 0xDC, 0xEB, 0xEA, 0xEA, 0x38, 0x7E, 0x6C, 0x6C, 0x4C, 0xE0, 0xFE, 0x9D,
+ 0xB8, 0xBF, 0xA7, 0xFA, 0xAF, 0x56, 0x56, 0x56, 0xEE, 0x6D, 0x6E, 0x6E, 0xDE, 0xB8, 0x47, 0x55,
+ 0x55, 0x55, 0x6C, 0x66, 0x66, 0x46, 0x44, 0xDA, 0x3B, 0x34, 0x1A, 0x4D, 0x94, 0xB0, 0x3F, 0x09,
+ 0x7B, 0x45, 0xBD, 0xA5, 0x5D, 0x2E, 0x57, 0x8C, 0x7A, 0x73, 0xD9, 0xED, 0xF6, 0x3B, 0x84, 0xFF,
+ 0xE7, 0x7D, 0xA6, 0x3A, 0x2C, 0x95, 0x4A, 0xB1, 0x8E, 0x8E, 0x0E, 0x6D, 0x77, 0x77, 0xB7, 0xCD,
+ 0xE9, 0x74, 0x3E, 0x73, 0xBB, 0xDD, 0x8F, 0x3C, 0x1E, 0x8F, 0xE6, 0xF4, 0xF4, 0x94, 0xAD, 0xAD,
+ 0xAD, 0xDD, 0xDE, 0xCF, 0x73, 0x0B, 0x0B, 0xB8, 0xB6, 0xE0, 0x5D, 0xC6, 0x66, 0xC5, 0xE4, 0x10,
+ 0x4C, 0xF4, 0xF7, 0xD8, 0x59, 0xF2, 0x7F, 0xA3, 0xB8, 0xB4, 0xFC, 0x0F, 0xEE, 0x37, 0x70, 0xEC,
+ 0x16, 0x4A, 0x7E, 0x04, 0x00, 0x00
+};
+
+AsyncWebServerResponse *response = request->beginResponse_P(200, "image/x-icon", favicon_ico_gz, favicon_ico_gz_len);
+response->addHeader("Content-Encoding", "gzip");
+request->send(response);
+```
+
+### Respond with content coming from a Stream
+```cpp
+//read 12 bytes from Serial and send them as Content Type text/plain
+request->send(Serial, "text/plain", 12);
+```
+
+### Respond with content coming from a Stream and extra headers
+```cpp
+//read 12 bytes from Serial and send them as Content Type text/plain
+AsyncWebServerResponse *response = request->beginResponse(Serial, "text/plain", 12);
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Respond with content coming from a Stream containing templates
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+//read 12 bytes from Serial and send them as Content Type text/plain
+request->send(Serial, "text/plain", 12, processor);
+```
+
+### Respond with content coming from a Stream containing templates and extra headers
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+//read 12 bytes from Serial and send them as Content Type text/plain
+AsyncWebServerResponse *response = request->beginResponse(Serial, "text/plain", 12, processor);
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Respond with content coming from a File
+```cpp
+//Send index.htm with default content type
+request->send(SPIFFS, "/index.htm");
+
+//Send index.htm as text
+request->send(SPIFFS, "/index.htm", "text/plain");
+
+//Download index.htm
+request->send(SPIFFS, "/index.htm", String(), true);
+```
+
+### Respond with content coming from a File and extra headers
+```cpp
+//Send index.htm with default content type
+AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.htm");
+
+//Send index.htm as text
+AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.htm", "text/plain");
+
+//Download index.htm
+AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.htm", String(), true);
+
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Respond with content coming from a File containing templates
+Internally uses [Chunked Response](#chunked-response).
+
+Index.htm contents:
+```
+%HELLO_FROM_TEMPLATE%
+```
+
+Somewhere in source files:
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+//Send index.htm with template processor function
+request->send(SPIFFS, "/index.htm", String(), false, processor);
+```
+
+### Respond with content using a callback
+```cpp
+//send 128 bytes as plain text
+request->send("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ //Write up to "maxLen" bytes into "buffer" and return the amount written.
+ //index equals the amount of bytes that have been already sent
+ //You will not be asked for more bytes once the content length has been reached.
+ //Keep in mind that you can not delay or yield waiting for more data!
+ //Send what you currently have and you will be asked for more again
+ return mySource.read(buffer, maxLen);
+});
+```
+
+### Respond with content using a callback and extra headers
+```cpp
+//send 128 bytes as plain text
+AsyncWebServerResponse *response = request->beginResponse("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ //Write up to "maxLen" bytes into "buffer" and return the amount written.
+ //index equals the amount of bytes that have been already sent
+ //You will not be asked for more bytes once the content length has been reached.
+ //Keep in mind that you can not delay or yield waiting for more data!
+ //Send what you currently have and you will be asked for more again
+ return mySource.read(buffer, maxLen);
+});
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Respond with content using a callback containing templates
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+//send 128 bytes as plain text
+request->send("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ //Write up to "maxLen" bytes into "buffer" and return the amount written.
+ //index equals the amount of bytes that have been already sent
+ //You will not be asked for more bytes once the content length has been reached.
+ //Keep in mind that you can not delay or yield waiting for more data!
+ //Send what you currently have and you will be asked for more again
+ return mySource.read(buffer, maxLen);
+}, processor);
+```
+
+### Respond with content using a callback containing templates and extra headers
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+//send 128 bytes as plain text
+AsyncWebServerResponse *response = request->beginResponse("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ //Write up to "maxLen" bytes into "buffer" and return the amount written.
+ //index equals the amount of bytes that have been already sent
+ //You will not be asked for more bytes once the content length has been reached.
+ //Keep in mind that you can not delay or yield waiting for more data!
+ //Send what you currently have and you will be asked for more again
+ return mySource.read(buffer, maxLen);
+}, processor);
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Chunked Response
+Used when content length is unknown. Works best if the client supports HTTP/1.1
+```cpp
+AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ //Write up to "maxLen" bytes into "buffer" and return the amount written.
+ //index equals the amount of bytes that have been already sent
+ //You will be asked for more data until 0 is returned
+ //Keep in mind that you can not delay or yield waiting for more data!
+ return mySource.read(buffer, maxLen);
+});
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Chunked Response containing templates
+Used when content length is unknown. Works best if the client supports HTTP/1.1
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ //Write up to "maxLen" bytes into "buffer" and return the amount written.
+ //index equals the amount of bytes that have been already sent
+ //You will be asked for more data until 0 is returned
+ //Keep in mind that you can not delay or yield waiting for more data!
+ return mySource.read(buffer, maxLen);
+}, processor);
+response->addHeader("Server","ESP Async Web Server");
+request->send(response);
+```
+
+### Print to response
+```cpp
+AsyncResponseStream *response = request->beginResponseStream("text/html");
+response->addHeader("Server","ESP Async Web Server");
+response->printf("Webpage at %s ", request->url().c_str());
+
+response->print("Hello ");
+response->print(request->client()->remoteIP());
+response->print(" ");
+
+response->print("General ");
+response->print("");
+response->printf("Version: HTTP/1.%u ", request->version());
+response->printf("Method: %s ", request->methodToString());
+response->printf("URL: %s ", request->url().c_str());
+response->printf("Host: %s ", request->host().c_str());
+response->printf("ContentType: %s ", request->contentType().c_str());
+response->printf("ContentLength: %u ", request->contentLength());
+response->printf("Multipart: %s ", request->multipart()?"true":"false");
+response->print(" ");
+
+response->print("Headers ");
+response->print("");
+int headers = request->headers();
+for(int i=0;igetHeader(i);
+ response->printf("%s: %s ", h->name().c_str(), h->value().c_str());
+}
+response->print(" ");
+
+response->print("Parameters ");
+response->print("");
+int params = request->params();
+for(int i=0;igetParam(i);
+ if(p->isFile()){
+ response->printf("FILE[%s]: %s, size: %u ", p->name().c_str(), p->value().c_str(), p->size());
+ } else if(p->isPost()){
+ response->printf("POST[%s]: %s ", p->name().c_str(), p->value().c_str());
+ } else {
+ response->printf("GET[%s]: %s ", p->name().c_str(), p->value().c_str());
+ }
+}
+response->print(" ");
+
+response->print("");
+//send the response last
+request->send(response);
+```
+
+### ArduinoJson Basic Response
+This way of sending Json is great for when the result is below 4KB
+```cpp
+#include "AsyncJson.h"
+#include "ArduinoJson.h"
+
+
+AsyncResponseStream *response = request->beginResponseStream("text/json");
+DynamicJsonBuffer jsonBuffer;
+JsonObject &root = jsonBuffer.createObject();
+root["heap"] = ESP.getFreeHeap();
+root["ssid"] = WiFi.SSID();
+root.printTo(*response);
+request->send(response);
+```
+
+### ArduinoJson Advanced Response
+This response can handle really large Json objects (tested to 40KB)
+There isn't any noticeable speed decrease for small results with the method above
+Since ArduinoJson does not allow reading parts of the string, the whole Json has to
+be passed every time a chunks needs to be sent, which shows speed decrease proportional
+to the resulting json packets
+```cpp
+#include "AsyncJson.h"
+#include "ArduinoJson.h"
+
+
+AsyncJsonResponse * response = new AsyncJsonResponse();
+response->addHeader("Server","ESP Async Web Server");
+JsonObject& root = response->getRoot();
+root["heap"] = ESP.getFreeHeap();
+root["ssid"] = WiFi.SSID();
+response->setLength();
+request->send(response);
+```
+
+## Serving static files
+In addition to serving files from SPIFFS as described above, the server provide a dedicated handler that optimize the
+performance of serving files from SPIFFS - ```AsyncStaticWebHandler```. Use ```server.serveStatic()``` function to
+initialize and add a new instance of ```AsyncStaticWebHandler``` to the server.
+The Handler will not handle the request if the file does not exists, e.g. the server will continue to look for another
+handler that can handle the request.
+Notice that you can chain setter functions to setup the handler, or keep a pointer to change it at a later time.
+
+### Serving specific file by name
+```cpp
+// Serve the file "/www/page.htm" when request url is "/page.htm"
+server.serveStatic("/page.htm", SPIFFS, "/www/page.htm");
+```
+
+### Serving files in directory
+To serve files in a directory, the path to the files should specify a directory in SPIFFS and ends with "/".
+```cpp
+// Serve files in directory "/www/" when request url starts with "/"
+// Request to the root or none existing files will try to server the defualt
+// file name "index.htm" if exists
+server.serveStatic("/", SPIFFS, "/www/");
+
+// Server with different default file
+server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("default.html");
+```
+
+### Serving static files with authentication
+
+```cpp
+server
+ .serveStatic("/", SPIFFS, "/www/")
+ .setDefaultFile("default.html")
+ .setAuthentication("user", "pass");
+```
+
+### Specifying Cache-Control header
+It is possible to specify Cache-Control header value to reduce the number of calls to the server once the client loaded
+the files. For more information on Cache-Control values see [Cache-Control](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9)
+```cpp
+// Cache responses for 10 minutes (600 seconds)
+server.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=600");
+
+//*** Change Cache-Control after server setup ***
+
+// During setup - keep a pointer to the handler
+AsyncStaticWebHandler* handler = &server.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=600");
+
+// At a later event - change Cache-Control
+handler->setCacheControl("max-age=30");
+```
+
+### Specifying Date-Modified header
+It is possible to specify Date-Modified header to enable the server to return Not-Modified (304) response for requests
+with "If-Modified-Since" header with the same value, instead of responding with the actual file content.
+```cpp
+// Update the date modified string every time files are updated
+server.serveStatic("/", SPIFFS, "/www/").setLastModified("Mon, 20 Jun 2016 14:00:00 GMT");
+
+//*** Chage last modified value at a later stage ***
+
+// During setup - read last modified value from config or EEPROM
+String date_modified = loadDateModified();
+AsyncStaticWebHandler* handler = &server.serveStatic("/", SPIFFS, "/www/");
+handler->setLastModified(date_modified);
+
+// At a later event when files are updated
+String date_modified = getNewDateModfied();
+saveDateModified(date_modified); // Save for next reset
+handler->setLastModified(date_modified);
+```
+
+### Specifying Template Processor callback
+It is possible to specify template processor for static files. For information on template processor see
+[Respond with content coming from a File containing templates](#respond-with-content-coming-from-a-file-containing-templates).
+```cpp
+String processor(const String& var)
+{
+ if(var == "HELLO_FROM_TEMPLATE")
+ return F("Hello world!");
+ return String();
+}
+
+// ...
+
+server.serveStatic("/", SPIFFS, "/www/").setTemplateProcessor(processor);
+```
+
+
+## Using filters
+Filters can be set to `Rewrite` or `Handler` in order to control when to apply the rewrite and consider the handler.
+A filter is a callback function that evaluates the request and return a boolean `true` to include the item
+or `false` to exclude it.
+Two filter callback are provided for convince:
+* `ON_STA_FILTER` - return true when requests are made to the STA (station mode) interface.
+* `ON_AP_FILTER` - return true when requests are made to the AP (access point) interface.
+
+### Serve different site files in AP mode
+```cpp
+server.serveStatic("/", SPIFFS, "/www/").setFilter(ON_STA_FILTER);
+server.serveStatic("/", SPIFFS, "/ap/").setFilter(ON_AP_FILTER);
+```
+
+### Rewrite to different index on AP
+```cpp
+// Serve the file "/www/index-ap.htm" in AP, and the file "/www/index.htm" on STA
+server.rewrite("/", "index.htm");
+server.rewrite("/index.htm", "index-ap.htm").setFilter(ON_AP_FILTER);
+server.serveStatic("/", SPIFFS, "/www/");
+```
+
+### Serving different hosts
+```cpp
+// Filter callback using request host
+bool filterOnHost1(AsyncWebServerRequest *request) { return request->host() == "host1"; }
+
+// Server setup: server files in "/host1/" to requests for "host1", and files in "/www/" otherwise.
+server.serveStatic("/", SPIFFS, "/host1/").setFilter(filterOnHost1);
+server.serveStatic("/", SPIFFS, "/www/");
+```
+
+## Bad Responses
+Some responses are implemented, but you should not use them, because they do not conform to HTTP.
+The following example will lead to unclean close of the connection and more time wasted
+than providing the length of the content
+
+### Respond with content using a callback without content length to HTTP/1.0 clients
+```cpp
+//This is used as fallback for chunked responses to HTTP/1.0 Clients
+request->send("text/plain", 0, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ //Write up to "maxLen" bytes into "buffer" and return the amount written.
+ //You will be asked for more data until 0 is returned
+ //Keep in mind that you can not delay or yield waiting for more data!
+ return mySource.read(buffer, maxLen);
+});
+```
+
+## Async WebSocket Plugin
+The server includes a web socket plugin which lets you define different WebSocket locations to connect to
+without starting another listening service or using different port
+
+### Async WebSocket Event
+```cpp
+
+void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
+ if(type == WS_EVT_CONNECT){
+ //client connected
+ os_printf("ws[%s][%u] connect\n", server->url(), client->id());
+ client->printf("Hello Client %u :)", client->id());
+ client->ping();
+ } else if(type == WS_EVT_DISCONNECT){
+ //client disconnected
+ os_printf("ws[%s][%u] disconnect: %u\n", server->url(), client->id());
+ } else if(type == WS_EVT_ERROR){
+ //error was received from the other end
+ os_printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data);
+ } else if(type == WS_EVT_PONG){
+ //pong message was received (in response to a ping request maybe)
+ os_printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char*)data:"");
+ } else if(type == WS_EVT_DATA){
+ //data packet
+ AwsFrameInfo * info = (AwsFrameInfo*)arg;
+ if(info->final && info->index == 0 && info->len == len){
+ //the whole message is in a single frame and we got all of it's data
+ os_printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len);
+ if(info->opcode == WS_TEXT){
+ data[len] = 0;
+ os_printf("%s\n", (char*)data);
+ } else {
+ for(size_t i=0; i < info->len; i++){
+ os_printf("%02x ", data[i]);
+ }
+ os_printf("\n");
+ }
+ if(info->opcode == WS_TEXT)
+ client->text("I got your text message");
+ else
+ client->binary("I got your binary message");
+ } else {
+ //message is comprised of multiple frames or the frame is split into multiple packets
+ if(info->index == 0){
+ if(info->num == 0)
+ os_printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary");
+ os_printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len);
+ }
+
+ os_printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT)?"text":"binary", info->index, info->index + len);
+ if(info->message_opcode == WS_TEXT){
+ data[len] = 0;
+ os_printf("%s\n", (char*)data);
+ } else {
+ for(size_t i=0; i < len; i++){
+ os_printf("%02x ", data[i]);
+ }
+ os_printf("\n");
+ }
+
+ if((info->index + len) == info->len){
+ os_printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len);
+ if(info->final){
+ os_printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary");
+ if(info->message_opcode == WS_TEXT)
+ client->text("I got your text message");
+ else
+ client->binary("I got your binary message");
+ }
+ }
+ }
+ }
+}
+```
+
+### Methods for sending data to a socket client
+```cpp
+
+
+
+//Server methods
+AsyncWebSocket ws("/ws");
+//printf to a client
+ws.printf((uint32_t)client_id, arguments...);
+//printf to all clients
+ws.printfAll(arguments...);
+//printf_P to a client
+ws.printf_P((uint32_t)client_id, PSTR(format), arguments...);
+//printfAll_P to all clients
+ws.printf_P(PSTR(format), arguments...);
+//send text to a client
+ws.text((uint32_t)client_id, (char*)text);
+ws.text((uint32_t)client_id, (uint8_t*)text, (size_t)len);
+//send text from PROGMEM to a client
+ws.text((uint32_t)client_id, PSTR("text"));
+const char flash_text[] PROGMEM = "Text to send"
+ws.text((uint32_t)client_id, FPSTR(flash_text));
+//send text to all clients
+ws.textAll((char*)text);
+ws.textAll((uint8_t*)text, (size_t)len);
+//send binary to a client
+ws.binary((uint32_t)client_id, (char*)binary);
+ws.binary((uint32_t)client_id, (uint8_t*)binary, (size_t)len);
+//send binary from PROGMEM to a client
+const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 };
+ws.binary((uint32_t)client_id, flash_binary, 4);
+//send binary to all clients
+ws.binaryAll((char*)binary);
+ws.binaryAll((uint8_t*)binary, (size_t)len);
+//HTTP Authenticate before switch to Websocket protocol
+ws.setAuthentication("user", "pass");
+
+//client methods
+AsyncWebSocketClient * client;
+//printf
+client->printf(arguments...);
+//printf_P
+client->printf_P(PSTR(format), arguments...);
+//send text
+client->text((char*)text);
+client->text((uint8_t*)text, (size_t)len);
+//send text from PROGMEM
+client->text(PSTR("text"));
+const char flash_text[] PROGMEM = "Text to send";
+client->text(FPSTR(flash_text));
+//send binary
+client->binary((char*)binary);
+client->binary((uint8_t*)binary, (size_t)len);
+//send binary from PROGMEM
+const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 };
+client->binary(flash_binary, 4);
+```
+
+### Direct access to web socket message buffer
+When sending a web socket message using the above methods a buffer is created. Under certain circumstances you might want to manipulate or populate this buffer directly from your application, for example to prevent unnecessary duplications of the data. This example below shows how to create a buffer and print data to it from an ArduinoJson object then send it.
+
+```cpp
+void sendDataWs(AsyncWebSocketClient * client)
+{
+ DynamicJsonBuffer jsonBuffer;
+ JsonObject& root = jsonBuffer.createObject();
+ root["a"] = "abc";
+ root["b"] = "abcd";
+ root["c"] = "abcde";
+ root["d"] = "abcdef";
+ root["e"] = "abcdefg";
+ size_t len = root.measureLength();
+ AsyncWebSocketMessageBuffer * buffer = ws.makeBuffer(len); // creates a buffer (len + 1) for you.
+ if (buffer) {
+ root.printTo((char *)buffer->get(), len + 1);
+ if (client) {
+ client->text(buffer);
+ } else {
+ ws.textAll(buffer);
+ }
+ }
+}
+```
+
+## Async Event Source Plugin
+The server includes EventSource (Server-Sent Events) plugin which can be used to send short text events to the browser.
+Difference between EventSource and WebSockets is that EventSource is single direction, text-only protocol.
+
+### Setup Event Source on the server
+```cpp
+AsyncWebServer server(80);
+AsyncEventSource events("/events");
+
+void setup(){
+ // setup ......
+ events.onConnect([](AsyncEventSourceClient *client){
+ if(client->lastId()){
+ Serial.printf("Client reconnected! Last message ID that it gat is: %u\n", client->lastId());
+ }
+ //send event with message "hello!", id current millis
+ // and set reconnect delay to 1 second
+ client->send("hello!",NULL,millis(),1000);
+ });
+ //HTTP Basic authentication
+ events.setAuthentication("user", "pass");
+ server.addHandler(&events);
+ // setup ......
+}
+
+void loop(){
+ if(eventTriggered){ // your logic here
+ //send event "myevent"
+ events.send("my event content","myevent",millis());
+ }
+}
+```
+
+### Setup Event Source in the browser
+```javascript
+if (!!window.EventSource) {
+ var source = new EventSource('/events');
+
+ source.addEventListener('open', function(e) {
+ console.log("Events Connected");
+ }, false);
+
+ source.addEventListener('error', function(e) {
+ if (e.target.readyState != EventSource.OPEN) {
+ console.log("Events Disconnected");
+ }
+ }, false);
+
+ source.addEventListener('message', function(e) {
+ console.log("message", e.data);
+ }, false);
+
+ source.addEventListener('myevent', function(e) {
+ console.log("myevent", e.data);
+ }, false);
+}
+```
+
+## Scanning for available WiFi Networks
+```cpp
+//First request will return 0 results unless you start scan from somewhere else (loop/setup)
+//Do not request more often than 3-5 seconds
+server.on("/scan", HTTP_GET, [](AsyncWebServerRequest *request){
+ String json = "[";
+ int n = WiFi.scanComplete();
+ if(n == -2){
+ WiFi.scanNetworks(true);
+ } else if(n){
+ for (int i = 0; i < n; ++i){
+ if(i) json += ",";
+ json += "{";
+ json += "\"rssi\":"+String(WiFi.RSSI(i));
+ json += ",\"ssid\":\""+WiFi.SSID(i)+"\"";
+ json += ",\"bssid\":\""+WiFi.BSSIDstr(i)+"\"";
+ json += ",\"channel\":"+String(WiFi.channel(i));
+ json += ",\"secure\":"+String(WiFi.encryptionType(i));
+ json += ",\"hidden\":"+String(WiFi.isHidden(i)?"true":"false");
+ json += "}";
+ }
+ WiFi.scanDelete();
+ if(WiFi.scanComplete() == -2){
+ WiFi.scanNetworks(true);
+ }
+ }
+ json += "]";
+ request->send(200, "text/json", json);
+ json = String();
+});
+```
+
+## Remove handlers and rewrites
+
+Server goes through handlers in same order as they were added. You can't simple add handler with same path to override them.
+To remove handler:
+```arduino
+// save callback for particular URL path
+auto handler = server.on("/some/path", [](AsyncWebServerRequest *request){
+ //do something useful
+});
+// when you don't need handler anymore remove it
+server.removeHandler(&handler);
+
+// same with rewrites
+server.removeRewrite(&someRewrite);
+
+server.onNotFound([](AsyncWebServerRequest *request){
+ request->send(404);
+});
+
+// remove server.onNotFound handler
+server.onNotFound(NULL);
+
+// remove all rewrites, handlers and onNotFound/onFileUpload/onRequestBody callbacks
+server.reset();
+```
+
+## Setting up the server
+```cpp
+#include "ESPAsyncTCP.h"
+#include "ESPAsyncWebServer.h"
+
+AsyncWebServer server(80);
+AsyncWebSocket ws("/ws"); // access at ws://[esp ip]/ws
+AsyncEventSource events("/events"); // event source (Server-Sent events)
+
+const char* ssid = "your-ssid";
+const char* password = "your-pass";
+const char* http_username = "admin";
+const char* http_password = "admin";
+
+//flag to use from web update to reboot the ESP
+bool shouldReboot = false;
+
+void onRequest(AsyncWebServerRequest *request){
+ //Handle Unknown Request
+ request->send(404);
+}
+
+void onBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){
+ //Handle body
+}
+
+void onUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
+ //Handle upload
+}
+
+void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
+ //Handle WebSocket event
+}
+
+void setup(){
+ Serial.begin(115200);
+ WiFi.mode(WIFI_STA);
+ WiFi.begin(ssid, password);
+ if (WiFi.waitForConnectResult() != WL_CONNECTED) {
+ Serial.printf("WiFi Failed!\n");
+ return;
+ }
+
+ // attach AsyncWebSocket
+ ws.onEvent(onEvent);
+ server.addHandler(&ws);
+
+ // attach AsyncEventSource
+ server.addHandler(&events);
+
+ // respond to GET requests on URL /heap
+ server.on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){
+ request->send(200, "text/plain", String(ESP.getFreeHeap()));
+ });
+
+ // upload a file to /upload
+ server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request){
+ request->send(200);
+ }, onUpload);
+
+ // send a file when /index is requested
+ server.on("/index", HTTP_ANY, [](AsyncWebServerRequest *request){
+ request->send(SPIFFS, "/index.htm");
+ });
+
+ // HTTP basic authentication
+ server.on("/login", HTTP_GET, [](AsyncWebServerRequest *request){
+ if(!request->authenticate(http_username, http_password))
+ return request->requestAuthentication();
+ request->send(200, "text/plain", "Login Success!");
+ });
+
+ // Simple Firmware Update Form
+ server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){
+ request->send(200, "text/html", "");
+ });
+ server.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){
+ shouldReboot = !Update.hasError();
+ AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", shouldReboot?"OK":"FAIL");
+ response->addHeader("Connection", "close");
+ request->send(response);
+ },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
+ if(!index){
+ Serial.printf("Update Start: %s\n", filename.c_str());
+ Update.runAsync(true);
+ if(!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)){
+ Update.printError(Serial);
+ }
+ }
+ if(!Update.hasError()){
+ if(Update.write(data, len) != len){
+ Update.printError(Serial);
+ }
+ }
+ if(final){
+ if(Update.end(true)){
+ Serial.printf("Update Success: %uB\n", index+len);
+ } else {
+ Update.printError(Serial);
+ }
+ }
+ });
+
+ // attach filesystem root at URL /fs
+ server.serveStatic("/fs", SPIFFS, "/");
+
+ // Catch-All Handlers
+ // Any request that can not find a Handler that canHandle it
+ // ends in the callbacks below.
+ server.onNotFound(onRequest);
+ server.onFileUpload(onUpload);
+ server.onRequestBody(onBody);
+
+ server.begin();
+}
+
+void loop(){
+ if(shouldReboot){
+ Serial.println("Rebooting...");
+ delay(100);
+ ESP.restart();
+ }
+ static char temp[128];
+ sprintf(temp, "Seconds since boot: %u", millis()/1000);
+ events.send(temp, "time"); //send event "time"
+}
+```
+
+### Setup global and class functions as request handlers
+
+```arduino
+#include
+#include
+#include
+#include
+
+void handleRequest(AsyncWebServerRequest *request)
+{
+}
+
+class WebClass
+{
+public :
+ WebClass(){
+ };
+
+ AsyncWebServer classWebServer = AsyncWebServer(80);
+
+ void classRequest (AsyncWebServerRequest *request)
+ {
+ }
+
+ void begin(){
+
+ // attach global request handler
+ classWebServer.on("/example", HTTP_ANY, handleRequest);
+
+ // attach class request handler
+ classWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, this, std::placeholders::_1));
+ }
+};
+
+AsyncWebServer globalWebServer(80);
+WebClass webClassInstance;
+
+void setup() {
+
+ // attach global request handler
+ globalWebServer.on("/example", HTTP_ANY, handleRequest);
+
+ // attach class request handler
+ globalWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, webClassInstance, std::placeholders::_1));
+}
+
+void loop() {
+
+}
+```
+
+### Methods for controlling websocket connections
+
+```arduino
+ // Disable client connections if it was activated
+ if ( ws.enabled() )
+ ws.enable(false);
+
+ // enable client connections if it was disabled
+ if ( !ws.enabled() )
+ ws.enable(true);
+```
+
+Example of OTA code
+
+```arduino
+ // OTA callbacks
+ ArduinoOTA.onStart([]() {
+ // Clean SPIFFS
+ SPIFFS.end();
+
+ // Disable client connections
+ ws.enable(false);
+
+ // Advertise connected clients what's going on
+ ws.textAll("OTA Update Started");
+
+ // Close them
+ ws.closeAll();
+
+ });
+
+```
+
+### Adding Default Headers
+
+In some cases, such as when working with CORS, or with some sort of custom authentication system,
+you might need to define a header that should get added to all responses (including static, websocket and EventSource).
+The DefaultHeaders singleton allows you to do this.
+
+Example:
+
+```arduino
+DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
+webServer.begin();
+```
+
+*NOTE*: You will still need to respond to the OPTIONS method for CORS pre-flight in most cases. (unless you are only using GET)
+
+This is one option:
+
+```arduino
+webServer.onNotFound([](AsyncWebServerRequest *request) {
+ if (request->method() == HTTP_OPTIONS) {
+ request->send(200);
+ } else {
+ request->send(404);
+ }
+});
+```
diff --git a/libraries/ESPAsyncWebServer/component.mk b/libraries/ESPAsyncWebServer/component.mk
new file mode 100644
index 00000000..bb5bb161
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/component.mk
@@ -0,0 +1,3 @@
+COMPONENT_ADD_INCLUDEDIRS := src
+COMPONENT_SRCDIRS := src
+CXXFLAGS += -fno-rtti
diff --git a/libraries/ESPAsyncWebServer/espressif32_library.json b/libraries/ESPAsyncWebServer/espressif32_library.json
new file mode 100644
index 00000000..baea1397
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/espressif32_library.json
@@ -0,0 +1,23 @@
+{
+ "name":"AsyncWebServer",
+ "description":"Asynchronous HTTP and WebSocket Server Library for ESP32",
+ "keywords":"http,async,websocket,webserver",
+ "authors":
+ {
+ "name": "Hristo Gochkov",
+ "maintainer": true
+ },
+ "repository":
+ {
+ "type": "git",
+ "url": "https://github.com/me-no-dev/ESPAsyncWebServer.git"
+ },
+ "version": "1.1.0",
+ "license": "LGPL-3.0",
+ "frameworks": "arduino",
+ "platforms": ["espressif32", "espressif32_stage"],
+ "dependencies":
+ {
+ "name": "AsyncTCP"
+ }
+}
diff --git a/libraries/ESPAsyncWebServer/espressif8266_library.json b/libraries/ESPAsyncWebServer/espressif8266_library.json
new file mode 100644
index 00000000..fee6410e
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/espressif8266_library.json
@@ -0,0 +1,23 @@
+{
+ "name":"ESPAsyncWebServer",
+ "description":"Asynchronous HTTP and WebSocket Server Library for ESP8266",
+ "keywords":"http,async,websocket,webserver",
+ "authors":
+ {
+ "name": "Hristo Gochkov",
+ "maintainer": true
+ },
+ "repository":
+ {
+ "type": "git",
+ "url": "https://github.com/me-no-dev/ESPAsyncWebServer.git"
+ },
+ "version": "1.1.0",
+ "license": "LGPL-3.0",
+ "frameworks": "arduino",
+ "platforms": ["espressif8266", "espressif8266_stage"],
+ "dependencies":
+ {
+ "name": "ESPAsyncTCP"
+ }
+}
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/.esp31b.skip b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/.esp31b.skip
new file mode 100644
index 00000000..e69de29b
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino
new file mode 100644
index 00000000..651c5577
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino
@@ -0,0 +1,211 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+// SKETCH BEGIN
+AsyncWebServer server(80);
+AsyncWebSocket ws("/ws");
+AsyncEventSource events("/events");
+
+void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
+ if(type == WS_EVT_CONNECT){
+ Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
+ client->printf("Hello Client %u :)", client->id());
+ client->ping();
+ } else if(type == WS_EVT_DISCONNECT){
+ Serial.printf("ws[%s][%u] disconnect: %u\n", server->url(), client->id());
+ } else if(type == WS_EVT_ERROR){
+ Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data);
+ } else if(type == WS_EVT_PONG){
+ Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char*)data:"");
+ } else if(type == WS_EVT_DATA){
+ AwsFrameInfo * info = (AwsFrameInfo*)arg;
+ String msg = "";
+ if(info->final && info->index == 0 && info->len == len){
+ //the whole message is in a single frame and we got all of it's data
+ Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len);
+
+ if(info->opcode == WS_TEXT){
+ for(size_t i=0; i < info->len; i++) {
+ msg += (char) data[i];
+ }
+ } else {
+ char buff[3];
+ for(size_t i=0; i < info->len; i++) {
+ sprintf(buff, "%02x ", (uint8_t) data[i]);
+ msg += buff ;
+ }
+ }
+ Serial.printf("%s\n",msg.c_str());
+
+ if(info->opcode == WS_TEXT)
+ client->text("I got your text message");
+ else
+ client->binary("I got your binary message");
+ } else {
+ //message is comprised of multiple frames or the frame is split into multiple packets
+ if(info->index == 0){
+ if(info->num == 0)
+ Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary");
+ Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len);
+ }
+
+ Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT)?"text":"binary", info->index, info->index + len);
+
+ if(info->opcode == WS_TEXT){
+ for(size_t i=0; i < info->len; i++) {
+ msg += (char) data[i];
+ }
+ } else {
+ char buff[3];
+ for(size_t i=0; i < info->len; i++) {
+ sprintf(buff, "%02x ", (uint8_t) data[i]);
+ msg += buff ;
+ }
+ }
+ Serial.printf("%s\n",msg.c_str());
+
+ if((info->index + len) == info->len){
+ Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len);
+ if(info->final){
+ Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary");
+ if(info->message_opcode == WS_TEXT)
+ client->text("I got your text message");
+ else
+ client->binary("I got your binary message");
+ }
+ }
+ }
+ }
+}
+
+
+const char* ssid = "*******";
+const char* password = "*******";
+const char * hostName = "esp-async";
+const char* http_username = "admin";
+const char* http_password = "admin";
+
+void setup(){
+ Serial.begin(115200);
+ Serial.setDebugOutput(true);
+ WiFi.hostname(hostName);
+ WiFi.mode(WIFI_AP_STA);
+ WiFi.softAP(hostName);
+ WiFi.begin(ssid, password);
+ if (WiFi.waitForConnectResult() != WL_CONNECTED) {
+ Serial.printf("STA: Failed!\n");
+ WiFi.disconnect(false);
+ delay(1000);
+ WiFi.begin(ssid, password);
+ }
+
+ //Send OTA events to the browser
+ ArduinoOTA.onStart([]() { events.send("Update Start", "ota"); });
+ ArduinoOTA.onEnd([]() { events.send("Update End", "ota"); });
+ ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
+ char p[32];
+ sprintf(p, "Progress: %u%%\n", (progress/(total/100)));
+ events.send(p, "ota");
+ });
+ ArduinoOTA.onError([](ota_error_t error) {
+ if(error == OTA_AUTH_ERROR) events.send("Auth Failed", "ota");
+ else if(error == OTA_BEGIN_ERROR) events.send("Begin Failed", "ota");
+ else if(error == OTA_CONNECT_ERROR) events.send("Connect Failed", "ota");
+ else if(error == OTA_RECEIVE_ERROR) events.send("Recieve Failed", "ota");
+ else if(error == OTA_END_ERROR) events.send("End Failed", "ota");
+ });
+ ArduinoOTA.setHostname(hostName);
+ ArduinoOTA.begin();
+
+ MDNS.addService("http","tcp",80);
+
+ SPIFFS.begin();
+
+ ws.onEvent(onWsEvent);
+ server.addHandler(&ws);
+
+ events.onConnect([](AsyncEventSourceClient *client){
+ client->send("hello!",NULL,millis(),1000);
+ });
+ server.addHandler(&events);
+
+ server.addHandler(new SPIFFSEditor(http_username,http_password));
+
+ server.on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){
+ request->send(200, "text/plain", String(ESP.getFreeHeap()));
+ });
+
+ server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
+
+ server.onNotFound([](AsyncWebServerRequest *request){
+ Serial.printf("NOT_FOUND: ");
+ if(request->method() == HTTP_GET)
+ Serial.printf("GET");
+ else if(request->method() == HTTP_POST)
+ Serial.printf("POST");
+ else if(request->method() == HTTP_DELETE)
+ Serial.printf("DELETE");
+ else if(request->method() == HTTP_PUT)
+ Serial.printf("PUT");
+ else if(request->method() == HTTP_PATCH)
+ Serial.printf("PATCH");
+ else if(request->method() == HTTP_HEAD)
+ Serial.printf("HEAD");
+ else if(request->method() == HTTP_OPTIONS)
+ Serial.printf("OPTIONS");
+ else
+ Serial.printf("UNKNOWN");
+ Serial.printf(" http://%s%s\n", request->host().c_str(), request->url().c_str());
+
+ if(request->contentLength()){
+ Serial.printf("_CONTENT_TYPE: %s\n", request->contentType().c_str());
+ Serial.printf("_CONTENT_LENGTH: %u\n", request->contentLength());
+ }
+
+ int headers = request->headers();
+ int i;
+ for(i=0;igetHeader(i);
+ Serial.printf("_HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str());
+ }
+
+ int params = request->params();
+ for(i=0;igetParam(i);
+ if(p->isFile()){
+ Serial.printf("_FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size());
+ } else if(p->isPost()){
+ Serial.printf("_POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
+ } else {
+ Serial.printf("_GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
+ }
+ }
+
+ request->send(404);
+ });
+ server.onFileUpload([](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final){
+ if(!index)
+ Serial.printf("UploadStart: %s\n", filename.c_str());
+ Serial.printf("%s", (const char*)data);
+ if(final)
+ Serial.printf("UploadEnd: %s (%u)\n", filename.c_str(), index+len);
+ });
+ server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){
+ if(!index)
+ Serial.printf("BodyStart: %u\n", total);
+ Serial.printf("%s", (const char*)data);
+ if(index + len == total)
+ Serial.printf("BodyEnd: %u\n", total);
+ });
+ server.begin();
+}
+
+void loop(){
+ ArduinoOTA.handle();
+}
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/.exclude.files b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/.exclude.files
new file mode 100644
index 00000000..955397fa
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/.exclude.files
@@ -0,0 +1,2 @@
+/*.js.gz
+/.exclude.files
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/ace.js.gz b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/ace.js.gz
new file mode 100644
index 00000000..7b175c1c
Binary files /dev/null and b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/ace.js.gz differ
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/ext-searchbox.js.gz b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/ext-searchbox.js.gz
new file mode 100644
index 00000000..cf5b49f6
Binary files /dev/null and b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/ext-searchbox.js.gz differ
diff --git a/libraries/WebServer/examples/FSBrowser/data/favicon.ico b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/favicon.ico
similarity index 100%
rename from libraries/WebServer/examples/FSBrowser/data/favicon.ico
rename to libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/favicon.ico
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/index.htm b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/index.htm
new file mode 100644
index 00000000..28f47e99
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/index.htm
@@ -0,0 +1,131 @@
+
+
+
+
+
+ WebSocketTester
+
+
+
+
+
+
+ $
+
+
+
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-css.js.gz b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-css.js.gz
new file mode 100644
index 00000000..ebd6fe94
Binary files /dev/null and b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-css.js.gz differ
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-html.js.gz b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-html.js.gz
new file mode 100644
index 00000000..26b53532
Binary files /dev/null and b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-html.js.gz differ
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-javascript.js.gz b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-javascript.js.gz
new file mode 100644
index 00000000..c0451c1c
Binary files /dev/null and b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/mode-javascript.js.gz differ
diff --git a/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/worker-html.js.gz b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/worker-html.js.gz
new file mode 100644
index 00000000..ec8aa87a
Binary files /dev/null and b/libraries/ESPAsyncWebServer/examples/ESP_AsyncFSBrowser/data/worker-html.js.gz differ
diff --git a/libraries/ESPAsyncWebServer/keywords.txt b/libraries/ESPAsyncWebServer/keywords.txt
new file mode 100644
index 00000000..c391e6c4
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/keywords.txt
@@ -0,0 +1,3 @@
+JsonArray KEYWORD1
+add KEYWORD2
+createArray KEYWORD3
diff --git a/libraries/ESPAsyncWebServer/library.properties b/libraries/ESPAsyncWebServer/library.properties
new file mode 100644
index 00000000..174bb2f5
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/library.properties
@@ -0,0 +1,9 @@
+name=ESP Async WebServer
+version=1.1.0
+author=Me-No-Dev
+maintainer=Me-No-Dev
+sentence=Async Web Server for ESP8266 and ESP31B
+paragraph=Async Web Server for ESP8266 and ESP31B
+category=Other
+url=https://github.com/me-no-dev/ESPAsyncWebServer
+architectures=*
diff --git a/libraries/ESPAsyncWebServer/src/AsyncEventSource.cpp b/libraries/ESPAsyncWebServer/src/AsyncEventSource.cpp
new file mode 100644
index 00000000..ecb6b019
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/src/AsyncEventSource.cpp
@@ -0,0 +1,345 @@
+/*
+ Asynchronous WebServer library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#include "Arduino.h"
+#include "AsyncEventSource.h"
+
+static String generateEventMessage(const char *message, const char *event, uint32_t id, uint32_t reconnect){
+ String ev = "";
+
+ if(reconnect){
+ ev += "retry: ";
+ ev += String(reconnect);
+ ev += "\r\n";
+ }
+
+ if(id){
+ ev += "id: ";
+ ev += String(id);
+ ev += "\r\n";
+ }
+
+ if(event != NULL){
+ ev += "event: ";
+ ev += String(event);
+ ev += "\r\n";
+ }
+
+ if(message != NULL){
+ size_t messageLen = strlen(message);
+ char * lineStart = (char *)message;
+ char * lineEnd;
+ do {
+ char * nextN = strchr(lineStart, '\n');
+ char * nextR = strchr(lineStart, '\r');
+ if(nextN == NULL && nextR == NULL){
+ size_t llen = ((char *)message + messageLen) - lineStart;
+ char * ldata = (char *)malloc(llen+1);
+ if(ldata != NULL){
+ memcpy(ldata, lineStart, llen);
+ ldata[llen] = 0;
+ ev += "data: ";
+ ev += ldata;
+ ev += "\r\n\r\n";
+ free(ldata);
+ }
+ lineStart = (char *)message + messageLen;
+ } else {
+ char * nextLine = NULL;
+ if(nextN != NULL && nextR != NULL){
+ if(nextR < nextN){
+ lineEnd = nextR;
+ if(nextN == (nextR + 1))
+ nextLine = nextN + 1;
+ else
+ nextLine = nextR + 1;
+ } else {
+ lineEnd = nextN;
+ if(nextR == (nextN + 1))
+ nextLine = nextR + 1;
+ else
+ nextLine = nextN + 1;
+ }
+ } else if(nextN != NULL){
+ lineEnd = nextN;
+ nextLine = nextN + 1;
+ } else {
+ lineEnd = nextR;
+ nextLine = nextR + 1;
+ }
+
+ size_t llen = lineEnd - lineStart;
+ char * ldata = (char *)malloc(llen+1);
+ if(ldata != NULL){
+ memcpy(ldata, lineStart, llen);
+ ldata[llen] = 0;
+ ev += "data: ";
+ ev += ldata;
+ ev += "\r\n";
+ free(ldata);
+ }
+ lineStart = nextLine;
+ if(lineStart == ((char *)message + messageLen))
+ ev += "\r\n";
+ }
+ } while(lineStart < ((char *)message + messageLen));
+ }
+
+ return ev;
+}
+
+// Message
+
+AsyncEventSourceMessage::AsyncEventSourceMessage(const char * data, size_t len)
+: _data(nullptr), _len(len), _sent(0), _acked(0)
+{
+ _data = (uint8_t*)malloc(_len+1);
+ if(_data == nullptr){
+ _len = 0;
+ } else {
+ memcpy(_data, data, len);
+ _data[_len] = 0;
+ }
+}
+
+AsyncEventSourceMessage::~AsyncEventSourceMessage() {
+ if(_data != NULL)
+ free(_data);
+}
+
+size_t AsyncEventSourceMessage::ack(size_t len, uint32_t time) {
+ // If the whole message is now acked...
+ if(_acked + len > _len){
+ // Return the number of extra bytes acked (they will be carried on to the next message)
+ const size_t extra = _acked + len - _len;
+ _acked = _len;
+ return extra;
+ }
+ // Return that no extra bytes left.
+ _acked += len;
+ return 0;
+}
+
+size_t AsyncEventSourceMessage::send(AsyncClient *client) {
+ const size_t len = _len - _sent;
+ if(client->space() < len){
+ return 0;
+ }
+ size_t sent = client->add((const char *)_data, len);
+ if(client->canSend())
+ client->send();
+ _sent += sent;
+ return sent;
+}
+
+// Client
+
+AsyncEventSourceClient::AsyncEventSourceClient(AsyncWebServerRequest *request, AsyncEventSource *server)
+: _messageQueue(LinkedList([](AsyncEventSourceMessage *m){ delete m; }))
+{
+ _client = request->client();
+ _server = server;
+ _lastId = 0;
+ if(request->hasHeader("Last-Event-ID"))
+ _lastId = atoi(request->getHeader("Last-Event-ID")->value().c_str());
+
+ _client->setRxTimeout(0);
+ _client->onError(NULL, NULL);
+ _client->onAck([](void *r, AsyncClient* c, size_t len, uint32_t time){ ((AsyncEventSourceClient*)(r))->_onAck(len, time); }, this);
+ _client->onPoll([](void *r, AsyncClient* c){ ((AsyncEventSourceClient*)(r))->_onPoll(); }, this);
+ _client->onData(NULL, NULL);
+ _client->onTimeout([this](void *r, AsyncClient* c __attribute__((unused)), uint32_t time){ ((AsyncEventSourceClient*)(r))->_onTimeout(time); }, this);
+ _client->onDisconnect([this](void *r, AsyncClient* c){ ((AsyncEventSourceClient*)(r))->_onDisconnect(); delete c; }, this);
+
+ _server->_addClient(this);
+ delete request;
+}
+
+AsyncEventSourceClient::~AsyncEventSourceClient(){
+ _messageQueue.free();
+ close();
+}
+
+void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage){
+ if(dataMessage == NULL)
+ return;
+ if(!connected()){
+ delete dataMessage;
+ return;
+ }
+
+ _messageQueue.add(dataMessage);
+
+ _runQueue();
+}
+
+void AsyncEventSourceClient::_onAck(size_t len, uint32_t time){
+ while(len && !_messageQueue.isEmpty()){
+ len = _messageQueue.front()->ack(len, time);
+ if(_messageQueue.front()->finished())
+ _messageQueue.remove(_messageQueue.front());
+ }
+
+ _runQueue();
+}
+
+void AsyncEventSourceClient::_onPoll(){
+ if(!_messageQueue.isEmpty()){
+ _runQueue();
+ }
+}
+
+
+void AsyncEventSourceClient::_onTimeout(uint32_t time __attribute__((unused))){
+ _client->close(true);
+}
+
+void AsyncEventSourceClient::_onDisconnect(){
+ _client = NULL;
+ _server->_handleDisconnect(this);
+}
+
+void AsyncEventSourceClient::close(){
+ if(_client != NULL)
+ _client->close();
+}
+
+void AsyncEventSourceClient::write(const char * message, size_t len){
+ _queueMessage(new AsyncEventSourceMessage(message, len));
+}
+
+void AsyncEventSourceClient::send(const char *message, const char *event, uint32_t id, uint32_t reconnect){
+ String ev = generateEventMessage(message, event, id, reconnect);
+ _queueMessage(new AsyncEventSourceMessage(ev.c_str(), ev.length()));
+}
+
+void AsyncEventSourceClient::_runQueue(){
+ while(!_messageQueue.isEmpty() && _messageQueue.front()->finished()){
+ _messageQueue.remove(_messageQueue.front());
+ }
+
+ for(auto i = _messageQueue.begin(); i != _messageQueue.end(); ++i)
+ {
+ if(!(*i)->sent())
+ (*i)->send(_client);
+ }
+}
+
+
+// Handler
+
+AsyncEventSource::AsyncEventSource(const String& url)
+ : _url(url)
+ , _clients(LinkedList([](AsyncEventSourceClient *c){ delete c; }))
+ , _connectcb(NULL)
+{}
+
+AsyncEventSource::~AsyncEventSource(){
+ close();
+}
+
+void AsyncEventSource::onConnect(ArEventHandlerFunction cb){
+ _connectcb = cb;
+}
+
+void AsyncEventSource::_addClient(AsyncEventSourceClient * client){
+ /*char * temp = (char *)malloc(2054);
+ if(temp != NULL){
+ memset(temp+1,' ',2048);
+ temp[0] = ':';
+ temp[2049] = '\r';
+ temp[2050] = '\n';
+ temp[2051] = '\r';
+ temp[2052] = '\n';
+ temp[2053] = 0;
+ client->write((const char *)temp, 2053);
+ free(temp);
+ }*/
+
+ _clients.add(client);
+ if(_connectcb)
+ _connectcb(client);
+}
+
+void AsyncEventSource::_handleDisconnect(AsyncEventSourceClient * client){
+ _clients.remove(client);
+}
+
+void AsyncEventSource::close(){
+ for(const auto &c: _clients){
+ if(c->connected())
+ c->close();
+ }
+}
+
+void AsyncEventSource::send(const char *message, const char *event, uint32_t id, uint32_t reconnect){
+ if(_clients.isEmpty())
+ return;
+
+ String ev = generateEventMessage(message, event, id, reconnect);
+ for(const auto &c: _clients){
+ if(c->connected()) {
+ c->write(ev.c_str(), ev.length());
+ }
+ }
+}
+
+size_t AsyncEventSource::count() const {
+ return _clients.count_if([](AsyncEventSourceClient *c){
+ return c->connected();
+ });
+}
+
+bool AsyncEventSource::canHandle(AsyncWebServerRequest *request){
+ if(request->method() != HTTP_GET || !request->url().equals(_url) || !request->isExpectedRequestedConnType(RCT_EVENT))
+ return false;
+ request->addInterestingHeader("Last-Event-ID");
+ return true;
+}
+
+void AsyncEventSource::handleRequest(AsyncWebServerRequest *request){
+ if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
+ return request->requestAuthentication();
+ request->send(new AsyncEventSourceResponse(this));
+}
+
+// Response
+
+AsyncEventSourceResponse::AsyncEventSourceResponse(AsyncEventSource *server){
+ _server = server;
+ _code = 200;
+ _contentType = "text/event-stream";
+ _sendContentLength = false;
+ addHeader("Cache-Control", "no-cache");
+ addHeader("Connection","keep-alive");
+}
+
+void AsyncEventSourceResponse::_respond(AsyncWebServerRequest *request){
+ String out = _assembleHead(request->version());
+ request->client()->write(out.c_str(), _headLength);
+ _state = RESPONSE_WAIT_ACK;
+}
+
+size_t AsyncEventSourceResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time __attribute__((unused))){
+ if(len){
+ new AsyncEventSourceClient(request, _server);
+ }
+ return 0;
+}
+
diff --git a/libraries/ESPAsyncWebServer/src/AsyncEventSource.h b/libraries/ESPAsyncWebServer/src/AsyncEventSource.h
new file mode 100644
index 00000000..1b4d604d
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/src/AsyncEventSource.h
@@ -0,0 +1,114 @@
+/*
+ Asynchronous WebServer library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#ifndef ASYNCEVENTSOURCE_H_
+#define ASYNCEVENTSOURCE_H_
+
+#include
+#ifdef ESP32
+#include
+#else
+#include
+#endif
+#include
+
+class AsyncEventSource;
+class AsyncEventSourceResponse;
+class AsyncEventSourceClient;
+typedef std::function ArEventHandlerFunction;
+
+class AsyncEventSourceMessage {
+ private:
+ uint8_t * _data;
+ size_t _len;
+ size_t _sent;
+ //size_t _ack;
+ size_t _acked;
+ public:
+ AsyncEventSourceMessage(const char * data, size_t len);
+ ~AsyncEventSourceMessage();
+ size_t ack(size_t len, uint32_t time __attribute__((unused)));
+ size_t send(AsyncClient *client);
+ bool finished(){ return _acked == _len; }
+ bool sent() { return _sent == _len; }
+};
+
+class AsyncEventSourceClient {
+ private:
+ AsyncClient *_client;
+ AsyncEventSource *_server;
+ uint32_t _lastId;
+ LinkedList _messageQueue;
+ void _queueMessage(AsyncEventSourceMessage *dataMessage);
+ void _runQueue();
+
+ public:
+
+ AsyncEventSourceClient(AsyncWebServerRequest *request, AsyncEventSource *server);
+ ~AsyncEventSourceClient();
+
+ AsyncClient* client(){ return _client; }
+ void close();
+ void write(const char * message, size_t len);
+ void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0);
+ bool connected() const { return (_client != NULL) && _client->connected(); }
+ uint32_t lastId() const { return _lastId; }
+
+ //system callbacks (do not call)
+ void _onAck(size_t len, uint32_t time);
+ void _onPoll();
+ void _onTimeout(uint32_t time);
+ void _onDisconnect();
+};
+
+class AsyncEventSource: public AsyncWebHandler {
+ private:
+ String _url;
+ LinkedList _clients;
+ ArEventHandlerFunction _connectcb;
+ public:
+ AsyncEventSource(const String& url);
+ ~AsyncEventSource();
+
+ const char * url() const { return _url.c_str(); }
+ void close();
+ void onConnect(ArEventHandlerFunction cb);
+ void send(const char *message, const char *event=NULL, uint32_t id=0, uint32_t reconnect=0);
+ size_t count() const; //number clinets connected
+
+ //system callbacks (do not call)
+ void _addClient(AsyncEventSourceClient * client);
+ void _handleDisconnect(AsyncEventSourceClient * client);
+ virtual bool canHandle(AsyncWebServerRequest *request) override final;
+ virtual void handleRequest(AsyncWebServerRequest *request) override final;
+};
+
+class AsyncEventSourceResponse: public AsyncWebServerResponse {
+ private:
+ String _content;
+ AsyncEventSource *_server;
+ public:
+ AsyncEventSourceResponse(AsyncEventSource *server);
+ void _respond(AsyncWebServerRequest *request);
+ size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
+ bool _sourceValid() const { return true; }
+};
+
+
+#endif /* ASYNCEVENTSOURCE_H_ */
diff --git a/libraries/ESPAsyncWebServer/src/AsyncJson.h b/libraries/ESPAsyncWebServer/src/AsyncJson.h
new file mode 100644
index 00000000..4d37062d
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/src/AsyncJson.h
@@ -0,0 +1,83 @@
+// ESPasyncJson.h
+/*
+ Async Response to use with arduinoJson and asyncwebserver
+ Written by Andrew Melvin (SticilFace) with help from me-no-dev and BBlanchon.
+
+ example of callback in use
+
+ server.on("/json", HTTP_ANY, [](AsyncWebServerRequest * request) {
+
+ AsyncJsonResponse * response = new AsyncJsonResponse();
+ JsonObject& root = response->getRoot();
+ root["key1"] = "key number one";
+ JsonObject& nested = root.createNestedObject("nested");
+ nested["key1"] = "key number one";
+
+ response->setLength();
+ request->send(response);
+ });
+
+*/
+#ifndef ASYNC_JSON_H_
+#define ASYNC_JSON_H_
+#include
+
+/*
+ * Json Response
+ * */
+
+class ChunkPrint : public Print {
+ private:
+ uint8_t* _destination;
+ size_t _to_skip;
+ size_t _to_write;
+ size_t _pos;
+ public:
+ ChunkPrint(uint8_t* destination, size_t from, size_t len)
+ : _destination(destination), _to_skip(from), _to_write(len), _pos{0} {}
+ virtual ~ChunkPrint(){}
+ size_t write(uint8_t c){
+ if (_to_skip > 0) {
+ _to_skip--;
+ return 1;
+ } else if (_to_write > 0) {
+ _to_write--;
+ _destination[_pos++] = c;
+ return 1;
+ }
+ return 0;
+ }
+};
+
+class AsyncJsonResponse: public AsyncAbstractResponse {
+ private:
+ DynamicJsonBuffer _jsonBuffer;
+ JsonVariant _root;
+ bool _isValid;
+ public:
+ AsyncJsonResponse(bool isArray=false): _isValid{false} {
+ _code = 200;
+ _contentType = "text/json";
+ if(isArray)
+ _root = _jsonBuffer.createArray();
+ else
+ _root = _jsonBuffer.createObject();
+ }
+ ~AsyncJsonResponse() {}
+ JsonVariant & getRoot() { return _root; }
+ bool _sourceValid() const { return _isValid; }
+ size_t setLength() {
+ _contentLength = _root.measureLength();
+ if (_contentLength) { _isValid = true; }
+ return _contentLength;
+ }
+
+ size_t getSize() { return _jsonBuffer.size(); }
+
+ size_t _fillBuffer(uint8_t *data, size_t len){
+ ChunkPrint dest(data, _sentLength, len);
+ _root.printTo( dest ) ;
+ return len;
+ }
+};
+#endif
diff --git a/libraries/ESPAsyncWebServer/src/AsyncWebSocket.cpp b/libraries/ESPAsyncWebServer/src/AsyncWebSocket.cpp
new file mode 100644
index 00000000..7eeadac4
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/src/AsyncWebSocket.cpp
@@ -0,0 +1,1206 @@
+/*
+ Asynchronous WebServer library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#include "Arduino.h"
+#include "AsyncWebSocket.h"
+
+#include
+
+#ifndef ESP8266
+extern "C" {
+typedef struct {
+ uint32_t state[5];
+ uint32_t count[2];
+ unsigned char buffer[64];
+} SHA1_CTX;
+
+void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
+void SHA1Init(SHA1_CTX* context);
+void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
+void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
+}
+#else
+#include
+#endif
+
+#define MAX_PRINTF_LEN 64
+
+size_t webSocketSendFrameWindow(AsyncClient *client){
+ if(!client->canSend())
+ return 0;
+ size_t space = client->space();
+ if(space < 9)
+ return 0;
+ return space - 8;
+}
+
+size_t webSocketSendFrame(AsyncClient *client, bool final, uint8_t opcode, bool mask, uint8_t *data, size_t len){
+ if(!client->canSend())
+ return 0;
+ size_t space = client->space();
+ if(space < 2)
+ return 0;
+ uint8_t mbuf[4] = {0,0,0,0};
+ uint8_t headLen = 2;
+ if(len && mask){
+ headLen += 4;
+ mbuf[0] = rand() % 0xFF;
+ mbuf[1] = rand() % 0xFF;
+ mbuf[2] = rand() % 0xFF;
+ mbuf[3] = rand() % 0xFF;
+ }
+ if(len > 125)
+ headLen += 2;
+ if(space < headLen)
+ return 0;
+ space -= headLen;
+
+ if(len > space) len = space;
+
+ uint8_t *buf = (uint8_t*)malloc(headLen);
+ if(buf == NULL){
+ //os_printf("could not malloc %u bytes for frame header\n", headLen);
+ return 0;
+ }
+
+ buf[0] = opcode & 0x0F;
+ if(final)
+ buf[0] |= 0x80;
+ if(len < 126)
+ buf[1] = len & 0x7F;
+ else {
+ buf[1] = 126;
+ buf[2] = (uint8_t)((len >> 8) & 0xFF);
+ buf[3] = (uint8_t)(len & 0xFF);
+ }
+ if(len && mask){
+ buf[1] |= 0x80;
+ memcpy(buf + (headLen - 4), mbuf, 4);
+ }
+ if(client->add((const char *)buf, headLen) != headLen){
+ //os_printf("error adding %lu header bytes\n", headLen);
+ free(buf);
+ return 0;
+ }
+ free(buf);
+
+ if(len){
+ if(len && mask){
+ size_t i;
+ for(i=0;iadd((const char *)data, len) != len){
+ //os_printf("error adding %lu data bytes\n", len);
+ return 0;
+ }
+ }
+ if(!client->send()){
+ //os_printf("error sending frame: %lu\n", headLen+len);
+ return 0;
+ }
+ return len;
+}
+
+
+/*
+ * AsyncWebSocketMessageBuffer
+ */
+
+
+
+AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer()
+ :_data(nullptr)
+ ,_len(0)
+ ,_lock(false)
+ ,_count(0)
+{
+
+}
+
+AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(uint8_t * data, size_t size)
+ :_data(nullptr)
+ ,_len(size)
+ ,_lock(false)
+ ,_count(0)
+{
+
+ if (!data) {
+ return;
+ }
+
+ _data = new uint8_t[size + 1];
+
+ if (_data) {
+ memcpy(_data, data, _len);
+ _data[_len] = 0;
+ }
+}
+
+
+AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(size_t size)
+ :_data(nullptr)
+ ,_len(size)
+ ,_lock(false)
+ ,_count(0)
+{
+ _data = new uint8_t[_len + 1];
+
+ if (_data) {
+ _data[_len] = 0;
+ }
+
+}
+
+AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(const AsyncWebSocketMessageBuffer & copy)
+ :_data(nullptr)
+ ,_len(0)
+ ,_lock(false)
+ ,_count(0)
+{
+ _len = copy._len;
+ _lock = copy._lock;
+ _count = 0;
+
+ if (_len) {
+ _data = new uint8_t[_len + 1];
+ _data[_len] = 0;
+ }
+
+ if (_data) {
+ memcpy(_data, copy._data, _len);
+ _data[_len] = 0;
+ }
+
+}
+
+AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(AsyncWebSocketMessageBuffer && copy)
+ :_data(nullptr)
+ ,_len(0)
+ ,_lock(false)
+ ,_count(0)
+{
+ _len = copy._len;
+ _lock = copy._lock;
+ _count = 0;
+
+ if (copy._data) {
+ _data = copy._data;
+ copy._data = nullptr;
+ }
+
+}
+
+AsyncWebSocketMessageBuffer::~AsyncWebSocketMessageBuffer()
+{
+ if (_data) {
+ delete[] _data;
+ }
+}
+
+bool AsyncWebSocketMessageBuffer::reserve(size_t size)
+{
+ _len = size;
+
+ if (_data) {
+ delete[] _data;
+ _data = nullptr;
+ }
+
+ _data = new uint8_t[size];
+
+ if (_data) {
+ _data[_len] = 0;
+ return true;
+ } else {
+ return false;
+ }
+
+}
+
+
+
+/*
+ * Control Frame
+ */
+
+class AsyncWebSocketControl {
+ private:
+ uint8_t _opcode;
+ uint8_t *_data;
+ size_t _len;
+ bool _mask;
+ bool _finished;
+ public:
+ AsyncWebSocketControl(uint8_t opcode, uint8_t *data=NULL, size_t len=0, bool mask=false)
+ :_opcode(opcode)
+ ,_len(len)
+ ,_mask(len && mask)
+ ,_finished(false)
+ {
+ if(data == NULL)
+ _len = 0;
+ if(_len){
+ if(_len > 125)
+ _len = 125;
+ _data = (uint8_t*)malloc(_len);
+ if(_data == NULL)
+ _len = 0;
+ else memcpy(_data, data, len);
+ } else _data = NULL;
+ }
+ virtual ~AsyncWebSocketControl(){
+ if(_data != NULL)
+ free(_data);
+ }
+ virtual bool finished() const { return _finished; }
+ uint8_t opcode(){ return _opcode; }
+ uint8_t len(){ return _len + 2; }
+ size_t send(AsyncClient *client){
+ _finished = true;
+ return webSocketSendFrame(client, true, _opcode & 0x0F, _mask, _data, _len);
+ }
+};
+
+/*
+ * Basic Buffered Message
+ */
+
+
+AsyncWebSocketBasicMessage::AsyncWebSocketBasicMessage(const char * data, size_t len, uint8_t opcode, bool mask)
+ :_len(len)
+ ,_sent(0)
+ ,_ack(0)
+ ,_acked(0)
+{
+ _opcode = opcode & 0x07;
+ _mask = mask;
+ _data = (uint8_t*)malloc(_len+1);
+ if(_data == NULL){
+ _len = 0;
+ _status = WS_MSG_ERROR;
+ } else {
+ _status = WS_MSG_SENDING;
+ memcpy(_data, data, _len);
+ _data[_len] = 0;
+ }
+}
+AsyncWebSocketBasicMessage::AsyncWebSocketBasicMessage(uint8_t opcode, bool mask)
+ :_len(0)
+ ,_sent(0)
+ ,_ack(0)
+ ,_acked(0)
+ ,_data(NULL)
+{
+ _opcode = opcode & 0x07;
+ _mask = mask;
+
+}
+
+
+AsyncWebSocketBasicMessage::~AsyncWebSocketBasicMessage() {
+ if(_data != NULL)
+ free(_data);
+}
+
+ void AsyncWebSocketBasicMessage::ack(size_t len, uint32_t time) {
+ _acked += len;
+ if(_sent == _len && _acked == _ack){
+ _status = WS_MSG_SENT;
+ }
+}
+ size_t AsyncWebSocketBasicMessage::send(AsyncClient *client) {
+ if(_status != WS_MSG_SENDING)
+ return 0;
+ if(_acked < _ack){
+ return 0;
+ }
+ if(_sent == _len){
+ if(_acked == _ack)
+ _status = WS_MSG_SENT;
+ return 0;
+ }
+ size_t window = webSocketSendFrameWindow(client);
+ size_t toSend = _len - _sent;
+ if(window < toSend) toSend = window;
+ bool final = ((toSend + _sent) == _len);
+ size_t sent = webSocketSendFrame(client, final, (_sent == 0)?_opcode:(int)WS_CONTINUATION, _mask, (uint8_t*)(_data+_sent), toSend);
+ _sent += sent;
+ uint8_t headLen = ((sent < 126)?2:4)+(_mask*4);
+ _ack += sent + headLen;
+ return sent;
+}
+
+// bool AsyncWebSocketBasicMessage::reserve(size_t size) {
+// if (size) {
+// _data = (uint8_t*)malloc(size +1);
+// if (_data) {
+// memset(_data, 0, size);
+// _len = size;
+// _status = WS_MSG_SENDING;
+// return true;
+// }
+// }
+// return false;
+// }
+
+
+/*
+ * AsyncWebSocketMultiMessage Message
+ */
+
+
+AsyncWebSocketMultiMessage::AsyncWebSocketMultiMessage(AsyncWebSocketMessageBuffer * buffer, uint8_t opcode, bool mask)
+ :_len(0)
+ ,_sent(0)
+ ,_ack(0)
+ ,_acked(0)
+ ,_WSbuffer(nullptr)
+{
+
+ _opcode = opcode & 0x07;
+ _mask = mask;
+
+ if (buffer) {
+ _WSbuffer = buffer;
+ (*_WSbuffer)++;
+ _data = buffer->get();
+ _len = buffer->length();
+ _status = WS_MSG_SENDING;
+ } else {
+ _status = WS_MSG_ERROR;
+ }
+
+}
+
+
+AsyncWebSocketMultiMessage::~AsyncWebSocketMultiMessage() {
+ if (_WSbuffer) {
+ (*_WSbuffer)--; // decreases the counter.
+ }
+}
+
+ void AsyncWebSocketMultiMessage::ack(size_t len, uint32_t time) {
+ _acked += len;
+ if(_sent == _len && _acked == _ack){
+ _status = WS_MSG_SENT;
+ }
+}
+ size_t AsyncWebSocketMultiMessage::send(AsyncClient *client) {
+ if(_status != WS_MSG_SENDING)
+ return 0;
+ if(_acked < _ack){
+ return 0;
+ }
+ if(_sent == _len){
+ if(_acked == _ack)
+ _status = WS_MSG_SENT;
+ return 0;
+ }
+ size_t window = webSocketSendFrameWindow(client);
+ size_t toSend = _len - _sent;
+ if(window < toSend) toSend = window;
+ bool final = ((toSend + _sent) == _len);
+ size_t sent = webSocketSendFrame(client, final, (_sent == 0)?_opcode:(int)WS_CONTINUATION, _mask, (uint8_t*)(_data+_sent), toSend);
+ _sent += sent;
+ uint8_t headLen = ((sent < 126)?2:4)+(_mask*4);
+ _ack += sent + headLen;
+ return sent;
+}
+
+
+/*
+ * Async WebSocket Client
+ */
+ const char * AWSC_PING_PAYLOAD = "ESPAsyncWebServer-PING";
+ const size_t AWSC_PING_PAYLOAD_LEN = 22;
+
+AsyncWebSocketClient::AsyncWebSocketClient(AsyncWebServerRequest *request, AsyncWebSocket *server)
+ : _controlQueue(LinkedList([](AsyncWebSocketControl *c){ delete c; }))
+ , _messageQueue(LinkedList([](AsyncWebSocketMessage *m){ delete m; }))
+ , _tempObject(NULL)
+{
+ _client = request->client();
+ _server = server;
+ _clientId = _server->_getNextId();
+ _status = WS_CONNECTED;
+ _pstate = 0;
+ _lastMessageTime = millis();
+ _keepAlivePeriod = 0;
+ _client->setRxTimeout(0);
+ _client->onError([](void *r, AsyncClient* c, int8_t error){ ((AsyncWebSocketClient*)(r))->_onError(error); }, this);
+ _client->onAck([](void *r, AsyncClient* c, size_t len, uint32_t time){ ((AsyncWebSocketClient*)(r))->_onAck(len, time); }, this);
+ _client->onDisconnect([](void *r, AsyncClient* c){ ((AsyncWebSocketClient*)(r))->_onDisconnect(); delete c; }, this);
+ _client->onTimeout([](void *r, AsyncClient* c, uint32_t time){ ((AsyncWebSocketClient*)(r))->_onTimeout(time); }, this);
+ _client->onData([](void *r, AsyncClient* c, void *buf, size_t len){ ((AsyncWebSocketClient*)(r))->_onData(buf, len); }, this);
+ _client->onPoll([](void *r, AsyncClient* c){ ((AsyncWebSocketClient*)(r))->_onPoll(); }, this);
+ _server->_addClient(this);
+ _server->_handleEvent(this, WS_EVT_CONNECT, NULL, NULL, 0);
+ delete request;
+}
+
+AsyncWebSocketClient::~AsyncWebSocketClient(){
+ _messageQueue.free();
+ _controlQueue.free();
+ _server->_handleEvent(this, WS_EVT_DISCONNECT, NULL, NULL, 0);
+}
+
+void AsyncWebSocketClient::_onAck(size_t len, uint32_t time){
+ _lastMessageTime = millis();
+ if(!_controlQueue.isEmpty()){
+ auto head = _controlQueue.front();
+ if(head->finished()){
+ len -= head->len();
+ if(_status == WS_DISCONNECTING && head->opcode() == WS_DISCONNECT){
+ _controlQueue.remove(head);
+ _status = WS_DISCONNECTED;
+ _client->close(true);
+ return;
+ }
+ _controlQueue.remove(head);
+ }
+ }
+ if(len && !_messageQueue.isEmpty()){
+ _messageQueue.front()->ack(len, time);
+ }
+ _server->_cleanBuffers();
+ _runQueue();
+}
+
+void AsyncWebSocketClient::_onPoll(){
+ if(_client->canSend() && (!_controlQueue.isEmpty() || !_messageQueue.isEmpty())){
+ _runQueue();
+ } else if(_keepAlivePeriod > 0 && _controlQueue.isEmpty() && _messageQueue.isEmpty() && (millis() - _lastMessageTime) >= _keepAlivePeriod){
+ ping((uint8_t *)AWSC_PING_PAYLOAD, AWSC_PING_PAYLOAD_LEN);
+ }
+}
+
+void AsyncWebSocketClient::_runQueue(){
+ while(!_messageQueue.isEmpty() && _messageQueue.front()->finished()){
+ _messageQueue.remove(_messageQueue.front());
+ }
+
+ if(!_controlQueue.isEmpty() && (_messageQueue.isEmpty() || _messageQueue.front()->betweenFrames()) && webSocketSendFrameWindow(_client) > (size_t)(_controlQueue.front()->len() - 1)){
+ _controlQueue.front()->send(_client);
+ } else if(!_messageQueue.isEmpty() && _messageQueue.front()->betweenFrames() && webSocketSendFrameWindow(_client)){
+ _messageQueue.front()->send(_client);
+ }
+}
+
+void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage *dataMessage){
+ if(dataMessage == NULL)
+ return;
+ if(_status != WS_CONNECTED){
+ delete dataMessage;
+ return;
+ }
+ _messageQueue.add(dataMessage);
+ if(_client->canSend())
+ _runQueue();
+}
+
+void AsyncWebSocketClient::_queueControl(AsyncWebSocketControl *controlMessage){
+ if(controlMessage == NULL)
+ return;
+ _controlQueue.add(controlMessage);
+ if(_client->canSend())
+ _runQueue();
+}
+
+void AsyncWebSocketClient::close(uint16_t code, const char * message){
+ if(_status != WS_CONNECTED)
+ return;
+ if(code){
+ uint8_t packetLen = 2;
+ if(message != NULL){
+ size_t mlen = strlen(message);
+ if(mlen > 123) mlen = 123;
+ packetLen += mlen;
+ }
+ char * buf = (char*)malloc(packetLen);
+ if(buf != NULL){
+ buf[0] = (uint8_t)(code >> 8);
+ buf[1] = (uint8_t)(code & 0xFF);
+ if(message != NULL){
+ memcpy(buf+2, message, packetLen -2);
+ }
+ _queueControl(new AsyncWebSocketControl(WS_DISCONNECT,(uint8_t*)buf,packetLen));
+ free(buf);
+ return;
+ }
+ }
+ _queueControl(new AsyncWebSocketControl(WS_DISCONNECT));
+}
+
+void AsyncWebSocketClient::ping(uint8_t *data, size_t len){
+ if(_status == WS_CONNECTED)
+ _queueControl(new AsyncWebSocketControl(WS_PING, data, len));
+}
+
+void AsyncWebSocketClient::_onError(int8_t){}
+
+void AsyncWebSocketClient::_onTimeout(uint32_t time){
+ _client->close(true);
+}
+
+void AsyncWebSocketClient::_onDisconnect(){
+ _client = NULL;
+ _server->_handleDisconnect(this);
+}
+
+void AsyncWebSocketClient::_onData(void *buf, size_t plen){
+ _lastMessageTime = millis();
+ uint8_t *fdata = (uint8_t*)buf;
+ uint8_t * data = fdata;
+ if(!_pstate){
+ _pinfo.index = 0;
+ _pinfo.final = (fdata[0] & 0x80) != 0;
+ _pinfo.opcode = fdata[0] & 0x0F;
+ _pinfo.masked = (fdata[1] & 0x80) != 0;
+ _pinfo.len = fdata[1] & 0x7F;
+ data += 2;
+ plen = plen - 2;
+ if(_pinfo.len == 126){
+ _pinfo.len = fdata[3] | (uint16_t)(fdata[2]) << 8;
+ data += 2;
+ plen = plen - 2;
+ } else if(_pinfo.len == 127){
+ _pinfo.len = fdata[9] | (uint16_t)(fdata[8]) << 8 | (uint32_t)(fdata[7]) << 16 | (uint32_t)(fdata[6]) << 24 | (uint64_t)(fdata[5]) << 32 | (uint64_t)(fdata[4]) << 40 | (uint64_t)(fdata[3]) << 48 | (uint64_t)(fdata[2]) << 56;
+ data += 8;
+ plen = plen - 8;
+ }
+
+ if(_pinfo.masked){
+ memcpy(_pinfo.mask, data, 4);
+ data += 4;
+ plen = plen - 4;
+ size_t i;
+ for(i=0;i_handleEvent(this, WS_EVT_DATA, (void *)&_pinfo, (uint8_t*)data, plen);
+
+ _pinfo.index += plen;
+ } else if((plen + _pinfo.index) == _pinfo.len){
+ _pstate = 0;
+ if(_pinfo.opcode == WS_DISCONNECT){
+ if(plen){
+ uint16_t reasonCode = (uint16_t)(data[0] << 8) + data[1];
+ char * reasonString = (char*)(data+2);
+ if(reasonCode > 1001){
+ _server->_handleEvent(this, WS_EVT_ERROR, (void *)&reasonCode, (uint8_t*)reasonString, strlen(reasonString));
+ }
+ }
+ if(_status == WS_DISCONNECTING){
+ _status = WS_DISCONNECTED;
+ _client->close(true);
+ } else {
+ _status = WS_DISCONNECTING;
+ _queueControl(new AsyncWebSocketControl(WS_DISCONNECT, data, plen));
+ }
+ } else if(_pinfo.opcode == WS_PING){
+ _queueControl(new AsyncWebSocketControl(WS_PONG, data, plen));
+ } else if(_pinfo.opcode == WS_PONG){
+ if(plen != AWSC_PING_PAYLOAD_LEN || memcmp(AWSC_PING_PAYLOAD, data, AWSC_PING_PAYLOAD_LEN) != 0)
+ _server->_handleEvent(this, WS_EVT_PONG, NULL, (uint8_t*)data, plen);
+ } else if(_pinfo.opcode < 8){//continuation or text/binary frame
+ _server->_handleEvent(this, WS_EVT_DATA, (void *)&_pinfo, (uint8_t*)data, plen);
+ }
+ } else {
+ //os_printf("frame error: len: %u, index: %llu, total: %llu\n", plen, _pinfo.index, _pinfo.len);
+ //what should we do?
+ }
+}
+
+size_t AsyncWebSocketClient::printf(const char *format, ...) {
+ va_list arg;
+ va_start(arg, format);
+ char* temp = new char[MAX_PRINTF_LEN];
+ if(!temp){
+ return 0;
+ }
+ char* buffer = temp;
+ size_t len = vsnprintf(temp, MAX_PRINTF_LEN, format, arg);
+ va_end(arg);
+
+ if (len > (MAX_PRINTF_LEN - 1)) {
+ buffer = new char[len + 1];
+ if (!buffer) {
+ delete[] temp;
+ return 0;
+ }
+ va_start(arg, format);
+ vsnprintf(buffer, len + 1, format, arg);
+ va_end(arg);
+ }
+ text(buffer, len);
+ if (buffer != temp) {
+ delete[] buffer;
+ }
+ delete[] temp;
+ return len;
+}
+
+#ifndef ESP32
+size_t AsyncWebSocketClient::printf_P(PGM_P formatP, ...) {
+ va_list arg;
+ va_start(arg, formatP);
+ char* temp = new char[MAX_PRINTF_LEN];
+ if(!temp){
+ return 0;
+ }
+ char* buffer = temp;
+ size_t len = vsnprintf_P(temp, MAX_PRINTF_LEN, formatP, arg);
+ va_end(arg);
+
+ if (len > (MAX_PRINTF_LEN - 1)) {
+ buffer = new char[len + 1];
+ if (!buffer) {
+ delete[] temp;
+ return 0;
+ }
+ va_start(arg, formatP);
+ vsnprintf_P(buffer, len + 1, formatP, arg);
+ va_end(arg);
+ }
+ text(buffer, len);
+ if (buffer != temp) {
+ delete[] buffer;
+ }
+ delete[] temp;
+ return len;
+}
+#endif
+
+void AsyncWebSocketClient::text(const char * message, size_t len){
+ _queueMessage(new AsyncWebSocketBasicMessage(message, len));
+}
+void AsyncWebSocketClient::text(const char * message){
+ text(message, strlen(message));
+}
+void AsyncWebSocketClient::text(uint8_t * message, size_t len){
+ text((const char *)message, len);
+}
+void AsyncWebSocketClient::text(char * message){
+ text(message, strlen(message));
+}
+void AsyncWebSocketClient::text(const String &message){
+ text(message.c_str(), message.length());
+}
+void AsyncWebSocketClient::text(const __FlashStringHelper *data){
+ PGM_P p = reinterpret_cast(data);
+ size_t n = 0;
+ while (1) {
+ if (pgm_read_byte(p+n) == 0) break;
+ n += 1;
+ }
+ char * message = (char*) malloc(n+1);
+ if(message){
+ for(size_t b=0; b(data);
+ char * message = (char*) malloc(len);
+ if(message){
+ for(size_t b=0; bremoteIP();
+}
+
+uint16_t AsyncWebSocketClient::remotePort() {
+ if(!_client) {
+ return 0;
+ }
+ return _client->remotePort();
+}
+
+
+
+/*
+ * Async Web Socket - Each separate socket location
+ */
+
+AsyncWebSocket::AsyncWebSocket(const String& url)
+ :_url(url)
+ ,_clients(LinkedList([](AsyncWebSocketClient *c){ delete c; }))
+ ,_cNextId(1)
+ ,_enabled(true)
+ ,_buffers(LinkedList([](AsyncWebSocketMessageBuffer *b){ delete b; }))
+{
+ _eventHandler = NULL;
+}
+
+AsyncWebSocket::~AsyncWebSocket(){}
+
+void AsyncWebSocket::_handleEvent(AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
+ if(_eventHandler != NULL){
+ _eventHandler(this, client, type, arg, data, len);
+ }
+}
+
+void AsyncWebSocket::_addClient(AsyncWebSocketClient * client){
+ _clients.add(client);
+}
+
+void AsyncWebSocket::_handleDisconnect(AsyncWebSocketClient * client){
+
+ _clients.remove_first([=](AsyncWebSocketClient * c){
+ return c->id() == client->id();
+ });
+}
+
+size_t AsyncWebSocket::count() const {
+ return _clients.count_if([](AsyncWebSocketClient * c){
+ return c->status() == WS_CONNECTED;
+ });
+}
+
+AsyncWebSocketClient * AsyncWebSocket::client(uint32_t id){
+ for(const auto &c: _clients){
+ if(c->id() == id && c->status() == WS_CONNECTED){
+ return c;
+ }
+ }
+ return nullptr;
+}
+
+
+void AsyncWebSocket::close(uint32_t id, uint16_t code, const char * message){
+ AsyncWebSocketClient * c = client(id);
+ if(c)
+ c->close(code, message);
+}
+
+void AsyncWebSocket::closeAll(uint16_t code, const char * message){
+ for(const auto& c: _clients){
+ if(c->status() == WS_CONNECTED)
+ c->close(code, message);
+ }
+}
+
+void AsyncWebSocket::ping(uint32_t id, uint8_t *data, size_t len){
+ AsyncWebSocketClient * c = client(id);
+ if(c)
+ c->ping(data, len);
+}
+
+void AsyncWebSocket::pingAll(uint8_t *data, size_t len){
+ for(const auto& c: _clients){
+ if(c->status() == WS_CONNECTED)
+ c->ping(data, len);
+ }
+}
+
+void AsyncWebSocket::text(uint32_t id, const char * message, size_t len){
+ AsyncWebSocketClient * c = client(id);
+ if(c)
+ c->text(message, len);
+}
+
+void AsyncWebSocket::textAll(AsyncWebSocketMessageBuffer * buffer){
+ if (!buffer) return;
+ buffer->lock();
+ for(const auto& c: _clients){
+ if(c->status() == WS_CONNECTED)
+ c->text(buffer);
+ }
+ buffer->unlock();
+ _cleanBuffers();
+}
+
+
+void AsyncWebSocket::textAll(const char * message, size_t len){
+ AsyncWebSocketMessageBuffer * WSBuffer = makeBuffer((uint8_t *)message, len);
+ textAll(WSBuffer);
+}
+
+void AsyncWebSocket::binary(uint32_t id, const char * message, size_t len){
+ AsyncWebSocketClient * c = client(id);
+ if(c)
+ c->binary(message, len);
+}
+
+void AsyncWebSocket::binaryAll(const char * message, size_t len){
+ AsyncWebSocketMessageBuffer * buffer = makeBuffer((uint8_t *)message, len);
+ binaryAll(buffer);
+}
+
+void AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer * buffer)
+{
+ if (!buffer) return;
+ buffer->lock();
+ for(const auto& c: _clients){
+ if(c->status() == WS_CONNECTED)
+ c->binary(buffer);
+ }
+ buffer->unlock();
+ _cleanBuffers();
+}
+
+void AsyncWebSocket::message(uint32_t id, AsyncWebSocketMessage *message){
+ AsyncWebSocketClient * c = client(id);
+ if(c)
+ c->message(message);
+}
+
+void AsyncWebSocket::messageAll(AsyncWebSocketMultiMessage *message){
+ for(const auto& c: _clients){
+ if(c->status() == WS_CONNECTED)
+ c->message(message);
+ }
+ _cleanBuffers();
+}
+
+size_t AsyncWebSocket::printf(uint32_t id, const char *format, ...){
+ AsyncWebSocketClient * c = client(id);
+ if(c){
+ va_list arg;
+ va_start(arg, format);
+ size_t len = c->printf(format, arg);
+ va_end(arg);
+ return len;
+ }
+ return 0;
+}
+
+size_t AsyncWebSocket::printfAll(const char *format, ...) {
+ va_list arg;
+ char* temp = new char[MAX_PRINTF_LEN];
+ if(!temp){
+ return 0;
+ }
+ va_start(arg, format);
+ size_t len = vsnprintf(temp, MAX_PRINTF_LEN, format, arg);
+ va_end(arg);
+ delete[] temp;
+
+ AsyncWebSocketMessageBuffer * buffer = makeBuffer(len + 1);
+ if (!buffer) {
+ return 0;
+ }
+
+ va_start(arg, format);
+ vsnprintf( (char *)buffer->get(), len + 1, format, arg);
+ va_end(arg);
+
+ textAll(buffer);
+ return len;
+}
+
+#ifndef ESP32
+size_t AsyncWebSocket::printf_P(uint32_t id, PGM_P formatP, ...){
+ AsyncWebSocketClient * c = client(id);
+ if(c != NULL){
+ va_list arg;
+ va_start(arg, formatP);
+ size_t len = c->printf_P(formatP, arg);
+ va_end(arg);
+ return len;
+ }
+ return 0;
+}
+#endif
+
+size_t AsyncWebSocket::printfAll_P(PGM_P formatP, ...) {
+ va_list arg;
+ char* temp = new char[MAX_PRINTF_LEN];
+ if(!temp){
+ return 0;
+ }
+ va_start(arg, formatP);
+ size_t len = vsnprintf_P(temp, MAX_PRINTF_LEN, formatP, arg);
+ va_end(arg);
+ delete[] temp;
+
+ AsyncWebSocketMessageBuffer * buffer = makeBuffer(len + 1);
+ if (!buffer) {
+ return 0;
+ }
+
+ va_start(arg, formatP);
+ vsnprintf_P((char *)buffer->get(), len + 1, formatP, arg);
+ va_end(arg);
+
+ textAll(buffer);
+ return len;
+}
+
+void AsyncWebSocket::text(uint32_t id, const char * message){
+ text(id, message, strlen(message));
+}
+void AsyncWebSocket::text(uint32_t id, uint8_t * message, size_t len){
+ text(id, (const char *)message, len);
+}
+void AsyncWebSocket::text(uint32_t id, char * message){
+ text(id, message, strlen(message));
+}
+void AsyncWebSocket::text(uint32_t id, const String &message){
+ text(id, message.c_str(), message.length());
+}
+void AsyncWebSocket::text(uint32_t id, const __FlashStringHelper *message){
+ AsyncWebSocketClient * c = client(id);
+ if(c != NULL)
+ c->text(message);
+}
+void AsyncWebSocket::textAll(const char * message){
+ textAll(message, strlen(message));
+}
+void AsyncWebSocket::textAll(uint8_t * message, size_t len){
+ textAll((const char *)message, len);
+}
+void AsyncWebSocket::textAll(char * message){
+ textAll(message, strlen(message));
+}
+void AsyncWebSocket::textAll(const String &message){
+ textAll(message.c_str(), message.length());
+}
+void AsyncWebSocket::textAll(const __FlashStringHelper *message){
+ for(const auto& c: _clients){
+ if(c->status() == WS_CONNECTED)
+ c->text(message);
+ }
+}
+void AsyncWebSocket::binary(uint32_t id, const char * message){
+ binary(id, message, strlen(message));
+}
+void AsyncWebSocket::binary(uint32_t id, uint8_t * message, size_t len){
+ binary(id, (const char *)message, len);
+}
+void AsyncWebSocket::binary(uint32_t id, char * message){
+ binary(id, message, strlen(message));
+}
+void AsyncWebSocket::binary(uint32_t id, const String &message){
+ binary(id, message.c_str(), message.length());
+}
+void AsyncWebSocket::binary(uint32_t id, const __FlashStringHelper *message, size_t len){
+ AsyncWebSocketClient * c = client(id);
+ if(c != NULL)
+ c-> binary(message, len);
+}
+void AsyncWebSocket::binaryAll(const char * message){
+ binaryAll(message, strlen(message));
+}
+void AsyncWebSocket::binaryAll(uint8_t * message, size_t len){
+ binaryAll((const char *)message, len);
+}
+void AsyncWebSocket::binaryAll(char * message){
+ binaryAll(message, strlen(message));
+}
+void AsyncWebSocket::binaryAll(const String &message){
+ binaryAll(message.c_str(), message.length());
+}
+void AsyncWebSocket::binaryAll(const __FlashStringHelper *message, size_t len){
+ for(const auto& c: _clients){
+ if(c->status() == WS_CONNECTED)
+ c-> binary(message, len);
+ }
+ }
+
+const char * WS_STR_CONNECTION = "Connection";
+const char * WS_STR_UPGRADE = "Upgrade";
+const char * WS_STR_ORIGIN = "Origin";
+const char * WS_STR_VERSION = "Sec-WebSocket-Version";
+const char * WS_STR_KEY = "Sec-WebSocket-Key";
+const char * WS_STR_PROTOCOL = "Sec-WebSocket-Protocol";
+const char * WS_STR_ACCEPT = "Sec-WebSocket-Accept";
+const char * WS_STR_UUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
+
+bool AsyncWebSocket::canHandle(AsyncWebServerRequest *request){
+ if(!_enabled)
+ return false;
+
+ if(request->method() != HTTP_GET || !request->url().equals(_url) || !request->isExpectedRequestedConnType(RCT_WS))
+ return false;
+
+ request->addInterestingHeader(WS_STR_CONNECTION);
+ request->addInterestingHeader(WS_STR_UPGRADE);
+ request->addInterestingHeader(WS_STR_ORIGIN);
+ request->addInterestingHeader(WS_STR_VERSION);
+ request->addInterestingHeader(WS_STR_KEY);
+ request->addInterestingHeader(WS_STR_PROTOCOL);
+ return true;
+}
+
+void AsyncWebSocket::handleRequest(AsyncWebServerRequest *request){
+ if(!request->hasHeader(WS_STR_VERSION) || !request->hasHeader(WS_STR_KEY)){
+ request->send(400);
+ return;
+ }
+ if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())){
+ return request->requestAuthentication();
+ }
+ AsyncWebHeader* version = request->getHeader(WS_STR_VERSION);
+ if(version->value().toInt() != 13){
+ AsyncWebServerResponse *response = request->beginResponse(400);
+ response->addHeader(WS_STR_VERSION,"13");
+ request->send(response);
+ return;
+ }
+ AsyncWebHeader* key = request->getHeader(WS_STR_KEY);
+ AsyncWebServerResponse *response = new AsyncWebSocketResponse(key->value(), this);
+ if(request->hasHeader(WS_STR_PROTOCOL)){
+ AsyncWebHeader* protocol = request->getHeader(WS_STR_PROTOCOL);
+ //ToDo: check protocol
+ response->addHeader(WS_STR_PROTOCOL, protocol->value());
+ }
+ request->send(response);
+}
+
+AsyncWebSocketMessageBuffer * AsyncWebSocket::makeBuffer(size_t size)
+{
+ AsyncWebSocketMessageBuffer * buffer = new AsyncWebSocketMessageBuffer(size);
+ if (buffer) {
+ _buffers.add(buffer);
+ }
+ return buffer;
+}
+
+AsyncWebSocketMessageBuffer * AsyncWebSocket::makeBuffer(uint8_t * data, size_t size)
+{
+ AsyncWebSocketMessageBuffer * buffer = new AsyncWebSocketMessageBuffer(data, size);
+
+ if (buffer) {
+ _buffers.add(buffer);
+ }
+
+ return buffer;
+}
+
+void AsyncWebSocket::_cleanBuffers()
+{
+ for(const auto& c: _buffers){
+ if(c->canDelete())
+ _buffers.remove(c);
+ }
+}
+
+
+/*
+ * Response to Web Socket request - sends the authorization and detaches the TCP Client from the web server
+ * Authentication code from https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.cpp#L480
+ */
+
+AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket *server){
+ _server = server;
+ _code = 101;
+ _sendContentLength = false;
+
+ uint8_t * hash = (uint8_t*)malloc(20);
+ if(hash == NULL){
+ _state = RESPONSE_FAILED;
+ return;
+ }
+ char * buffer = (char *) malloc(33);
+ if(buffer == NULL){
+ free(hash);
+ _state = RESPONSE_FAILED;
+ return;
+ }
+#ifdef ESP8266
+ sha1(key + WS_STR_UUID, hash);
+#else
+ (String&)key += WS_STR_UUID;
+ SHA1_CTX ctx;
+ SHA1Init(&ctx);
+ SHA1Update(&ctx, (const unsigned char*)key.c_str(), key.length());
+ SHA1Final(hash, &ctx);
+#endif
+ base64_encodestate _state;
+ base64_init_encodestate(&_state);
+ int len = base64_encode_block((const char *) hash, 20, buffer, &_state);
+ len = base64_encode_blockend((buffer + len), &_state);
+ addHeader(WS_STR_CONNECTION, WS_STR_UPGRADE);
+ addHeader(WS_STR_UPGRADE, "websocket");
+ addHeader(WS_STR_ACCEPT,buffer);
+ free(buffer);
+ free(hash);
+}
+
+void AsyncWebSocketResponse::_respond(AsyncWebServerRequest *request){
+ if(_state == RESPONSE_FAILED){
+ request->client()->close(true);
+ return;
+ }
+ String out = _assembleHead(request->version());
+ request->client()->write(out.c_str(), _headLength);
+ _state = RESPONSE_WAIT_ACK;
+}
+
+size_t AsyncWebSocketResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time){
+ if(len){
+ new AsyncWebSocketClient(request, _server);
+ }
+ return 0;
+}
diff --git a/libraries/ESPAsyncWebServer/src/AsyncWebSocket.h b/libraries/ESPAsyncWebServer/src/AsyncWebSocket.h
new file mode 100644
index 00000000..5242ba3c
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/src/AsyncWebSocket.h
@@ -0,0 +1,306 @@
+/*
+ Asynchronous WebServer library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#ifndef ASYNCWEBSOCKET_H_
+#define ASYNCWEBSOCKET_H_
+
+#include
+#ifdef ESP32
+#include
+#else
+#include
+#endif
+#include
+
+class AsyncWebSocket;
+class AsyncWebSocketResponse;
+class AsyncWebSocketClient;
+class AsyncWebSocketControl;
+
+typedef struct {
+ uint8_t message_opcode;
+ uint32_t num;
+ uint8_t final;
+ uint8_t masked;
+ uint8_t opcode;
+ uint64_t len;
+ uint8_t mask[4];
+ uint64_t index;
+} AwsFrameInfo;
+
+typedef enum { WS_DISCONNECTED, WS_CONNECTED, WS_DISCONNECTING } AwsClientStatus;
+typedef enum { WS_CONTINUATION, WS_TEXT, WS_BINARY, WS_DISCONNECT = 0x08, WS_PING, WS_PONG } AwsFrameType;
+typedef enum { WS_MSG_SENDING, WS_MSG_SENT, WS_MSG_ERROR } AwsMessageStatus;
+typedef enum { WS_EVT_CONNECT, WS_EVT_DISCONNECT, WS_EVT_PONG, WS_EVT_ERROR, WS_EVT_DATA } AwsEventType;
+
+class AsyncWebSocketMessageBuffer {
+ private:
+ uint8_t * _data;
+ size_t _len;
+ bool _lock;
+ uint32_t _count;
+
+ public:
+ AsyncWebSocketMessageBuffer();
+ AsyncWebSocketMessageBuffer(size_t size);
+ AsyncWebSocketMessageBuffer(uint8_t * data, size_t size);
+ AsyncWebSocketMessageBuffer(const AsyncWebSocketMessageBuffer &);
+ AsyncWebSocketMessageBuffer(AsyncWebSocketMessageBuffer &&);
+ ~AsyncWebSocketMessageBuffer();
+ void operator ++(int i) { _count++; }
+ void operator --(int i) { if (_count > 0) { _count--; } ; }
+ bool reserve(size_t size);
+ void lock() { _lock = true; }
+ void unlock() { _lock = false; }
+ uint8_t * get() { return _data; }
+ size_t length() { return _len; }
+ uint32_t count() { return _count; }
+ bool canDelete() { return (!_count && !_lock); }
+
+ friend AsyncWebSocket;
+
+};
+
+class AsyncWebSocketMessage {
+ protected:
+ uint8_t _opcode;
+ bool _mask;
+ AwsMessageStatus _status;
+ public:
+ AsyncWebSocketMessage():_opcode(WS_TEXT),_mask(false),_status(WS_MSG_ERROR){}
+ virtual ~AsyncWebSocketMessage(){}
+ virtual void ack(size_t len __attribute__((unused)), uint32_t time __attribute__((unused))){}
+ virtual size_t send(AsyncClient *client __attribute__((unused))){ return 0; }
+ virtual bool finished(){ return _status != WS_MSG_SENDING; }
+ virtual bool betweenFrames() const { return false; }
+};
+
+class AsyncWebSocketBasicMessage: public AsyncWebSocketMessage {
+ private:
+ size_t _len;
+ size_t _sent;
+ size_t _ack;
+ size_t _acked;
+ uint8_t * _data;
+public:
+ AsyncWebSocketBasicMessage(const char * data, size_t len, uint8_t opcode=WS_TEXT, bool mask=false);
+ AsyncWebSocketBasicMessage(uint8_t opcode=WS_TEXT, bool mask=false);
+ virtual ~AsyncWebSocketBasicMessage() override;
+ virtual bool betweenFrames() const override { return _acked == _ack; }
+ virtual void ack(size_t len, uint32_t time) override ;
+ virtual size_t send(AsyncClient *client) override ;
+};
+
+class AsyncWebSocketMultiMessage: public AsyncWebSocketMessage {
+ private:
+ uint8_t * _data;
+ size_t _len;
+ size_t _sent;
+ size_t _ack;
+ size_t _acked;
+ AsyncWebSocketMessageBuffer * _WSbuffer;
+public:
+ AsyncWebSocketMultiMessage(AsyncWebSocketMessageBuffer * buffer, uint8_t opcode=WS_TEXT, bool mask=false);
+ virtual ~AsyncWebSocketMultiMessage() override;
+ virtual bool betweenFrames() const override { return _acked == _ack; }
+ virtual void ack(size_t len, uint32_t time) override ;
+ virtual size_t send(AsyncClient *client) override ;
+};
+
+class AsyncWebSocketClient {
+ private:
+ AsyncClient *_client;
+ AsyncWebSocket *_server;
+ uint32_t _clientId;
+ AwsClientStatus _status;
+
+ LinkedList _controlQueue;
+ LinkedList _messageQueue;
+
+ uint8_t _pstate;
+ AwsFrameInfo _pinfo;
+
+ uint32_t _lastMessageTime;
+ uint32_t _keepAlivePeriod;
+
+ void _queueMessage(AsyncWebSocketMessage *dataMessage);
+ void _queueControl(AsyncWebSocketControl *controlMessage);
+ void _runQueue();
+
+ public:
+ void *_tempObject;
+
+ AsyncWebSocketClient(AsyncWebServerRequest *request, AsyncWebSocket *server);
+ ~AsyncWebSocketClient();
+
+ //client id increments for the given server
+ uint32_t id(){ return _clientId; }
+ AwsClientStatus status(){ return _status; }
+ AsyncClient* client(){ return _client; }
+
+ IPAddress remoteIP();
+ uint16_t remotePort();
+
+ //control frames
+ void close(uint16_t code=0, const char * message=NULL);
+ void ping(uint8_t *data=NULL, size_t len=0);
+
+ //set auto-ping period in seconds. disabled if zero (default)
+ void keepAlivePeriod(uint16_t seconds){
+ _keepAlivePeriod = seconds * 1000;
+ }
+ uint16_t keepAlivePeriod(){
+ return (uint16_t)(_keepAlivePeriod / 1000);
+ }
+
+ //data packets
+ void message(AsyncWebSocketMessage *message){ _queueMessage(message); }
+
+ size_t printf(const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+#ifndef ESP32
+ size_t printf_P(PGM_P formatP, ...) __attribute__ ((format (printf, 2, 3)));
+#endif
+ void text(const char * message, size_t len);
+ void text(const char * message);
+ void text(uint8_t * message, size_t len);
+ void text(char * message);
+ void text(const String &message);
+ void text(const __FlashStringHelper *data);
+ void text(AsyncWebSocketMessageBuffer *buffer);
+
+ void binary(const char * message, size_t len);
+ void binary(const char * message);
+ void binary(uint8_t * message, size_t len);
+ void binary(char * message);
+ void binary(const String &message);
+ void binary(const __FlashStringHelper *data, size_t len);
+ void binary(AsyncWebSocketMessageBuffer *buffer);
+
+ //system callbacks (do not call)
+ void _onAck(size_t len, uint32_t time);
+ void _onError(int8_t);
+ void _onPoll();
+ void _onTimeout(uint32_t time);
+ void _onDisconnect();
+ void _onData(void *buf, size_t plen);
+};
+
+typedef std::function AwsEventHandler;
+
+//WebServer Handler implementation that plays the role of a socket server
+class AsyncWebSocket: public AsyncWebHandler {
+ private:
+ String _url;
+ LinkedList _clients;
+ uint32_t _cNextId;
+ AwsEventHandler _eventHandler;
+ bool _enabled;
+ public:
+ AsyncWebSocket(const String& url);
+ ~AsyncWebSocket();
+ const char * url() const { return _url.c_str(); }
+ void enable(bool e){ _enabled = e; }
+ bool enabled() const { return _enabled; }
+
+ size_t count() const;
+ AsyncWebSocketClient * client(uint32_t id);
+ bool hasClient(uint32_t id){ return client(id) != NULL; }
+
+ void close(uint32_t id, uint16_t code=0, const char * message=NULL);
+ void closeAll(uint16_t code=0, const char * message=NULL);
+
+ void ping(uint32_t id, uint8_t *data=NULL, size_t len=0);
+ void pingAll(uint8_t *data=NULL, size_t len=0); // done
+
+ void text(uint32_t id, const char * message, size_t len);
+ void text(uint32_t id, const char * message);
+ void text(uint32_t id, uint8_t * message, size_t len);
+ void text(uint32_t id, char * message);
+ void text(uint32_t id, const String &message);
+ void text(uint32_t id, const __FlashStringHelper *message);
+
+ void textAll(const char * message, size_t len);
+ void textAll(const char * message);
+ void textAll(uint8_t * message, size_t len);
+ void textAll(char * message);
+ void textAll(const String &message);
+ void textAll(const __FlashStringHelper *message); // need to convert
+ void textAll(AsyncWebSocketMessageBuffer * buffer);
+
+ void binary(uint32_t id, const char * message, size_t len);
+ void binary(uint32_t id, const char * message);
+ void binary(uint32_t id, uint8_t * message, size_t len);
+ void binary(uint32_t id, char * message);
+ void binary(uint32_t id, const String &message);
+ void binary(uint32_t id, const __FlashStringHelper *message, size_t len);
+
+ void binaryAll(const char * message, size_t len);
+ void binaryAll(const char * message);
+ void binaryAll(uint8_t * message, size_t len);
+ void binaryAll(char * message);
+ void binaryAll(const String &message);
+ void binaryAll(const __FlashStringHelper *message, size_t len);
+ void binaryAll(AsyncWebSocketMessageBuffer * buffer);
+
+ void message(uint32_t id, AsyncWebSocketMessage *message);
+ void messageAll(AsyncWebSocketMultiMessage *message);
+
+ size_t printf(uint32_t id, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
+ size_t printfAll(const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+#ifndef ESP32
+ size_t printf_P(uint32_t id, PGM_P formatP, ...) __attribute__ ((format (printf, 3, 4)));
+#endif
+ size_t printfAll_P(PGM_P formatP, ...) __attribute__ ((format (printf, 2, 3)));
+
+ //event listener
+ void onEvent(AwsEventHandler handler){
+ _eventHandler = handler;
+ }
+
+ //system callbacks (do not call)
+ uint32_t _getNextId(){ return _cNextId++; }
+ void _addClient(AsyncWebSocketClient * client);
+ void _handleDisconnect(AsyncWebSocketClient * client);
+ void _handleEvent(AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);
+ virtual bool canHandle(AsyncWebServerRequest *request) override final;
+ virtual void handleRequest(AsyncWebServerRequest *request) override final;
+
+
+ // messagebuffer functions/objects.
+ AsyncWebSocketMessageBuffer * makeBuffer(size_t size = 0);
+ AsyncWebSocketMessageBuffer * makeBuffer(uint8_t * data, size_t size);
+ LinkedList _buffers;
+ void _cleanBuffers();
+};
+
+//WebServer response to authenticate the socket and detach the tcp client from the web server request
+class AsyncWebSocketResponse: public AsyncWebServerResponse {
+ private:
+ String _content;
+ AsyncWebSocket *_server;
+ public:
+ AsyncWebSocketResponse(const String& key, AsyncWebSocket *server);
+ void _respond(AsyncWebServerRequest *request);
+ size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
+ bool _sourceValid() const { return true; }
+};
+
+
+#endif /* ASYNCWEBSOCKET_H_ */
diff --git a/libraries/ESPAsyncWebServer/src/ESPAsyncWebServer.h b/libraries/ESPAsyncWebServer/src/ESPAsyncWebServer.h
new file mode 100644
index 00000000..447eb34e
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/src/ESPAsyncWebServer.h
@@ -0,0 +1,448 @@
+/*
+ Asynchronous WebServer library for Espressif MCUs
+
+ Copyright (c) 2016 Hristo Gochkov. All rights reserved.
+ This file is part of the esp8266 core for Arduino environment.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+#ifndef _ESPAsyncWebServer_H_
+#define _ESPAsyncWebServer_H_
+
+#include "Arduino.h"
+
+#include
+#include "FS.h"
+
+#include "StringArray.h"
+
+#ifdef ESP32
+#include
+#include
+#elif defined(ESP8266)
+#include
+#include
+#else
+#error Platform not supported
+#endif
+
+#define DEBUGF(...) //Serial.printf(__VA_ARGS__)
+
+class AsyncWebServer;
+class AsyncWebServerRequest;
+class AsyncWebServerResponse;
+class AsyncWebHeader;
+class AsyncWebParameter;
+class AsyncWebRewrite;
+class AsyncWebHandler;
+class AsyncStaticWebHandler;
+class AsyncCallbackWebHandler;
+class AsyncResponseStream;
+
+typedef enum {
+ HTTP_GET = 0b00000001,
+ HTTP_POST = 0b00000010,
+ HTTP_DELETE = 0b00000100,
+ HTTP_PUT = 0b00001000,
+ HTTP_PATCH = 0b00010000,
+ HTTP_HEAD = 0b00100000,
+ HTTP_OPTIONS = 0b01000000,
+ HTTP_ANY = 0b01111111,
+} WebRequestMethod;
+typedef uint8_t WebRequestMethodComposite;
+typedef std::function ArDisconnectHandler;
+
+/*
+ * PARAMETER :: Chainable object to hold GET/POST and FILE parameters
+ * */
+
+class AsyncWebParameter {
+ private:
+ String _name;
+ String _value;
+ size_t _size;
+ bool _isForm;
+ bool _isFile;
+
+ public:
+
+ AsyncWebParameter(const String& name, const String& value, bool form=false, bool file=false, size_t size=0): _name(name), _value(value), _size(size), _isForm(form), _isFile(file){}
+ const String& name() const { return _name; }
+ const String& value() const { return _value; }
+ size_t size() const { return _size; }
+ bool isPost() const { return _isForm; }
+ bool isFile() const { return _isFile; }
+};
+
+/*
+ * HEADER :: Chainable object to hold the headers
+ * */
+
+class AsyncWebHeader {
+ private:
+ String _name;
+ String _value;
+
+ public:
+ AsyncWebHeader(const String& name, const String& value): _name(name), _value(value){}
+ AsyncWebHeader(const String& data): _name(), _value(){
+ if(!data) return;
+ int index = data.indexOf(':');
+ if (index < 0) return;
+ _name = data.substring(0, index);
+ _value = data.substring(index + 2);
+ }
+ ~AsyncWebHeader(){}
+ const String& name() const { return _name; }
+ const String& value() const { return _value; }
+ String toString() const { return String(_name+": "+_value+"\r\n"); }
+};
+
+/*
+ * REQUEST :: Each incoming Client is wrapped inside a Request and both live together until disconnect
+ * */
+
+typedef enum { RCT_NOT_USED = -1, RCT_DEFAULT = 0, RCT_HTTP, RCT_WS, RCT_EVENT, RCT_MAX } RequestedConnectionType;
+
+typedef std::function AwsResponseFiller;
+typedef std::function AwsTemplateProcessor;
+
+class AsyncWebServerRequest {
+ using File = fs::File;
+ using FS = fs::FS;
+ friend class AsyncWebServer;
+ private:
+ AsyncClient* _client;
+ AsyncWebServer* _server;
+ AsyncWebHandler* _handler;
+ AsyncWebServerResponse* _response;
+ StringArray _interestingHeaders;
+ ArDisconnectHandler _onDisconnectfn;
+ String _temp;
+ uint8_t _parseState;
+
+ uint8_t _version;
+ WebRequestMethodComposite _method;
+ String _url;
+ String _host;
+ String _contentType;
+ String _boundary;
+ String _authorization;
+ RequestedConnectionType _reqconntype;
+ void _removeNotInterestingHeaders();
+ bool _isDigest;
+ bool _isMultipart;
+ bool _isPlainPost;
+ bool _expectingContinue;
+ size_t _contentLength;
+ size_t _parsedLength;
+
+ LinkedList _headers;
+ LinkedList _params;
+
+ uint8_t _multiParseState;
+ uint8_t _boundaryPosition;
+ size_t _itemStartIndex;
+ size_t _itemSize;
+ String _itemName;
+ String _itemFilename;
+ String _itemType;
+ String _itemValue;
+ uint8_t *_itemBuffer;
+ size_t _itemBufferIndex;
+ bool _itemIsFile;
+
+ void _onPoll();
+ void _onAck(size_t len, uint32_t time);
+ void _onError(int8_t error);
+ void _onTimeout(uint32_t time);
+ void _onDisconnect();
+ void _onData(void *buf, size_t len);
+
+ void _addParam(AsyncWebParameter*);
+
+ bool _parseReqHead();
+ bool _parseReqHeader();
+ void _parseLine();
+ void _parsePlainPostChar(uint8_t data);
+ void _parseMultipartPostByte(uint8_t data, bool last);
+ void _addGetParams(const String& params);
+
+ void _handleUploadStart();
+ void _handleUploadByte(uint8_t data, bool last);
+ void _handleUploadEnd();
+
+ public:
+ File _tempFile;
+ void *_tempObject;
+
+ AsyncWebServerRequest(AsyncWebServer*, AsyncClient*);
+ ~AsyncWebServerRequest();
+
+ AsyncClient* client(){ return _client; }
+ uint8_t version() const { return _version; }
+ WebRequestMethodComposite method() const { return _method; }
+ const String& url() const { return _url; }
+ const String& host() const { return _host; }
+ const String& contentType() const { return _contentType; }
+ size_t contentLength() const { return _contentLength; }
+ bool multipart() const { return _isMultipart; }
+ const char * methodToString() const;
+ const char * requestedConnTypeToString() const;
+ RequestedConnectionType requestedConnType() const { return _reqconntype; }
+ bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED, RequestedConnectionType erct3 = RCT_NOT_USED);
+ void onDisconnect (ArDisconnectHandler fn);
+ //hash is the string representation of:
+ // base64(user:pass) for basic or
+ // user:realm:md5(user:realm:pass) for digest
+ bool authenticate(const char * hash);
+ bool authenticate(const char * username, const char * password, const char * realm = NULL, bool passwordIsHash = false);
+ void requestAuthentication(const char * realm = NULL, bool isDigest = true);
+
+ void setHandler(AsyncWebHandler *handler){ _handler = handler; }
+ void addInterestingHeader(const String& name);
+
+ void redirect(const String& url);
+
+ void send(AsyncWebServerResponse *response);
+ void send(int code, const String& contentType=String(), const String& content=String());
+ void send(FS &fs, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
+ void send(File content, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
+ void send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback=nullptr);
+ void send(const String& contentType, size_t len, AwsResponseFiller callback, AwsTemplateProcessor templateCallback=nullptr);
+ void sendChunked(const String& contentType, AwsResponseFiller callback, AwsTemplateProcessor templateCallback=nullptr);
+ void send_P(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback=nullptr);
+ void send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback=nullptr);
+
+ AsyncWebServerResponse *beginResponse(int code, const String& contentType=String(), const String& content=String());
+ AsyncWebServerResponse *beginResponse(FS &fs, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
+ AsyncWebServerResponse *beginResponse(File content, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);
+ AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback=nullptr);
+ AsyncWebServerResponse *beginResponse(const String& contentType, size_t len, AwsResponseFiller callback, AwsTemplateProcessor templateCallback=nullptr);
+ AsyncWebServerResponse *beginChunkedResponse(const String& contentType, AwsResponseFiller callback, AwsTemplateProcessor templateCallback=nullptr);
+ AsyncResponseStream *beginResponseStream(const String& contentType, size_t bufferSize=1460);
+ AsyncWebServerResponse *beginResponse_P(int code, const String& contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback=nullptr);
+ AsyncWebServerResponse *beginResponse_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback=nullptr);
+
+ size_t headers() const; // get header count
+ bool hasHeader(const String& name) const; // check if header exists
+ bool hasHeader(const __FlashStringHelper * data) const; // check if header exists
+
+ AsyncWebHeader* getHeader(const String& name) const;
+ AsyncWebHeader* getHeader(const __FlashStringHelper * data) const;
+ AsyncWebHeader* getHeader(size_t num) const;
+
+ size_t params() const; // get arguments count
+ bool hasParam(const String& name, bool post=false, bool file=false) const;
+ bool hasParam(const __FlashStringHelper * data, bool post=false, bool file=false) const;
+
+ AsyncWebParameter* getParam(const String& name, bool post=false, bool file=false) const;
+ AsyncWebParameter* getParam(const __FlashStringHelper * data, bool post, bool file) const;
+ AsyncWebParameter* getParam(size_t num) const;
+
+ size_t args() const { return params(); } // get arguments count
+ const String& arg(const String& name) const; // get request argument value by name
+ const String& arg(const __FlashStringHelper * data) const; // get request argument value by F(name)
+ const String& arg(size_t i) const; // get request argument value by number
+ const String& argName(size_t i) const; // get request argument name by number
+ bool hasArg(const char* name) const; // check if argument exists
+ bool hasArg(const __FlashStringHelper * data) const; // check if F(argument) exists
+
+ const String& header(const char* name) const;// get request header value by name
+ const String& header(const __FlashStringHelper * data) const;// get request header value by F(name)
+ const String& header(size_t i) const; // get request header value by number
+ const String& headerName(size_t i) const; // get request header name by number
+ String urlDecode(const String& text) const;
+};
+
+/*
+ * FILTER :: Callback to filter AsyncWebRewrite and AsyncWebHandler (done by the Server)
+ * */
+
+typedef std::function ArRequestFilterFunction;
+
+bool ON_STA_FILTER(AsyncWebServerRequest *request);
+
+bool ON_AP_FILTER(AsyncWebServerRequest *request);
+
+/*
+ * REWRITE :: One instance can be handle any Request (done by the Server)
+ * */
+
+class AsyncWebRewrite {
+ protected:
+ String _from;
+ String _toUrl;
+ String _params;
+ ArRequestFilterFunction _filter;
+ public:
+ AsyncWebRewrite(const char* from, const char* to): _from(from), _toUrl(to), _params(String()), _filter(NULL){
+ int index = _toUrl.indexOf('?');
+ if (index > 0) {
+ _params = _toUrl.substring(index +1);
+ _toUrl = _toUrl.substring(0, index);
+ }
+ }
+ AsyncWebRewrite& setFilter(ArRequestFilterFunction fn) { _filter = fn; return *this; }
+ bool filter(AsyncWebServerRequest *request) const { return _filter == NULL || _filter(request); }
+ const String& from(void) const { return _from; }
+ const String& toUrl(void) const { return _toUrl; }
+ const String& params(void) const { return _params; }
+};
+
+/*
+ * HANDLER :: One instance can be attached to any Request (done by the Server)
+ * */
+
+class AsyncWebHandler {
+ protected:
+ ArRequestFilterFunction _filter;
+ String _username;
+ String _password;
+ public:
+ AsyncWebHandler():_username(""), _password(""){}
+ AsyncWebHandler& setFilter(ArRequestFilterFunction fn) { _filter = fn; return *this; }
+ AsyncWebHandler& setAuthentication(const char *username, const char *password){ _username = String(username);_password = String(password); return *this; };
+ bool filter(AsyncWebServerRequest *request){ return _filter == NULL || _filter(request); }
+ virtual ~AsyncWebHandler(){}
+ virtual bool canHandle(AsyncWebServerRequest *request __attribute__((unused))){
+ return false;
+ }
+ virtual void handleRequest(AsyncWebServerRequest *request __attribute__((unused))){}
+ virtual void handleUpload(AsyncWebServerRequest *request __attribute__((unused)), const String& filename __attribute__((unused)), size_t index __attribute__((unused)), uint8_t *data __attribute__((unused)), size_t len __attribute__((unused)), bool final __attribute__((unused))){}
+ virtual void handleBody(AsyncWebServerRequest *request __attribute__((unused)), uint8_t *data __attribute__((unused)), size_t len __attribute__((unused)), size_t index __attribute__((unused)), size_t total __attribute__((unused))){}
+};
+
+/*
+ * RESPONSE :: One instance is created for each Request (attached by the Handler)
+ * */
+
+typedef enum {
+ RESPONSE_SETUP, RESPONSE_HEADERS, RESPONSE_CONTENT, RESPONSE_WAIT_ACK, RESPONSE_END, RESPONSE_FAILED
+} WebResponseState;
+
+class AsyncWebServerResponse {
+ protected:
+ int _code;
+ LinkedList _headers;
+ String _contentType;
+ size_t _contentLength;
+ bool _sendContentLength;
+ bool _chunked;
+ size_t _headLength;
+ size_t _sentLength;
+ size_t _ackedLength;
+ size_t _writtenLength;
+ WebResponseState _state;
+ const char* _responseCodeToString(int code);
+
+ public:
+ AsyncWebServerResponse();
+ virtual ~AsyncWebServerResponse();
+ virtual void setCode(int code);
+ virtual void setContentLength(size_t len);
+ virtual void setContentType(const String& type);
+ virtual void addHeader(const String& name, const String& value);
+ virtual String _assembleHead(uint8_t version);
+ virtual bool _started() const;
+ virtual bool _finished() const;
+ virtual bool _failed() const;
+ virtual bool _sourceValid() const;
+ virtual void _respond(AsyncWebServerRequest *request);
+ virtual size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
+};
+
+/*
+ * SERVER :: One instance
+ * */
+
+typedef std::function ArRequestHandlerFunction;
+typedef std::function ArUploadHandlerFunction;
+typedef std::function ArBodyHandlerFunction;
+
+class AsyncWebServer {
+ protected:
+ AsyncServer _server;
+ LinkedList _rewrites;
+ LinkedList _handlers;
+ AsyncCallbackWebHandler* _catchAllHandler;
+
+ public:
+ AsyncWebServer(uint16_t port);
+ ~AsyncWebServer();
+
+ void begin();
+
+#if ASYNC_TCP_SSL_ENABLED
+ void onSslFileRequest(AcSSlFileHandler cb, void* arg);
+ void beginSecure(const char *cert, const char *private_key_file, const char *password);
+#endif
+
+ AsyncWebRewrite& addRewrite(AsyncWebRewrite* rewrite);
+ bool removeRewrite(AsyncWebRewrite* rewrite);
+ AsyncWebRewrite& rewrite(const char* from, const char* to);
+
+ AsyncWebHandler& addHandler(AsyncWebHandler* handler);
+ bool removeHandler(AsyncWebHandler* handler);
+
+ AsyncCallbackWebHandler& on(const char* uri, ArRequestHandlerFunction onRequest);
+ AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest);
+ AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload);
+ AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody);
+
+ AsyncStaticWebHandler& serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control = NULL);
+
+ void onNotFound(ArRequestHandlerFunction fn); //called when handler is not assigned
+ void onFileUpload(ArUploadHandlerFunction fn); //handle file uploads
+ void onRequestBody(ArBodyHandlerFunction fn); //handle posts with plain body content (JSON often transmitted this way as a request)
+
+ void reset(); //remove all writers and handlers, with onNotFound/onFileUpload/onRequestBody
+
+ void _handleDisconnect(AsyncWebServerRequest *request);
+ void _attachHandler(AsyncWebServerRequest *request);
+ void _rewriteRequest(AsyncWebServerRequest *request);
+};
+
+class DefaultHeaders {
+ using headers_t = LinkedList;
+ headers_t _headers;
+
+ DefaultHeaders()
+ :_headers(headers_t([](AsyncWebHeader *h){ delete h; }))
+ {}
+public:
+ using ConstIterator = headers_t::ConstIterator;
+
+ void addHeader(const String& name, const String& value){
+ _headers.add(new AsyncWebHeader(name, value));
+ }
+
+ ConstIterator begin() const { return _headers.begin(); }
+ ConstIterator end() const { return _headers.end(); }
+
+ DefaultHeaders(DefaultHeaders const &) = delete;
+ DefaultHeaders &operator=(DefaultHeaders const &) = delete;
+ static DefaultHeaders &Instance() {
+ static DefaultHeaders instance;
+ return instance;
+ }
+};
+
+#include "WebResponseImpl.h"
+#include "WebHandlerImpl.h"
+#include "AsyncWebSocket.h"
+#include "AsyncEventSource.h"
+
+#endif /* _AsyncWebServer_H_ */
diff --git a/libraries/ESPAsyncWebServer/src/SPIFFSEditor.cpp b/libraries/ESPAsyncWebServer/src/SPIFFSEditor.cpp
new file mode 100644
index 00000000..a385a974
--- /dev/null
+++ b/libraries/ESPAsyncWebServer/src/SPIFFSEditor.cpp
@@ -0,0 +1,544 @@
+#include "SPIFFSEditor.h"
+#include