diff --git a/README.md b/README.md index 71058a22..75e3b9cb 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,13 @@ This [WebSockets2_Generic library](https://github.com/khoih-prog/WebSockets2_Gen --- +### New in v1.0.6 + +1. Add ***non-blocking WebSockets Server*** feature to enable WS Server and WebServer running ***concurently***. See [***Support as Http server and the Websockets server on Arduino DUE***](https://github.com/khoih-prog/WebSockets_Generic/issues/1) and [***Running Http and Websocket Servers concurrently***](https://github.com/khoih-prog/WebSockets2_Generic/issues/1). Thanks to bug report and persistence of [Jake](https://github.com/jakespeed1311). +2. Add non-blocking WebSockets Server and WebServer examples. +3. Add Ethernet Library Patches +4. Add Arduino SAMD Packages_Patches to fix compiler errors when using [Standard Template Library STL](https://en.wikipedia.org/wiki/Standard_Template_Library) + #### New in v1.0.5 1. Sync with [ArduinoWebsockets v0.4.18](https://github.com/gilmaimon/ArduinoWebsockets/releases/tag/0.4.18) to fix ESP8266 SSL bug. See [Secured-Two-Way: Client certificate is not sent if used along with setTrustAnchors](https://github.com/gilmaimon/ArduinoWebsockets/issues/84) @@ -72,22 +79,24 @@ This [WebSockets2_Generic library](https://github.com/khoih-prog/WebSockets2_Gen 2. [`ESP32 core v1.0.4+`](https://github.com/espressif/arduino-esp32/releases) for ESP32 boards. ***Ready*** from v1.0.0. 3. [`ESP8266 core v2.7.3+` for Arduino](https://github.com/esp8266/Arduino#installing-with-boards-manager) for ESP8266 boards. ***Ready*** from v1.0.0. 4. `Arduino AVR core v1.8.2+` for Arduino (Use Arduino Board Manager). - 5. [`Teensy core v1.53+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards. ***Not yet ready*** in v1.0.4. + 5. [`Teensy core v1.53+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards. ***Not yet ready*** in v1.0.6. 6. [`Arduino SAM DUE core v1.6.12+`](https://www.arduino.cc/en/Guide/ArduinoDue) for SAM DUE ARM Cortex-M3 boards. ***Ready*** from v1.0.1. 7. [`Arduino SAMD core v1.8.7+`](https://www.arduino.cc/en/Guide/ArduinoM0) for SAMD ARM Cortex-M0+ boards. ***Ready*** from v1.0.0. 8. [`Adafruit SAMD core v1.6.0+`](https://www.adafruit.com/) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). ***Ready*** from v1.0.0. 9. [`Seeeduino SAMD core 1.7.7+`](https://www.seeedstudio.com/) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). ***Ready*** from v1.0.4. 10. [`Adafruit nRF52 v0.20.5+`](https://www.adafruit.com/) for nRF52 boards such as AdaFruit Feather nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc. ***Ready*** from v1.0.0. -11. [`Arduino Core for STM32 v1.9.0+`](https://github.com/khoih-prog/Arduino_Core_STM32) for STM32 boards. To install go to Arduino IDE, select Boards Manager, search for ***`STM32`***. ***Ready*** from v1.0.3. +11. [`Arduino Core for STM32 v1.9.0+`](https://github.com/khoih-prog/Arduino_Core_STM32) for STM32F/L/H/G/WB/MP1 boards. To install go to Arduino IDE, select Boards Manager, search for ***`STM32`***. ***Ready*** from v1.0.3. 12. [`WiFiNINA_Generic library v1.6.2+`](https://github.com/khoih-prog/WiFiNINA_Generic) if for WiFiNINA. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WiFiNINA_Generic.svg?)](https://www.ardu-badge.com/WiFiNINA_Generic). ***Ready*** from v1.0.0. 13. Depending on which Ethernet module/shield you're using : - [`Ethernet library v2.0.0+`](https://www.arduino.cc/en/Reference/Ethernet) for W5100, W5200 and W5500. ***Ready*** from v1.0.1. - [`Ethernet2 library v1.0.4+`](https://github.com/khoih-prog/Ethernet2) for W5500 (Deprecated, use Arduino Ethernet library). ***Ready*** from v1.0.1. - - [`Ethernet3 library v1.5.3+`](https://github.com/sstaub/Ethernet3) for W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip. ***Not yet ready*** in v1.0.4. + - [`Ethernet3 library v1.5.3+`](https://github.com/sstaub/Ethernet3) for W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip. ***Not yet ready*** in v1.0.6. - [`EthernetLarge library v2.0.0+`](https://github.com/OPEnSLab-OSU/EthernetLarge) for W5100, W5200 and W5500. ***Ready*** from v1.0.1. - [`UIPEthernet library v2.0.8+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. ***Ready*** from v1.0.2. - [`STM32Ethernet library v1.2.0+`](https://github.com/stm32duino/STM32Ethernet) for built-in Ethernet LAN8742A on (Nucleo-144, Discovery). To be used with [`STM32duino_LwIP library v2.1.2+`](https://github.com/stm32duino/LwIP). ***Ready*** from v1.0.3. -14. [`ESP_AT_Lib library v1.0.0+`](https://github.com/khoih-prog/ESP_AT_Lib) if necessary to use ESP8288/ESP32-AT shields. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_AT_Lib.svg?)](https://www.ardu-badge.com/ESP_AT_Lib). ***Not yet ready*** in v1.0.4. +14. [`ESP_AT_Lib library v1.0.0+`](https://github.com/khoih-prog/ESP_AT_Lib) if necessary to use ESP8288/ESP32-AT shields. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_AT_Lib.svg?)](https://www.ardu-badge.com/ESP_AT_Lib). ***Not yet ready*** in v1.0.6. + +--- ## Installation @@ -370,9 +379,71 @@ client.onMessage([&](WebsocketsMessage message) Serial.println(message.data()); }); ``` + +#### Reading WebSockets Client messages using non-blocking mode (new from v1.0.6): + +Using this new feature to enable doing other tasks in the loop(), such as WebServer, control tasks, etc. +Server, using library version before v1.0.6, can only read Client messages in blocking mode. Therefore, the WebSocket Server can't hang, waiting for Client, and block all other tasks from running. + +```c++ + + // You can do some other tasks here, such as WebServer, controlling tasks, etc. + + WebsocketsClient client = SocketsServer.accept(); + + if (client.available()) + { + WebsocketsMessage msg = client.readNonBlocking(); + + // log + Serial.print("Got Message: "); + Serial.println(msg.data()); + + // return echo + client.send("Echo: " + msg.data()); + + // close the connection + client.close(); + } +``` + +Please test using one of these following new examples with v1.0.6 and v1.0.5- to see the blocking effects. Please remember to change in loop() from + +``` +WebsocketsMessage msg = client.readNonBlocking(); +``` + +to + +``` +WebsocketsMessage msg = client.readBlocking(); +``` + +as ***client.readNonBlocking() is a new function in v1.0.6+.*** + +##### For ESP32/ESP8266 + +1. [Esp32-AdvancedWebServer](examples/ESP32/Esp32-Esp32-AdvancedWebServer) using ESP32 +2. [Esp8266-AdvancedWebServer](examples/ESP8266/Esp8266-AdvancedWebServer) using ESP8266 + +##### For WiFiNINA + +3. [SAMD-AdvancedWebServer](examples/Generic/WiFiNINA/SAMD/SAMD-AdvancedWebServer) using Nano-33-IoT +4. [nRF52-AdvancedWebServer](examples/Generic/WiFiNINA/nRF52/nRF52-AdvancedWebServer) using Adafruit nRF52 NRF52840_FEATHER_EXPRESS, NINA_B302_ublox and WiFiNINA W102 module. +5. [STM32-AdvancedWebServer](examples/Generic/WiFiNINA/STM32/STM32-AdvancedWebServer) using STM32 Nucleo-64 L053R8, STM32F4 and WiFiNINA W102 module. + + +##### For W5x00, ENC28J60 or LAN8742A Ethernet + +6. [SAMDUE-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/SAMDUE/SAMDUE-Ethernet_AdvancedWebServer) using SAM DUE and W5100 Ethernet +7. [STM32-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/STM32/STM32-Ethernet_AdvancedWebServer) using STM32F7 Nucleo-144 F676ZI and built-in LAN8742A Ethernet. +8. [SAMD-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/SAMD/SAMD-Ethernet_AdvancedWebServer) using Adafruit SAMD51 Itsy_Bitsy_M4, Seeeduino SAMD21 XIAO_M0 and W5500 Ethernet. +9. [nRF52-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/nRF52/nRF52-Ethernet_AdvancedWebServer) using Adafruit nRF52 NRF52840_FEATHER_EXPRESS, NINA_B302_ublox and W5500 Ethernet. + + --- -### To use WiFiNINA module/shield with WiFiNINA_Generic library +### HOWTO use WiFiNINA module/shield with WiFiNINA_Generic library ```cpp #define WEBSOCKETS_USE_WIFININA true @@ -396,7 +467,7 @@ client.onMessage([&](WebsocketsMessage message)

-1. To use Ethernet `W5x00` module/shield with one of the Ethernet libraries +#### 1. To use Ethernet `W5x00` module/shield with one of the Ethernet libraries ```cpp #define WEBSOCKETS_USE_ETHERNET true @@ -437,7 +508,7 @@ client.onMessage([&](WebsocketsMessage message) #define USE_UIP_ETHERNET false ``` -2. To use Ethernet `ENC28J60` module/shield with `UIPEthernet` library +#### 2. To use Ethernet `ENC28J60` module/shield with `UIPEthernet` library

@@ -453,7 +524,7 @@ client.onMessage([&](WebsocketsMessage message) #define USE_ETHERNET_LARGE_LIB false ``` -3. It's much easier just add to the sketch +#### 3. It's much easier just add to the sketch ```cpp #define WEBSOCKETS_USE_ETHERNET true @@ -464,7 +535,7 @@ client.onMessage([&](WebsocketsMessage message) #define USE_ETHERNET2_LIB false #define USE_ETHERNET_LARGE_LIB false -#define USE_UIP_ETHERNET true +#define USE_UIP_ETHERNET false #if USE_ETHERNET_LIB // Also default to Ethernet library @@ -484,15 +555,21 @@ client.onMessage([&](WebsocketsMessage message) // Default to Ethernet library #include #define ETHERNET_TYPE "W5x00 and Ethernet Library" + #define USE_ETHERNET_LIB true +#endif + +#ifndef USE_THIS_SS_PIN +#define USE_THIS_SS_PIN 10 // For other boards #endif ``` + --- ### For STM32F/L/H/G/WB/MP1 using Ethernet W5x0, ENC28J60 or LAN8742A #### To use Ethernet W5x00 module/shield with Ethernetx library -1. To use Ethernet `W5x00` module/shield with one of the Ethernet libraries +#### 1. To use Ethernet `W5x00` module/shield with one of the Ethernet libraries ```cpp #define WEBSOCKETS_USE_ETHERNET true @@ -538,7 +615,7 @@ client.onMessage([&](WebsocketsMessage message) #define USE_LAN8742A_ETHERNET false ``` -2. To use Ethernet `ENC28J60` module/shield with `UIPEthernet` library +#### 2. To use Ethernet `ENC28J60` module/shield with `UIPEthernet` library ```cpp #define WEBSOCKETS_USE_ETHERNET true @@ -551,7 +628,7 @@ client.onMessage([&](WebsocketsMessage message) #define USE_ETHERNET_LARGE_LIB false ``` -3. To use Ethernet `LAN8742A` built-in module/shield with `STM32Ethernet` library +#### 3. To use Ethernet `LAN8742A` built-in module/shield with `STM32Ethernet` library ```cpp #define WEBSOCKETS_USE_ETHERNET true @@ -564,7 +641,7 @@ client.onMessage([&](WebsocketsMessage message) #define USE_ETHERNET_LARGE_LIB false ``` -4. It's much easier just add to the sketch +#### 4. It's much easier just add to the sketch ```cpp #define WEBSOCKETS_USE_ETHERNET true @@ -594,9 +671,10 @@ client.onMessage([&](WebsocketsMessage message) #include #define ETHERNET_TYPE "ENC28J60 and UIPEthernet Library" #elif USE_LAN8742A_ETHERNET + #define USE_BUILTIN_ETHERNET true #include #include - #define ETHERNET_TYPE "LAN8742A and STM32Ethernet Library" + #define ETHERNET_TYPE "LAN8742A and STM32Ethernet Library" #else // Default to Ethernet library #include @@ -621,6 +699,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [ESP32-Client_SINRIC](examples/ESP32/ESP32-Client_SINRIC) 5. [Esp32-Server](examples/ESP32/Esp32-Server) 6. [Esp32-RepeatingClient](examples/ESP32/Esp32-RepeatingClient) +7. [Esp32-AdvancedWebServer](examples/ESP32/Esp32-Esp32-AdvancedWebServer). New in v1.0.6+ #### For ESP8266 boards @@ -631,6 +710,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 5. [ESP8266-Client_SINRIC](examples/ESP8266/ESP8266-Client_SINRIC) 6. [Esp8266-Server](examples/ESP8266/Esp8266-Server) 7. [Esp8266-RepeatingClient](examples/ESP8266/Esp8266-RepeatingClient) +8. [Esp8266-AdvancedWebServer](examples/ESP8266/Esp8266-AdvancedWebServer). New in v1.0.6+ #### For nRF52 boards using WiFiNINA @@ -640,6 +720,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [nRF52-Server](examples/Generic/WiFiNINA/nRF52/nRF52-Server) 5. [nRF52-RepeatingClient](examples/Generic/WiFiNINA/nRF52/nRF52-RepeatingClient) 6. [nRF52_ServerAllFunctionsDemo](examples/Generic/WiFiNINA/nRF52/nRF52_ServerAllFunctionsDemo) +7. [nRF52-AdvancedWebServer](examples/Generic/WiFiNINA/nRF52/nRF52-AdvancedWebServer). New in v1.0.6+ #### For SAMD21/SAMD51 boards using WiFiNINA @@ -649,6 +730,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [SAMD-Server](examples/Generic/WiFiNINA/SAMD/SAMD-Server) 5. [SAMD-RepeatingClient](examples/Generic/WiFiNINA/SAMD/SAMD-RepeatingClient) 6. [SAMD_ServerAllFunctionsDemo](examples/Generic/WiFiNINA/SAMD/SAMD_ServerAllFunctionsDemo) +7. [SAMD-AdvancedWebServer](examples/Generic/WiFiNINA/SAMD/SAMD-AdvancedWebServer). New in v1.0.6+ #### For STM32F/L/H/G/WB/MP1 boards using WiFiNINA @@ -658,6 +740,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [STM32-Server](examples/Generic/WiFiNINA/STM32/STM32-Server) 5. [STM32-RepeatingClient](examples/Generic/WiFiNINA/STM32/STM32-RepeatingClient) 6. [STM32_ServerAllFunctionsDemo](examples/Generic/WiFiNINA/STM32/STM32_ServerAllFunctionsDemo) +7. [STM32-AdvancedWebServer](examples/Generic/WiFiNINA/STM32/STM32-AdvancedWebServer). New in v1.0.6+ #### For nRF52 boards using Ethernet (W5x00 or ENC28J60) @@ -667,6 +750,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [nRF52-Ethernet-Server](examples/Generic/Ethernet/nRF52/nRF52-Ethernet-Server) 5. [nRF52-Ethernet-RepeatingClient](examples/Generic/Ethernet/nRF52/nRF52-Ethernet-RepeatingClient) 6. [nRF52-Ethernet_ServerAllFunctionsDemo](examples/Generic/Ethernet/nRF52/nRF52-Ethernet_ServerAllFunctionsDemo) +7. [nRF52-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/nRF52/nRF52-Ethernet_AdvancedWebServer). New in v1.0.6+ #### For SAMD21/SAMD51 boards using Ethernet (W5x00 or ENC28J60) @@ -676,6 +760,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [SAMD-Ethernet-Server](examples/Generic/Ethernet/SAMD/SAMD-Ethernet-Server) 5. [SAMD-Ethernet-RepeatingClient](examples/Generic/Ethernet/SAMD/SAMD-Ethernet-RepeatingClient) 6. [SAMD-Ethernet_ServerAllFunctionsDemo](examples/Generic/Ethernet/SAMD/SAMD-Ethernet_ServerAllFunctionsDemo) +7. [SAMD-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/SAMD/SAMD-Ethernet_AdvancedWebServer). New in v1.0.6+ #### For SAM-DUE boards using Ethernet (W5x00 or ENC28J60) @@ -685,6 +770,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [SAMDUE-Ethernet-Server](examples/Generic/Ethernet/SAMDUE/SAMDUE-Ethernet-Server) 5. [SAMDUE-Ethernet-RepeatingClient](examples/Generic/Ethernet/SAMDUE/SAMDUE-Ethernet-RepeatingClient) 6. [SAMDUE-Ethernet_ServerAllFunctionsDemo](examples/Generic/Ethernet/SAMDUE/SAMDUE-Ethernet_ServerAllFunctionsDemo) +7. [SAMDUE-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/SAMDUE/SAMDUE-Ethernet_AdvancedWebServer). New in v1.0.6+ #### For STM32F/L/H/G/WB/MP1 boards using Ethernet (W5x00, ENC28J60 or LAN8742A) @@ -694,6 +780,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec 4. [STM32-Ethernet-Server](examples/Generic/Ethernet/STM32/STM32-Ethernet-Server) 5. [STM32-Ethernet-RepeatingClient](examples/Generic/Ethernet/STM32/STM32-Ethernet-RepeatingClient) 6. [STM32-Ethernet_ServerAllFunctionsDemo](examples/Generic/Ethernet/STM32/STM32-Ethernet_ServerAllFunctionsDemo) +7. [STM32-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/STM32/STM32-Ethernet_AdvancedWebServer). New in v1.0.6+ --- @@ -701,7 +788,7 @@ Default is using `ESP8266/ESP32 native WiFi`. You don't need to do anything spec Please take a look at other examples, as well. -1. File [SAMD-Client_SINRIC.ino](examples/Generic/WiFiNINA/SAMD/SAMD-Client_SINRIC/SAMD-Client_SINRIC.ino) +#### 1. File [SAMD-Client_SINRIC.ino](examples/Generic/WiFiNINA/SAMD/SAMD-Client_SINRIC/SAMD-Client_SINRIC.ino) ```cpp #include "defines.h" @@ -938,7 +1025,7 @@ void loop() } ``` -2. File [defines.h](examples/Generic/WiFiNINA/SAMD/SAMD-Client_SINRIC/defines.h) +#### 2. File [defines.h](examples/Generic/WiFiNINA/SAMD/SAMD-Client_SINRIC/defines.h) ```cpp #ifndef defines_h @@ -1132,14 +1219,14 @@ Turn off Device ID: 012345678901234567890123 ``` --- -## Binary Data +### Binary Data For binary data it is recommended to use `msg.rawData()` which returns a `std::string`, or `msg.c_str()` which returns a `const char*`. The reason is that `msg.data()` returns an Arduino `String`, which is great for Serial printing and very basic memory handling but bad for most binary usages. See [issue #32](https://github.com/gilmaimon/ArduinoWebsockets/issues/32) for further information. -## SSL and WSS Support +### SSL and WSS Support No matter what board you are using, in order to use WSS (websockets over SSL) you need to use ```c++ @@ -1212,6 +1299,7 @@ const char ssl_ca_cert[] PROGMEM = \ client.setCACert(ssl_ca_cert); ``` + --- ### Debug Termimal Output Samples @@ -1264,6 +1352,8 @@ Got Message: {"deviceId":"012345678901234567890123","action":"setPowerState","va Turn off Device ID: 012345678901234567890123 ``` +--- + 2. This is terminal debug output when running [SAMDUE-Ethernet-Server](examples/Generic/Ethernet/SAMDUE/SAMDUE-Ethernet-Server) on ***SAM DUE board with Ethernet W5100 shield using EthernetLarge library***, and receiving WebSockets connection from an ESP8266 board. ``` @@ -1299,6 +1389,8 @@ Got Message: Hello to Server from ESP8266 HHHHHHHHH ``` +--- + 3. This is terminal debug output when running [nRF52-Ethernet-Server](examples/Generic/Ethernet/nRF52/nRF52-Ethernet-Server) on ***Adafruit nRF52840 Itsy-Bitsy Express board with Ethernet ENC28J60 shield using UIPEthernet library***, and receiving WebSockets connection from an ESP8266 board. ``` @@ -1336,6 +1428,8 @@ Got Message: Hello to Server from ESP8266 HHHHHHHHH ``` +--- + 4. This is terminal debug output when running [STM32-Ethernet-Client_SINRIC](examples/Generic/Ethernet/STM32/STM32-Ethernet-Client_SINRIC) on ***Nucleo-144 NUCLEO_F767ZI board with built-in Ethernet LAN8742A using STMEthernet library***. ``` @@ -1378,6 +1472,8 @@ Turn on device id: 012345678901234567890123 Got Message: {"deviceId":"012345678901234567890123","action":"setPowerState","value":"OFF"} Turn off Device ID: 012345678901234567890123 ``` +--- + 5. This is the terminal debug output when running [SAMDUE-Ethernet_ServerAllFunctionsDemo](examples/Generic/Ethernet/SAMDUE/SAMDUE-Ethernet_ServerAllFunctionsDemo) example on ***SAM DUE and W5100 Ethernet***. There are 3 WebSockets Clients connecting to the WebSockets Server: - ESP32 running [Esp32-RepeatingClient](examples/ESP32/Esp32-RepeatingClient) @@ -1443,6 +1539,23 @@ Got Message: Hello to Server from NUCLEO_F767ZI Got Message: Hello to Server from ESP32 ... ``` + +--- + +### Screenshots + +1. This is the screenshot when running [STM32-Ethernet_AdvancedWebServer](examples/Generic/Ethernet/STM32/STM32-Ethernet_AdvancedWebServer) example on ***STM32F7 Nucleo-144 F767ZI and built-in LAN8742A Ethernet*** to demonstrate the new non-blocking feature of WebSockets Server enabling WbServer and WebSockets Server to run concurrently. + +

+ +

+ +2. This is the screenshot when running [SAMD-AdvancedWebServer](examples/Generic/WiFiNINA/SAMD/SAMD-AdvancedWebServer) example on ***Arduino SAMD21 Nano-33-IoT and built-in WiFiNINA*** to demonstrate the new non-blocking feature of WebSockets Server enabling WbServer and WebSockets Server to run concurrently. + +

+ +

+ --- ### Debug @@ -1464,7 +1577,7 @@ Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, chan 1. Support more boards (Teensy, etc.) 2. Support ESP8266/ESP32-AT shields. - 3. Add SSL support to SAMD and nRF52 using WiFiNINA. + 3. Add SSL support to SAMD21/SAMD51 and nRF52 using WiFiNINA. 4. Support more non-compatible Ethernet Libraries such as Ethernet_Shield_W5200, EtherCard, EtherSia 5. Add mDNS features. @@ -1483,9 +1596,17 @@ Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, chan 11. Add support to ***STM32F/L/H/G/WB/MP1.*** 12. Add support to ***Ethernet LAN8742A***, using [`STM32Ethernet library`](https://github.com/stm32duino/STM32Ethernet) and [`STM32duino_LwIP library`](https://github.com/stm32duino/LwIP). 13. Add support to ***Seeeduino SAMD21/SAMD51: LoRaWAN, Zero, Femto M0, XIAO M0, Wio GPS Board, Wio Terminal, Grove UI Wireless, etc.*** +14. Add ***non-blocking WebSockets Server*** feature to enable WS Server and WebServer running ***concurently*** --- +### New in v1.0.6 + +1. Add ***non-blocking WebSockets Server*** feature to enable WS Server and WebServer running ***concurently***. See [***Support as Http server and the Websockets server on Arduino DUE***](https://github.com/khoih-prog/WebSockets_Generic/issues/1) and [***Running Http and Websocket Servers concurrently***](https://github.com/khoih-prog/WebSockets2_Generic/issues/1). Thanks to bug report and persistence of [Jake](https://github.com/jakespeed1311). +2. Add non-blocking WebSockets Server and WebServer examples. +3. Add Ethernet Library Patches +4. Add Arduino SAMD Packages_Patches to fix compiler errors when using [Standard Template Library STL](https://en.wikipedia.org/wiki/Standard_Template_Library) + #### New in v1.0.5 1. Sync with [ArduinoWebsockets v0.4.18](https://github.com/gilmaimon/ArduinoWebsockets/releases/tag/0.4.18) to fix ESP8266 SSL bug. See [Secured-Two-Way: Client certificate is not sent if used along with setTrustAnchors](https://github.com/gilmaimon/ArduinoWebsockets/issues/84) @@ -1544,6 +1665,7 @@ Submit issues to: [WebSockets2_Generic issues](https://github.com/khoih-prog/Web gilmaimon
⭐️⭐️ gilmaimon

tcpipchip
⭐️ tcpipchip

+ jakespeed1311
jakespeed1311

diff --git a/keywords.txt b/keywords.txt index eb0d5762..c636c841 100644 --- a/keywords.txt +++ b/keywords.txt @@ -60,6 +60,7 @@ streamBinary KEYWORD2 end KEYWORD2 setFragmentsPolicy KEYWORD2 getFragmentsPolicy KEYWORD2 +readNonBlocking KEYWORD2 readBlocking KEYWORD2 ping KEYWORD2 pong KEYWORD2 diff --git a/library.json b/library.json index f8894409..9031e629 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "WebSockets2_Generic", - "version": "1.0.5", + "version": "1.0.6", "description": "WebSocket Server and Client for Arduino based on RFC6455, originally designed for ESP8266/ESP32, now modified and ported to run on nRF52, SAMD21/SAMD51, SAM DUE, STM32F/L/H/G/WB/MP1, etc. boards, with WiFiNINA, Ethernet W5x00/ENC28J60/LAN8742A, ESP8266/ESP32-AT modules/shields, as well as SINRIC / Alexa / Google Home", "keywords": "wifi, http, web, server, client, websocket, ethernet, Sinric, Alexa", "authors": [ diff --git a/library.properties b/library.properties index 5e83ffc0..2a6df3b9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WebSockets2_Generic -version=1.0.5 +version=1.0.6 author=Gil Maimon , Khoi Hoang maintainer=Khoi Hoang sentence=A library for writing modern Websockets applications with Arduino. Now support ESP8266, ESP32, nRF52, SAMD21, SAMD51, SAM DUE, STM32F/L/H/G/WB/MP1, etc. boards, with WiFiNINA, Ethernet W5x00/ENC28J60/LAN8742A, ESP8266/ESP32-AT modules/shields, as well as SINRIC / Alexa / Google Home diff --git a/src/Tiny_Websockets_Generic/client.hpp b/src/Tiny_Websockets_Generic/client.hpp index cca3dd3b..928fae91 100644 --- a/src/Tiny_Websockets_Generic/client.hpp +++ b/src/Tiny_Websockets_Generic/client.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _CLIENT_HPP_ @@ -119,6 +120,10 @@ namespace websockets2_generic void setFragmentsPolicy(const FragmentsPolicy newPolicy); FragmentsPolicy getFragmentsPolicy() const; + // KH add in v1.0.6 + WebsocketsMessage readNonBlocking(); + ////// + WebsocketsMessage readBlocking(); bool ping(const WSInterfaceString data = ""); diff --git a/src/Tiny_Websockets_Generic/internals/data_frame.hpp b/src/Tiny_Websockets_Generic/internals/data_frame.hpp index da133e75..58822a26 100644 --- a/src/Tiny_Websockets_Generic/internals/data_frame.hpp +++ b/src/Tiny_Websockets_Generic/internals/data_frame.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/websockets_endpoint.hpp b/src/Tiny_Websockets_Generic/internals/websockets_endpoint.hpp index 9f2ac340..c6b89901 100644 --- a/src/Tiny_Websockets_Generic/internals/websockets_endpoint.hpp +++ b/src/Tiny_Websockets_Generic/internals/websockets_endpoint.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/ws_common.hpp b/src/Tiny_Websockets_Generic/internals/ws_common.hpp index 650ef3b1..f2d9d913 100644 --- a/src/Tiny_Websockets_Generic/internals/ws_common.hpp +++ b/src/Tiny_Websockets_Generic/internals/ws_common.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/ws_common_Ethernet_W5x00.hpp b/src/Tiny_Websockets_Generic/internals/ws_common_Ethernet_W5x00.hpp index b6a98973..46cd5aec 100644 --- a/src/Tiny_Websockets_Generic/internals/ws_common_Ethernet_W5x00.hpp +++ b/src/Tiny_Websockets_Generic/internals/ws_common_Ethernet_W5x00.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/ws_common_LAN8742AEthernet.hpp b/src/Tiny_Websockets_Generic/internals/ws_common_LAN8742AEthernet.hpp index 87b55eb2..d14b42ca 100644 --- a/src/Tiny_Websockets_Generic/internals/ws_common_LAN8742AEthernet.hpp +++ b/src/Tiny_Websockets_Generic/internals/ws_common_LAN8742AEthernet.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/ws_common_UIPEthernet.hpp b/src/Tiny_Websockets_Generic/internals/ws_common_UIPEthernet.hpp index 85b70061..60007919 100644 --- a/src/Tiny_Websockets_Generic/internals/ws_common_UIPEthernet.hpp +++ b/src/Tiny_Websockets_Generic/internals/ws_common_UIPEthernet.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/ws_common_WiFiNINA.hpp b/src/Tiny_Websockets_Generic/internals/ws_common_WiFiNINA.hpp index ee8dcbdf..86563be8 100644 --- a/src/Tiny_Websockets_Generic/internals/ws_common_WiFiNINA.hpp +++ b/src/Tiny_Websockets_Generic/internals/ws_common_WiFiNINA.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/wscrypto/crypto.hpp b/src/Tiny_Websockets_Generic/internals/wscrypto/crypto.hpp index 0227a53f..e0ce3207 100644 --- a/src/Tiny_Websockets_Generic/internals/wscrypto/crypto.hpp +++ b/src/Tiny_Websockets_Generic/internals/wscrypto/crypto.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/internals/wscrypto/sha1.hpp b/src/Tiny_Websockets_Generic/internals/wscrypto/sha1.hpp index 4ab60da7..155948a6 100644 --- a/src/Tiny_Websockets_Generic/internals/wscrypto/sha1.hpp +++ b/src/Tiny_Websockets_Generic/internals/wscrypto/sha1.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/message.hpp b/src/Tiny_Websockets_Generic/message.hpp index bfda95da..cbdb297a 100644 --- a/src/Tiny_Websockets_Generic/message.hpp +++ b/src/Tiny_Websockets_Generic/message.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _MESSAGE_HPP_ diff --git a/src/Tiny_Websockets_Generic/network/DUE_Ethernet_W5x00/DUE_Ethernet_W5x00_tcp.hpp b/src/Tiny_Websockets_Generic/network/DUE_Ethernet_W5x00/DUE_Ethernet_W5x00_tcp.hpp index 6620da3e..f97a5b53 100644 --- a/src/Tiny_Websockets_Generic/network/DUE_Ethernet_W5x00/DUE_Ethernet_W5x00_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/DUE_Ethernet_W5x00/DUE_Ethernet_W5x00_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -122,15 +123,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/DUE_UIPEthernet/DUE_UIPEthernet_tcp.hpp b/src/Tiny_Websockets_Generic/network/DUE_UIPEthernet/DUE_UIPEthernet_tcp.hpp index e09a74ce..2b4e4db5 100644 --- a/src/Tiny_Websockets_Generic/network/DUE_UIPEthernet/DUE_UIPEthernet_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/DUE_UIPEthernet/DUE_UIPEthernet_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -118,15 +119,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/SAMD_Ethernet_W5x00/SAMD_Ethernet_W5x00_tcp.hpp b/src/Tiny_Websockets_Generic/network/SAMD_Ethernet_W5x00/SAMD_Ethernet_W5x00_tcp.hpp index 54582806..a0557b19 100644 --- a/src/Tiny_Websockets_Generic/network/SAMD_Ethernet_W5x00/SAMD_Ethernet_W5x00_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/SAMD_Ethernet_W5x00/SAMD_Ethernet_W5x00_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -126,15 +127,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/SAMD_UIPEthernet/SAMD_UIPEthernet_tcp.hpp b/src/Tiny_Websockets_Generic/network/SAMD_UIPEthernet/SAMD_UIPEthernet_tcp.hpp index 85b37154..90b63ef5 100644 --- a/src/Tiny_Websockets_Generic/network/SAMD_UIPEthernet/SAMD_UIPEthernet_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/SAMD_UIPEthernet/SAMD_UIPEthernet_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -122,15 +123,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/SAMD_WiFiNINA/SAMD_WiFiNINA_tcp.hpp b/src/Tiny_Websockets_Generic/network/SAMD_WiFiNINA/SAMD_WiFiNINA_tcp.hpp index 1f9f8639..25a0bf76 100644 --- a/src/Tiny_Websockets_Generic/network/SAMD_WiFiNINA/SAMD_WiFiNINA_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/SAMD_WiFiNINA/SAMD_WiFiNINA_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -107,20 +108,29 @@ namespace websockets2_generic ////// return available(); } - + TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new WiFiNINATcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new WiFiNINATcpClient; } - + bool available() override { yield(); diff --git a/src/Tiny_Websockets_Generic/network/STM32_Ethernet_W5x00/STM32_Ethernet_W5x00_tcp.hpp b/src/Tiny_Websockets_Generic/network/STM32_Ethernet_W5x00/STM32_Ethernet_W5x00_tcp.hpp index 92097f2d..e4f2732f 100644 --- a/src/Tiny_Websockets_Generic/network/STM32_Ethernet_W5x00/STM32_Ethernet_W5x00_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/STM32_Ethernet_W5x00/STM32_Ethernet_W5x00_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -123,15 +124,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/STM32_LAN8742AEthernet/STM32_LAN8742AEthernet_tcp.hpp b/src/Tiny_Websockets_Generic/network/STM32_LAN8742AEthernet/STM32_LAN8742AEthernet_tcp.hpp index 93533092..15cea96a 100644 --- a/src/Tiny_Websockets_Generic/network/STM32_LAN8742AEthernet/STM32_LAN8742AEthernet_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/STM32_LAN8742AEthernet/STM32_LAN8742AEthernet_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -119,15 +120,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/STM32_UIPEthernet/STM32_UIPEthernet_tcp.hpp b/src/Tiny_Websockets_Generic/network/STM32_UIPEthernet/STM32_UIPEthernet_tcp.hpp index 9d77a364..da7f09dd 100644 --- a/src/Tiny_Websockets_Generic/network/STM32_UIPEthernet/STM32_UIPEthernet_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/STM32_UIPEthernet/STM32_UIPEthernet_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -117,20 +118,29 @@ namespace websockets2_generic ////// return available(); } - + TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } - + bool available() override { yield(); diff --git a/src/Tiny_Websockets_Generic/network/STM32_WiFiNINA/STM32_WiFiNINA_tcp.hpp b/src/Tiny_Websockets_Generic/network/STM32_WiFiNINA/STM32_WiFiNINA_tcp.hpp index b72e21e5..fc9c1fca 100644 --- a/src/Tiny_Websockets_Generic/network/STM32_WiFiNINA/STM32_WiFiNINA_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/STM32_WiFiNINA/STM32_WiFiNINA_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -107,15 +108,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new WiFiNINATcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new WiFiNINATcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/esp32/esp32_tcp.hpp b/src/Tiny_Websockets_Generic/network/esp32/esp32_tcp.hpp index e392401b..161fbc88 100644 --- a/src/Tiny_Websockets_Generic/network/esp32/esp32_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/esp32/esp32_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -79,7 +80,7 @@ namespace websockets2_generic server.begin(port); return available(); } - + TcpClient* accept() override { while (available()) @@ -90,7 +91,14 @@ namespace websockets2_generic { return new Esp32TcpClient{client}; } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new Esp32TcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/esp8266/esp8266_tcp.hpp b/src/Tiny_Websockets_Generic/network/esp8266/esp8266_tcp.hpp index ba3ccead..ed6a7bc6 100644 --- a/src/Tiny_Websockets_Generic/network/esp8266/esp8266_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/esp8266/esp8266_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -97,7 +98,7 @@ namespace websockets2_generic server.begin(port); return available(); } - + TcpClient* accept() override { while (available()) @@ -106,8 +107,17 @@ namespace websockets2_generic auto client = server.available(); if (client) + { return new Esp8266TcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new Esp8266TcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/generic_esp/generic_esp_clients.hpp b/src/Tiny_Websockets_Generic/network/generic_esp/generic_esp_clients.hpp index 26da9788..01c38277 100644 --- a/src/Tiny_Websockets_Generic/network/generic_esp/generic_esp_clients.hpp +++ b/src/Tiny_Websockets_Generic/network/generic_esp/generic_esp_clients.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/network/linux/linux_tcp_client.hpp b/src/Tiny_Websockets_Generic/network/linux/linux_tcp_client.hpp index b127ff0a..38a3b904 100644 --- a/src/Tiny_Websockets_Generic/network/linux/linux_tcp_client.hpp +++ b/src/Tiny_Websockets_Generic/network/linux/linux_tcp_client.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/network/linux/linux_tcp_server.hpp b/src/Tiny_Websockets_Generic/network/linux/linux_tcp_server.hpp index f931d675..9c686acd 100644 --- a/src/Tiny_Websockets_Generic/network/linux/linux_tcp_server.hpp +++ b/src/Tiny_Websockets_Generic/network/linux/linux_tcp_server.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/network/nRF52_Ethernet_W5x00/nRF52_Ethernet_W5x00_tcp.hpp b/src/Tiny_Websockets_Generic/network/nRF52_Ethernet_W5x00/nRF52_Ethernet_W5x00_tcp.hpp index ee44d34f..f6e3720c 100644 --- a/src/Tiny_Websockets_Generic/network/nRF52_Ethernet_W5x00/nRF52_Ethernet_W5x00_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/nRF52_Ethernet_W5x00/nRF52_Ethernet_W5x00_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,14 +21,13 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. - *****************************************************************************************************************************/ + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once #if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) - #include #include @@ -124,15 +123,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/nRF52_UIPEthernet/nRF52_UIPEthernet_tcp.hpp b/src/Tiny_Websockets_Generic/network/nRF52_UIPEthernet/nRF52_UIPEthernet_tcp.hpp index adfdea3e..71011ac2 100644 --- a/src/Tiny_Websockets_Generic/network/nRF52_UIPEthernet/nRF52_UIPEthernet_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/nRF52_UIPEthernet/nRF52_UIPEthernet_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -120,15 +121,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new EthernetTcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new EthernetTcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/nRF52_WiFiNINA/nRF52_WiFiNINA_tcp.hpp b/src/Tiny_Websockets_Generic/network/nRF52_WiFiNINA/nRF52_WiFiNINA_tcp.hpp index 76f41812..3235e455 100644 --- a/src/Tiny_Websockets_Generic/network/nRF52_WiFiNINA/nRF52_WiFiNINA_tcp.hpp +++ b/src/Tiny_Websockets_Generic/network/nRF52_WiFiNINA/nRF52_WiFiNINA_tcp.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once @@ -107,15 +108,24 @@ namespace websockets2_generic } TcpClient* accept() override - { + { while (available()) { yield(); auto client = server.available(); - if (client) + if (client) + { return new WiFiNINATcpClient{client}; + } + // KH, from v1.0.6, add to enable non-blocking when no WS Client + else + { + // Return NULL Client. Remember to test for NULL and process correctly + return NULL; + } } + return new WiFiNINATcpClient; } diff --git a/src/Tiny_Websockets_Generic/network/tcp_client.hpp b/src/Tiny_Websockets_Generic/network/tcp_client.hpp index 975a4445..6a0e9610 100644 --- a/src/Tiny_Websockets_Generic/network/tcp_client.hpp +++ b/src/Tiny_Websockets_Generic/network/tcp_client.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/network/tcp_server.hpp b/src/Tiny_Websockets_Generic/network/tcp_server.hpp index bce3adc2..b339d06d 100644 --- a/src/Tiny_Websockets_Generic/network/tcp_server.hpp +++ b/src/Tiny_Websockets_Generic/network/tcp_server.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/network/tcp_socket.hpp b/src/Tiny_Websockets_Generic/network/tcp_socket.hpp index 5aaefeb2..45689fa8 100644 --- a/src/Tiny_Websockets_Generic/network/tcp_socket.hpp +++ b/src/Tiny_Websockets_Generic/network/tcp_socket.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,10 +21,15 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once +// KH add v1.0.6 +#include "WebSockets2_Generic_Debug.h" +////// + #include namespace websockets2_generic diff --git a/src/Tiny_Websockets_Generic/network/windows/win_tcp_client.hpp b/src/Tiny_Websockets_Generic/network/windows/win_tcp_client.hpp index 38a28b30..9a612f42 100644 --- a/src/Tiny_Websockets_Generic/network/windows/win_tcp_client.hpp +++ b/src/Tiny_Websockets_Generic/network/windows/win_tcp_client.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/network/windows/win_tcp_server.hpp b/src/Tiny_Websockets_Generic/network/windows/win_tcp_server.hpp index 1094cb71..47fecdfa 100644 --- a/src/Tiny_Websockets_Generic/network/windows/win_tcp_server.hpp +++ b/src/Tiny_Websockets_Generic/network/windows/win_tcp_server.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/Tiny_Websockets_Generic/server.hpp b/src/Tiny_Websockets_Generic/server.hpp index 11ff0a2d..5565dbdc 100644 --- a/src/Tiny_Websockets_Generic/server.hpp +++ b/src/Tiny_Websockets_Generic/server.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _SERVER_HPP_ diff --git a/src/Tiny_Websockets_Generic/ws_config_defs.hpp b/src/Tiny_Websockets_Generic/ws_config_defs.hpp index a2848d4b..56bc73d9 100644 --- a/src/Tiny_Websockets_Generic/ws_config_defs.hpp +++ b/src/Tiny_Websockets_Generic/ws_config_defs.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #pragma once diff --git a/src/WebSockets2_Generic.h b/src/WebSockets2_Generic.h index 25489e50..3f041025 100644 --- a/src/WebSockets2_Generic.h +++ b/src/WebSockets2_Generic.h @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,7 +20,8 @@ 1.0.3 K Hoang 18/07/2020 Add support to STM32F boards using Ethernet W5x00, ENC28J60 and LAN8742A 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. - 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _WEBSOCKETS2_GENERIC_H diff --git a/src/WebSockets2_Generic_Client.hpp b/src/WebSockets2_Generic_Client.hpp index 34f53960..b7bc366f 100644 --- a/src/WebSockets2_Generic_Client.hpp +++ b/src/WebSockets2_Generic_Client.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,7 +20,8 @@ 1.0.3 K Hoang 18/07/2020 Add support to STM32F boards using Ethernet W5x00, ENC28J60 and LAN8742A 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. - 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _WEBSOCKETS2_GENERIC_CLIENT_H @@ -707,6 +708,18 @@ namespace websockets2_generic return messageReceived; } + // KH add in v1.0.6 + WebsocketsMessage WebsocketsClient::readNonBlocking() + { + auto msg = _endpoint.recv(); + + if (!msg.isEmpty()) + return msg; + else + return {}; + } + ////// + WebsocketsMessage WebsocketsClient::readBlocking() { while (available()) diff --git a/src/WebSockets2_Generic_Common.hpp b/src/WebSockets2_Generic_Common.hpp index d2da920a..55b569a0 100644 --- a/src/WebSockets2_Generic_Common.hpp +++ b/src/WebSockets2_Generic_Common.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _WEBSOCKETS2_GENERIC_COMMON_H diff --git a/src/WebSockets2_Generic_Crypto.hpp b/src/WebSockets2_Generic_Crypto.hpp index 9bdbcaaf..db7683e5 100644 --- a/src/WebSockets2_Generic_Crypto.hpp +++ b/src/WebSockets2_Generic_Crypto.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _WEBSOCKETS2_GENERIC_CRYPTO_H diff --git a/src/WebSockets2_Generic_Debug.h b/src/WebSockets2_Generic_Debug.h index f59e2734..ef6bf132 100644 --- a/src/WebSockets2_Generic_Debug.h +++ b/src/WebSockets2_Generic_Debug.h @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef WebSockets2_Generic_Debug_h diff --git a/src/WebSockets2_Generic_Endpoint.hpp b/src/WebSockets2_Generic_Endpoint.hpp index fe138988..933ad172 100644 --- a/src/WebSockets2_Generic_Endpoint.hpp +++ b/src/WebSockets2_Generic_Endpoint.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _WEBSOCKETS2_GENERIC_ENDPOINT_H diff --git a/src/WebSockets2_Generic_Message.hpp b/src/WebSockets2_Generic_Message.hpp index e7a5f945..faf79f9e 100644 --- a/src/WebSockets2_Generic_Message.hpp +++ b/src/WebSockets2_Generic_Message.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _WEBSOCKETS2_GENERIC_MESSAGE_H diff --git a/src/WebSockets2_Generic_Server.hpp b/src/WebSockets2_Generic_Server.hpp index 6d34b190..19f16f48 100644 --- a/src/WebSockets2_Generic_Server.hpp +++ b/src/WebSockets2_Generic_Server.hpp @@ -10,7 +10,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Websockets2_Generic Licensed under MIT license - Version: 1.0.5 + Version: 1.0.6 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,7 @@ 1.0.4 K Hoang 27/07/2020 Add support to STM32F/L/H/G/WB/MP1 and Seeeduino SAMD21/SAMD51 using Ethernet W5x00, ENC28J60, LAN8742A and WiFiNINA. Add examples and Packages' Patches. 1.0.5 K Hoang 29/07/2020 Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug. + 1.0.6 K Hoang 06/08/2020 Add non-blocking WebSocketsServer feature and non-blocking examples. *****************************************************************************************************************************/ #ifndef _WEBSOCKETS2_GENERIC_SERVER_H @@ -109,9 +110,16 @@ namespace websockets2_generic } WebsocketsClient WebsocketsServer::accept() - { + { std::shared_ptr tcpClient(_server->accept()); + // KH add v1.0.6 + if (!tcpClient) + { + return {}; + } + ////// + if (tcpClient->available() == false) { // KH