diff --git a/.travis.yml b/.travis.yml index 63151dd6..be0c6054 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,7 +46,7 @@ before_script: - cd tools - python get.py - cp -r $TRAVIS_BUILD_DIR/libraries/ESP32SSDP-1.1.0 $HOME/arduino_ide/libraries/ - - cp -r $TRAVIS_BUILD_DIR/libraries/arduinoWebSockets-2.2.0 $HOME/arduino_ide/libraries/ + - cp -r $TRAVIS_BUILD_DIR/libraries/arduinoWebSockets-2.3.0 $HOME/arduino_ide/libraries/ - cp -r $TRAVIS_BUILD_DIR/libraries/DHT_sensor_library_for_ESPx-1.0.6 $HOME/arduino_ide/libraries/ - cp -r $TRAVIS_BUILD_DIR/libraries/esp8266-oled-ssd1306-4.0.0 $HOME/arduino_ide/libraries/ - cp -r $TRAVIS_BUILD_DIR/libraries/TFT_eSPI-1.4.11 $HOME/arduino_ide/libraries/ diff --git a/libraries/arduinoWebSockets-2.2.0/.clang-format b/libraries/arduinoWebSockets-2.3.0/.clang-format similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/.clang-format rename to libraries/arduinoWebSockets-2.3.0/.clang-format diff --git a/libraries/arduinoWebSockets-2.2.0/.gitignore b/libraries/arduinoWebSockets-2.3.0/.gitignore similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/.gitignore rename to libraries/arduinoWebSockets-2.3.0/.gitignore diff --git a/libraries/arduinoWebSockets-2.2.0/.travis.yml b/libraries/arduinoWebSockets-2.3.0/.travis.yml similarity index 84% rename from libraries/arduinoWebSockets-2.2.0/.travis.yml rename to libraries/arduinoWebSockets-2.3.0/.travis.yml index 871c2397..7c59234e 100644 --- a/libraries/arduinoWebSockets-2.2.0/.travis.yml +++ b/libraries/arduinoWebSockets-2.3.0/.travis.yml @@ -10,14 +10,12 @@ os: - linux env: matrix: - - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80" IDE_VERSION=1.6.5 - - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80,dbg=Serial1" IDE_VERSION=1.6.5 - - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80,eesz=1M,FlashMode=qio,FlashFreq=80" IDE_VERSION=1.8.5 - - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80,eesz=1M,FlashMode=qio,FlashFreq=80" IDE_VERSION=1.8.9 - - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80,eesz=1M,FlashMode=qio,FlashFreq=80" IDE_VERSION=1.8.12 + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80" IDE_VERSION=1.6.13 + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80,dbg=Serial1" IDE_VERSION=1.6.13 + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:xtal=80,eesz=1M,FlashMode=qio,FlashFreq=80" IDE_VERSION=1.8.13 - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.5 - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.9 - - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.12 + - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.13 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 - export DISPLAY=:1.0 diff --git a/libraries/arduinoWebSockets-2.2.0/LICENSE b/libraries/arduinoWebSockets-2.3.0/LICENSE similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/LICENSE rename to libraries/arduinoWebSockets-2.3.0/LICENSE diff --git a/libraries/arduinoWebSockets-2.2.0/README.md b/libraries/arduinoWebSockets-2.3.0/README.md similarity index 88% rename from libraries/arduinoWebSockets-2.2.0/README.md rename to libraries/arduinoWebSockets-2.3.0/README.md index 2a499305..fa7eda53 100644 --- a/libraries/arduinoWebSockets-2.2.0/README.md +++ b/libraries/arduinoWebSockets-2.3.0/README.md @@ -1,4 +1,4 @@ -WebSocket Server and Client for Arduino [![Build Status](https://travis-ci.org/Links2004/arduinoWebSockets.svg?branch=master)](https://travis-ci.org/Links2004/arduinoWebSockets) +WebSocket Server and Client for Arduino [![Build Status](https://travis-ci.com/Links2004/arduinoWebSockets.svg?branch=master)](https://travis-ci.com/Links2004/arduinoWebSockets) =========================================== a WebSocket Server and Client for Arduino based on RFC6455. @@ -34,7 +34,9 @@ a WebSocket Server and Client for Arduino based on RFC6455. ###### Note: ###### - version 2.0 and up is not compatible with AVR/ATmega, check ATmega branch. + version 2.0.0 and up is not compatible with AVR/ATmega, check ATmega branch. + + version 2.3.0 has API changes for the ESP8266 BareSSL (may brakes existing code) Arduino for AVR not supports std namespace of c++. @@ -79,10 +81,12 @@ Where `WStype_t type` is defined as: WStype_CONNECTED, WStype_TEXT, WStype_BIN, - WStype_FRAGMENT_TEXT_START, - WStype_FRAGMENT_BIN_START, - WStype_FRAGMENT, - WStype_FRAGMENT_FIN, + WStype_FRAGMENT_TEXT_START, + WStype_FRAGMENT_BIN_START, + WStype_FRAGMENT, + WStype_FRAGMENT_FIN, + WStype_PING, + WStype_PONG, } WStype_t; ``` diff --git a/libraries/arduinoWebSockets-2.2.0/examples/Nginx/esp8266.ssl.reverse.proxy.conf b/libraries/arduinoWebSockets-2.3.0/examples/Nginx/esp8266.ssl.reverse.proxy.conf similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/Nginx/esp8266.ssl.reverse.proxy.conf rename to libraries/arduinoWebSockets-2.3.0/examples/Nginx/esp8266.ssl.reverse.proxy.conf diff --git a/libraries/arduinoWebSockets-2.2.0/examples/avr/WebSocketClientAVR/WebSocketClientAVR.ino b/libraries/arduinoWebSockets-2.3.0/examples/avr/WebSocketClientAVR/WebSocketClientAVR.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/avr/WebSocketClientAVR/WebSocketClientAVR.ino rename to libraries/arduinoWebSockets-2.3.0/examples/avr/WebSocketClientAVR/WebSocketClientAVR.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp32/WebSocketClient/WebSocketClient.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp32/WebSocketClient/WebSocketClient.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp32/WebSocketClient/WebSocketClient.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp32/WebSocketClient/WebSocketClient.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp32/WebSocketServer/WebSocketServer.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp32/WebSocketServer/WebSocketServer.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp32/WebSocketServer/WebSocketServer.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp32/WebSocketServer/WebSocketServer.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClient/WebSocketClient.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClient/WebSocketClient.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClient/WebSocketClient.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClient/WebSocketClient.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSSL/WebSocketClientSSL.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSSL/WebSocketClientSSL.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSSL/WebSocketClientSSL.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSSL/WebSocketClientSSL.ino diff --git a/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSSLWithCA/WebSocketClientSSLWithCA.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSSLWithCA/WebSocketClientSSLWithCA.ino new file mode 100644 index 00000000..72ffae91 --- /dev/null +++ b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSSLWithCA/WebSocketClientSSLWithCA.ino @@ -0,0 +1,99 @@ +/* + * WebSocketClientSSLWithCA.ino + * + * Created on: 27.10.2019 + * + * note SSL is only possible with the ESP8266 + * + */ + +#include + +#include +#include + +#include + +ESP8266WiFiMulti WiFiMulti; +WebSocketsClient webSocket; + +#define USE_SERIAL Serial1 + + +// Can be obtained with: +// openssl s_client -showcerts -connect echo.websocket.org:443 0; t--) { + USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } + + WiFiMulti.addAP("SSID", "passpasspass"); + + while(WiFiMulti.run() != WL_CONNECTED) { + delay(100); + } + + webSocket.beginSslWithCA("echo.websocket.org", 443, "/", ENDPOINT_CA_CERT); + webSocket.onEvent(webSocketEvent); +} + +void loop() { + webSocket.loop(); +} diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino similarity index 98% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino index a952e5de..a97482ea 100644 --- a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino +++ b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino @@ -110,7 +110,7 @@ void loop() { // add payload (parameters) for the event JsonObject param1 = array.createNestedObject(); - param1["now"] = now; + param1["now"] = (uint32_t) now; // JSON to String (serializion) String output; diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSocketIOack/WebSocketClientSocketIOack.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSocketIOack/WebSocketClientSocketIOack.ino similarity index 99% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSocketIOack/WebSocketClientSocketIOack.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSocketIOack/WebSocketClientSocketIOack.ino index bd49ad05..f0f89915 100644 --- a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientSocketIOack/WebSocketClientSocketIOack.ino +++ b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientSocketIOack/WebSocketClientSocketIOack.ino @@ -147,7 +147,7 @@ void loop() { // add payload (parameters) for the event JsonObject param1 = array.createNestedObject(); - param1["now"] = now; + param1["now"] = (uint32_t) now; // JSON to String (serializion) String output; diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientStomp/WebSocketClientStomp.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientStomp/WebSocketClientStomp.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientStomp/WebSocketClientStomp.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientStomp/WebSocketClientStomp.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServer/WebSocketServer.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServer/WebSocketServer.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServer/WebSocketServer.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServer/WebSocketServer.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServerAllFunctionsDemo/WebSocketServerAllFunctionsDemo.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServerAllFunctionsDemo/WebSocketServerAllFunctionsDemo.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServerAllFunctionsDemo/WebSocketServerAllFunctionsDemo.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServerAllFunctionsDemo/WebSocketServerAllFunctionsDemo.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServerFragmentation/WebSocketServerFragmentation.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServerFragmentation/WebSocketServerFragmentation.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServerFragmentation/WebSocketServerFragmentation.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServerFragmentation/WebSocketServerFragmentation.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino b/libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino rename to libraries/arduinoWebSockets-2.3.0/examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino diff --git a/libraries/arduinoWebSockets-2.2.0/examples/particle/ParticleWebSocketClient/application.cpp b/libraries/arduinoWebSockets-2.3.0/examples/particle/ParticleWebSocketClient/application.cpp similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/examples/particle/ParticleWebSocketClient/application.cpp rename to libraries/arduinoWebSockets-2.3.0/examples/particle/ParticleWebSocketClient/application.cpp diff --git a/libraries/arduinoWebSockets-2.2.0/library.json b/libraries/arduinoWebSockets-2.3.0/library.json similarity index 96% rename from libraries/arduinoWebSockets-2.2.0/library.json rename to libraries/arduinoWebSockets-2.3.0/library.json index 9fe38a43..1f372350 100644 --- a/libraries/arduinoWebSockets-2.2.0/library.json +++ b/libraries/arduinoWebSockets-2.3.0/library.json @@ -13,7 +13,7 @@ "type": "git", "url": "https://github.com/Links2004/arduinoWebSockets.git" }, - "version": "2.2.0", + "version": "2.3.0", "license": "LGPL-2.1", "export": { "exclude": [ diff --git a/libraries/arduinoWebSockets-2.2.0/library.properties b/libraries/arduinoWebSockets-2.3.0/library.properties similarity index 94% rename from libraries/arduinoWebSockets-2.2.0/library.properties rename to libraries/arduinoWebSockets-2.3.0/library.properties index 4f18ec8b..130d851e 100644 --- a/libraries/arduinoWebSockets-2.2.0/library.properties +++ b/libraries/arduinoWebSockets-2.3.0/library.properties @@ -1,5 +1,5 @@ name=WebSockets -version=2.2.0 +version=2.3.0 author=Markus Sattler maintainer=Markus Sattler sentence=WebSockets for Arduino (Server + Client) diff --git a/libraries/arduinoWebSockets-2.2.0/src/SocketIOclient.cpp b/libraries/arduinoWebSockets-2.3.0/src/SocketIOclient.cpp similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/SocketIOclient.cpp rename to libraries/arduinoWebSockets-2.3.0/src/SocketIOclient.cpp diff --git a/libraries/arduinoWebSockets-2.2.0/src/SocketIOclient.h b/libraries/arduinoWebSockets-2.3.0/src/SocketIOclient.h similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/SocketIOclient.h rename to libraries/arduinoWebSockets-2.3.0/src/SocketIOclient.h diff --git a/libraries/arduinoWebSockets-2.2.0/src/WebSockets.cpp b/libraries/arduinoWebSockets-2.3.0/src/WebSockets.cpp similarity index 98% rename from libraries/arduinoWebSockets-2.2.0/src/WebSockets.cpp rename to libraries/arduinoWebSockets-2.3.0/src/WebSockets.cpp index 2dc884ec..4840fb92 100644 --- a/libraries/arduinoWebSockets-2.2.0/src/WebSockets.cpp +++ b/libraries/arduinoWebSockets-2.3.0/src/WebSockets.cpp @@ -39,7 +39,14 @@ extern "C" { #ifdef ESP8266 #include #elif defined(ESP32) +#include + +#if ESP_IDF_VERSION_MAJOR >= 4 +#include +#else #include +#endif + #else extern "C" { @@ -494,7 +501,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t reasonCode = payload[0] << 8 | payload[1]; } #endif - DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d", client->num, reasonCode); + DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d\n", client->num, reasonCode); if(header->payloadLen > 2) { DEBUG_WEBSOCKETS(" (%s)\n", (payload + 2)); } else { @@ -503,6 +510,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t clientDisconnect(client, 1000); } break; default: + DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] got unknown opcode: %d\n", client->num, header->opCode); clientDisconnect(client, 1002); break; } @@ -623,7 +631,7 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait } if(!client->tcp->available()) { - WEBSOCKETS_YIELD(); + WEBSOCKETS_YIELD_MORE(); continue; } @@ -636,7 +644,9 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait } else { //DEBUG_WEBSOCKETS("Receive %d left %d!\n", len, n); } - WEBSOCKETS_YIELD(); + if (n > 0) { + WEBSOCKETS_YIELD(); + } } if(cb) { cb(client, true); @@ -686,9 +696,11 @@ size_t WebSockets::write(WSclient_t * client, uint8_t * out, size_t n) { total += len; //DEBUG_WEBSOCKETS("write %d left %d!\n", len, n); } else { - //DEBUG_WEBSOCKETS("write %d failed left %d!\n", len, n); + DEBUG_WEBSOCKETS("WS write %d failed left %d!\n", len, n); + } + if (n > 0) { + WEBSOCKETS_YIELD(); } - WEBSOCKETS_YIELD(); } WEBSOCKETS_YIELD(); return total; diff --git a/libraries/arduinoWebSockets-2.2.0/src/WebSockets.h b/libraries/arduinoWebSockets-2.3.0/src/WebSockets.h similarity index 96% rename from libraries/arduinoWebSockets-2.2.0/src/WebSockets.h rename to libraries/arduinoWebSockets-2.3.0/src/WebSockets.h index aec9f2b6..2c63522c 100644 --- a/libraries/arduinoWebSockets-2.2.0/src/WebSockets.h +++ b/libraries/arduinoWebSockets-2.3.0/src/WebSockets.h @@ -50,8 +50,10 @@ #ifndef DEBUG_WEBSOCKETS #define DEBUG_WEBSOCKETS(...) +#ifndef NODEBUG_WEBSOCKETS #define NODEBUG_WEBSOCKETS #endif +#endif #if defined(ESP8266) || defined(ESP32) @@ -63,8 +65,10 @@ #if defined(ESP8266) #define WEBSOCKETS_YIELD() delay(0) +#define WEBSOCKETS_YIELD_MORE() delay(1) #elif defined(ESP32) #define WEBSOCKETS_YIELD() yield() +#define WEBSOCKETS_YIELD_MORE() delay(1) #endif #elif defined(STM32_DEVICE) @@ -73,7 +77,7 @@ #define WEBSOCKETS_USE_BIG_MEM #define GET_FREE_HEAP System.freeMemory() #define WEBSOCKETS_YIELD() - +#define WEBSOCKETS_YIELD_MORE() #else //atmega328p has only 2KB ram! @@ -81,7 +85,7 @@ // moves all Header strings to Flash #define WEBSOCKETS_SAVE_RAM #define WEBSOCKETS_YIELD() - +#define WEBSOCKETS_YIELD_MORE() #endif #define WEBSOCKETS_TCP_TIMEOUT (5000) @@ -124,6 +128,7 @@ #elif defined(ESP32) #include #include +#define SSL_AXTLS #elif defined(ESP31B) #include #else @@ -143,6 +148,11 @@ #ifdef ESP8266 #include +#if defined(wificlientbearssl_h) && !defined(USING_AXTLS) && !defined(wificlientsecure_h) +#define SSL_BARESSL +#else +#define SSL_AXTLS +#endif #else #include #endif @@ -172,6 +182,7 @@ #include #include +#define SSL_AXTLS #define WEBSOCKETS_NETWORK_CLASS WiFiClient #define WEBSOCKETS_NETWORK_SSL_CLASS WiFiClientSecure #define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer diff --git a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsClient.cpp b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsClient.cpp similarity index 92% rename from libraries/arduinoWebSockets-2.2.0/src/WebSocketsClient.cpp rename to libraries/arduinoWebSockets-2.3.0/src/WebSocketsClient.cpp index 4d3c883d..d4619953 100644 --- a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsClient.cpp +++ b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsClient.cpp @@ -31,6 +31,8 @@ WebSocketsClient::WebSocketsClient() { _client.cIsClient = true; _client.extraHeaders = WEBSOCKETS_STRING("Origin: file://"); _reconnectInterval = 500; + _port = 0; + _host = ""; } WebSocketsClient::~WebSocketsClient() { @@ -44,7 +46,7 @@ void WebSocketsClient::begin(const char * host, uint16_t port, const char * url, _host = host; _port = port; #if defined(HAS_SSL) - _fingerprint = ""; + _fingerprint = SSL_FINGERPRINT_NULL; _CA_cert = NULL; #endif @@ -83,6 +85,7 @@ void WebSocketsClient::begin(const char * host, uint16_t port, const char * url, #endif _lastConnectionFail = 0; + _lastHeaderSent = 0; } void WebSocketsClient::begin(String host, uint16_t port, String url, String protocol) { @@ -94,6 +97,7 @@ void WebSocketsClient::begin(IPAddress host, uint16_t port, const char * url, co } #if defined(HAS_SSL) +#if defined(SSL_AXTLS) void WebSocketsClient::beginSSL(const char * host, uint16_t port, const char * url, const char * fingerprint, const char * protocol) { begin(host, port, url, protocol); _client.isSSL = true; @@ -108,10 +112,31 @@ void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String f void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const char * url, const char * CA_cert, const char * protocol) { begin(host, port, url, protocol); _client.isSSL = true; - _fingerprint = ""; + _fingerprint = SSL_FINGERPRINT_NULL; _CA_cert = CA_cert; } -#endif +#else +void WebSocketsClient::beginSSL(const char * host, uint16_t port, const char * url, const uint8_t * fingerprint, const char * protocol) { + begin(host, port, url, protocol); + _client.isSSL = true; + _fingerprint = fingerprint; + _CA_cert = NULL; +} +void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const char * url, const char * CA_cert, const char * protocol) { + begin(host, port, url, protocol); + _client.isSSL = true; + _fingerprint = SSL_FINGERPRINT_NULL; + _CA_cert = new BearSSL::X509List(CA_cert); +} + +void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const char * url, BearSSL::X509List * CA_cert, const char * protocol) { + begin(host, port, url, protocol); + _client.isSSL = true; + _fingerprint = SSL_FINGERPRINT_NULL; + _CA_cert = CA_cert; +} +#endif // SSL_AXTLS +#endif // HAS_SSL void WebSocketsClient::beginSocketIO(const char * host, uint16_t port, const char * url, const char * protocol) { begin(host, port, url, protocol); @@ -127,7 +152,7 @@ void WebSocketsClient::beginSocketIOSSL(const char * host, uint16_t port, const begin(host, port, url, protocol); _client.isSocketIO = true; _client.isSSL = true; - _fingerprint = ""; + _fingerprint = SSL_FINGERPRINT_NULL; } void WebSocketsClient::beginSocketIOSSL(String host, uint16_t port, String url, String protocol) { @@ -138,8 +163,12 @@ void WebSocketsClient::beginSocketIOSSLWithCA(const char * host, uint16_t port, begin(host, port, url, protocol); _client.isSocketIO = true; _client.isSSL = true; - _fingerprint = ""; - _CA_cert = CA_cert; + _fingerprint = SSL_FINGERPRINT_NULL; +#if defined(SSL_AXTLS) + _CA_cert = CA_cert; +#else + _CA_cert = new BearSSL::X509List(CA_cert); +#endif } #endif @@ -148,6 +177,9 @@ void WebSocketsClient::beginSocketIOSSLWithCA(const char * host, uint16_t port, * called in arduino loop */ void WebSocketsClient::loop(void) { + if(_port == 0) { + return; + } WEBSOCKETS_YIELD(); if(!clientIsConnected(&_client)) { // do not flood the server @@ -169,10 +201,18 @@ void WebSocketsClient::loop(void) { DEBUG_WEBSOCKETS("[WS-Client] setting CA certificate"); #if defined(ESP32) _client.ssl->setCACert(_CA_cert); -#elif defined(ESP8266) +#elif defined(ESP8266) && defined(SSL_AXTLS) _client.ssl->setCACert((const uint8_t *)_CA_cert, strlen(_CA_cert) + 1); +#elif defined(ESP8266) && defined(SSL_BARESSL) + _client.ssl->setTrustAnchors(_CA_cert); #else #error setCACert not implemented +#endif +#if defined(SSL_BARESSL) + } else if(_fingerprint) { + _client.ssl->setFingerprint(_fingerprint); + } else { + _client.ssl->setInsecure(); #endif } } else { @@ -485,6 +525,12 @@ bool WebSocketsClient::clientIsConnected(WSclient_t * client) { * Handel incomming data from Client */ void WebSocketsClient::handleClientData(void) { + if(_client.status == WSC_HEADER && _lastHeaderSent + WEBSOCKETS_TCP_TIMEOUT < millis()) { + DEBUG_WEBSOCKETS("[WS-Client][handleClientData] header response timeout.. disconnecting!\n"); + clientDisconnect(&_client); + WEBSOCKETS_YIELD(); + return; + } int len = _client.tcp->available(); if(len > 0) { switch(_client.status) { @@ -593,6 +639,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { #endif DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%luus).\n", (micros() - start)); + _lastHeaderSent = millis(); } /** @@ -706,6 +753,7 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) { headerDone(client); runCbEvent(WStype_CONNECTED, (uint8_t *)client->cUrl.c_str(), client->cUrl.length()); +#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) } else if(clientIsConnected(client) && client->isSocketIO && client->cSessionId.length() > 0) { if(_client.tcp->available()) { // read not needed data @@ -715,6 +763,7 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) { } } sendHeader(client); +#endif } else { DEBUG_WEBSOCKETS("[WS-Client][handleHeader] no Websocket connection close.\n"); _lastConnectionFail = millis(); @@ -755,14 +804,18 @@ void WebSocketsClient::connectedCb() { #endif #if defined(HAS_SSL) +#if defined(SSL_AXTLS) || defined(ESP32) if(_client.isSSL && _fingerprint.length()) { if(!_client.ssl->verify(_fingerprint.c_str(), _host.c_str())) { DEBUG_WEBSOCKETS("[WS-Client] certificate mismatch\n"); WebSockets::clientDisconnect(&_client, 1000); return; } +#else + if(_client.isSSL && _fingerprint) { +#endif } else if(_client.isSSL && !_CA_cert) { -#if defined(wificlientbearssl_h) && !defined(USING_AXTLS) && !defined(wificlientsecure_h) +#if defined(SSL_BARESSL) _client.ssl->setInsecure(); #endif } diff --git a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsClient.h b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsClient.h similarity index 89% rename from libraries/arduinoWebSockets-2.2.0/src/WebSocketsClient.h rename to libraries/arduinoWebSockets-2.3.0/src/WebSocketsClient.h index b6fe7387..cfa90db3 100644 --- a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsClient.h +++ b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsClient.h @@ -43,8 +43,13 @@ class WebSocketsClient : protected WebSockets { void begin(IPAddress host, uint16_t port, const char * url = "/", const char * protocol = "arduino"); #if defined(HAS_SSL) - void beginSSL(const char * host, uint16_t port, const char * url = "/", const char * = "", const char * protocol = "arduino"); +#ifdef SSL_AXTLS + void beginSSL(const char * host, uint16_t port, const char * url = "/", const char * fingerprint = "", const char * protocol = "arduino"); void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "", String protocol = "arduino"); +#else + void beginSSL(const char * host, uint16_t port, const char * url = "/", const uint8_t * fingerprint = NULL, const char * protocol = "arduino"); + void beginSslWithCA(const char * host, uint16_t port, const char * url = "/", BearSSL::X509List * CA_cert = NULL, const char * protocol = "arduino"); +#endif void beginSslWithCA(const char * host, uint16_t port, const char * url = "/", const char * CA_cert = NULL, const char * protocol = "arduino"); #endif @@ -91,15 +96,23 @@ class WebSocketsClient : protected WebSockets { void enableHeartbeat(uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount); void disableHeartbeat(); + bool isConnected(void); + protected: String _host; uint16_t _port; - bool isConnected(void); - #if defined(HAS_SSL) +#ifdef SSL_AXTLS String _fingerprint; const char * _CA_cert; +#define SSL_FINGERPRINT_NULL "" +#else + const uint8_t * _fingerprint; + BearSSL::X509List * _CA_cert; +#define SSL_FINGERPRINT_NULL NULL +#endif + #endif WSclient_t _client; @@ -107,6 +120,7 @@ class WebSocketsClient : protected WebSockets { unsigned long _lastConnectionFail; unsigned long _reconnectInterval; + unsigned long _lastHeaderSent; void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin); diff --git a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsServer.cpp b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsServer.cpp similarity index 98% rename from libraries/arduinoWebSockets-2.2.0/src/WebSocketsServer.cpp rename to libraries/arduinoWebSockets-2.3.0/src/WebSocketsServer.cpp index f98b0fd3..0e1a593b 100644 --- a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsServer.cpp +++ b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsServer.cpp @@ -419,6 +419,18 @@ int WebSocketsServer::connectedClients(bool ping) { return count; } +/** + * see if one client is connected + * @param num uint8_t client id + */ +bool WebSocketsServer::clientIsConnected(uint8_t num) { + if(num >= WEBSOCKETS_SERVER_CLIENT_MAX) { + return false; + } + WSclient_t * client = &_clients[num]; + return clientIsConnected(client); +} + #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) /** * get an IP for a client @@ -555,7 +567,7 @@ void WebSocketsServer::clientDisconnect(WSclient_t * client) { if(client->tcp) { if(client->tcp->connected()) { -#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) +#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) && (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP32) client->tcp->flush(); #endif client->tcp->stop(); @@ -682,6 +694,7 @@ void WebSocketsServer::handleClientData(void) { WebSockets::handleWebsocket(client); break; default: + DEBUG_WEBSOCKETS("[WS-Server][%d][handleClientData] unknown client status %d\n", client->num, client->status); WebSockets::clientDisconnect(client, 1002); break; } diff --git a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsServer.h b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsServer.h similarity index 99% rename from libraries/arduinoWebSockets-2.2.0/src/WebSocketsServer.h rename to libraries/arduinoWebSockets-2.3.0/src/WebSocketsServer.h index 37243f9a..5784cbd3 100644 --- a/libraries/arduinoWebSockets-2.2.0/src/WebSocketsServer.h +++ b/libraries/arduinoWebSockets-2.3.0/src/WebSocketsServer.h @@ -92,6 +92,8 @@ class WebSocketsServer : protected WebSockets { int connectedClients(bool ping = false); + bool clientIsConnected(uint8_t num); + void enableHeartbeat(uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount); void disableHeartbeat(); diff --git a/libraries/arduinoWebSockets-2.2.0/src/libb64/AUTHORS b/libraries/arduinoWebSockets-2.3.0/src/libb64/AUTHORS similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libb64/AUTHORS rename to libraries/arduinoWebSockets-2.3.0/src/libb64/AUTHORS diff --git a/libraries/arduinoWebSockets-2.2.0/src/libb64/LICENSE b/libraries/arduinoWebSockets-2.3.0/src/libb64/LICENSE similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libb64/LICENSE rename to libraries/arduinoWebSockets-2.3.0/src/libb64/LICENSE diff --git a/libraries/arduinoWebSockets-2.2.0/src/libb64/cdecode.c b/libraries/arduinoWebSockets-2.3.0/src/libb64/cdecode.c similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libb64/cdecode.c rename to libraries/arduinoWebSockets-2.3.0/src/libb64/cdecode.c diff --git a/libraries/arduinoWebSockets-2.2.0/src/libb64/cdecode_inc.h b/libraries/arduinoWebSockets-2.3.0/src/libb64/cdecode_inc.h similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libb64/cdecode_inc.h rename to libraries/arduinoWebSockets-2.3.0/src/libb64/cdecode_inc.h diff --git a/libraries/arduinoWebSockets-2.2.0/src/libb64/cencode.c b/libraries/arduinoWebSockets-2.3.0/src/libb64/cencode.c similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libb64/cencode.c rename to libraries/arduinoWebSockets-2.3.0/src/libb64/cencode.c diff --git a/libraries/arduinoWebSockets-2.2.0/src/libb64/cencode_inc.h b/libraries/arduinoWebSockets-2.3.0/src/libb64/cencode_inc.h similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libb64/cencode_inc.h rename to libraries/arduinoWebSockets-2.3.0/src/libb64/cencode_inc.h diff --git a/libraries/arduinoWebSockets-2.2.0/src/libsha1/libsha1.c b/libraries/arduinoWebSockets-2.3.0/src/libsha1/libsha1.c similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libsha1/libsha1.c rename to libraries/arduinoWebSockets-2.3.0/src/libsha1/libsha1.c diff --git a/libraries/arduinoWebSockets-2.2.0/src/libsha1/libsha1.h b/libraries/arduinoWebSockets-2.3.0/src/libsha1/libsha1.h similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/src/libsha1/libsha1.h rename to libraries/arduinoWebSockets-2.3.0/src/libsha1/libsha1.h diff --git a/libraries/arduinoWebSockets-2.2.0/tests/webSocket.html b/libraries/arduinoWebSockets-2.3.0/tests/webSocket.html similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/tests/webSocket.html rename to libraries/arduinoWebSockets-2.3.0/tests/webSocket.html diff --git a/libraries/arduinoWebSockets-2.2.0/tests/webSocketServer/index.js b/libraries/arduinoWebSockets-2.3.0/tests/webSocketServer/index.js similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/tests/webSocketServer/index.js rename to libraries/arduinoWebSockets-2.3.0/tests/webSocketServer/index.js diff --git a/libraries/arduinoWebSockets-2.2.0/tests/webSocketServer/package.json b/libraries/arduinoWebSockets-2.3.0/tests/webSocketServer/package.json similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/tests/webSocketServer/package.json rename to libraries/arduinoWebSockets-2.3.0/tests/webSocketServer/package.json diff --git a/libraries/arduinoWebSockets-2.2.0/travis/common.sh b/libraries/arduinoWebSockets-2.3.0/travis/common.sh similarity index 100% rename from libraries/arduinoWebSockets-2.2.0/travis/common.sh rename to libraries/arduinoWebSockets-2.3.0/travis/common.sh