WebSockets2_Generic for ESP32, ESP8266, nRF52, SAMD, STM32, Teensy, DUE, W5x00, ENC, NINA, NativeEth. LAN8742A and LAN8720

WebSockets2_Generic

How To Install Using Arduino Library Manager

Why do we need this WebSockets2_Generic

Many Web services require WebSockets library, which is so far written only for ESP8266/ESP32 boards. The ESP boards so far rely on the Markus Sattler’s WebSockets Library to connect to Alexa via Sinric or SinricPro skills.

This WebSockets2_Generic is based on and modified from Gil Maimon’s ArduinoWebSockets Library to provide support to many more boards, such as Arduino SAMD21, Adafruit SAMD21/SAMD51, nRF52, STM32, Teensy, SAM DUE, etc. and enable those boards to use WebSockets services, including voice-control Alexa along with Blynk. Those supported boards can also run WebSockets Server. The WebSockets can be used with ESP’s WiFi, WiFiNINA, W5x00/ENC28J60/LAN8742A Ethernet, ESP8266/ESP32-AT modules/shields.

New in v1.0.2

  1. Add support to Ethernet ENC28J60, using UIPEthernet library. for nRF52, SAMD21/SAMD51 and SAM DUE boards.

New in v1.0.1

  1. Add support to SAM DUE boards.
  2. Add support to Ethernet W5x00, using either Ethernet, EthernetLarge or Ethernet2 library.
  3. Restructure code to provide flexibility to support many more WiFi/Ethernet modules/shields in the future. Please delete the *.cpp files, replaced by *.hpp files, in the src directory, if *.cpp files still exist after installing new version.

New in v1.0.0

  1. Add support to nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc..
  2. Add support to SAMD51 (Itsy-Bitsy M4, Metro M4, Grand Central M4, Feather M4 Express, etc.).
  3. Add support to SAMD21 (ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit CIRCUITPLAYGROUND_EXPRESS, etc.).
  4. Add Alexa / SINRIC examples and supports to those boards as well as ESP8266/ESP32

Supported features of RFC6455

  • text frame
  • binary frame
  • connection close
  • ping
  • pong
  • continuation frame
  1. This is the terminal output when running SAMD-Client_SINRIC example on Nano-33 IoT:
Starting WebSockets2_Generic SAMD-Client_SINRIC with WiFiNINA on SAMD NANO_33_IOT
WiFi-begin: return1 = 3
WiFi-begin: return2 = 3
Connected to Wifi, Connecting to WebSockets Server @iot.sinric.com
[WS] WebsocketsClient::generateHandshake: base64Authorization = ***************
[WS] WebsocketsClient::generateHandshake: handshake = GET / HTTP/1.1
Host: iot.sinric.com
Sec-WebSocket-Key: *********
apikey: 11111111-2222-3333-4444-555555555555
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
User-Agent: TinyWebsockets Client
Authorization: Basic ***************
Origin: https://github.com/khoih-prog/Websockets2_Generic

[WS] WebsocketsClient::generateHandshake: key = Server
[WS] WebsocketsClient::generateHandshake: value = nginx/1.10.3 (Ubuntu)
[WS] WebsocketsClient::generateHandshake: key = Date
[WS] WebsocketsClient::generateHandshake: value = Tue, 14 Jul 2020 02:27:30 GMT
[WS] WebsocketsClient::generateHandshake: key = Connection
[WS] WebsocketsClient::generateHandshake: value = upgrade
[WS] WebsocketsClient::generateHandshake: key = Upgrade
[WS] WebsocketsClient::generateHandshake: value = websocket
[WS] WebsocketsClient::generateHandshake: key = Sec-WebSocket-Accept
[WS] WebsocketsClient::generateHandshake: value = *********
Connected!
Got Message: {"deviceId":"012345678901234567890123","action":"setPowerState","value":"ON"}
Turn on device id: 012345678901234567890123
Got Message: {"deviceId":"012345678901234567890123","action":"setPowerState","value":"OFF"}
Turn off Device ID: 012345678901234567890123
  1. This is terminal debug output when running SAMD-Ethernet-Client_SINRIC on SAMD51 Adafruit Itsy-Bitsy M4 Express using ENC28J60 Ethernet module.
Starting WebSockets2_Generic SAMD-Ethernet-Client_SINRIC on SAMD ADAFRUIT_ITSYBITSY_M4_EXPRESS
Ethernet using ENC28J60 and UIPEthernet Library
[SETUP] BOOT WAIT 4
[SETUP] BOOT WAIT 3
[SETUP] BOOT WAIT 2
[SETUP] BOOT WAIT 1
ENC28J60_CONTROL_CS =16
SS =16
SPI_MOSI =25
SPI_MISO =23
SPI_SCK =24
WebSockets Client IP address: 192.168.2.137
Connecting to WebSockets Server @iot.sinric.com
[WS] WebsocketsClient::generateHandshake: base64Authorization = ********
[WS] WebsocketsClient::generateHandshake: handshake = GET / HTTP/1.1
Host: iot.sinric.com
Sec-WebSocket-Key: ********
apikey: 11111111-2222-3333-4444-555555555555
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
User-Agent: TinyWebsockets Client
Authorization: Basic ********
Origin: https://github.com/khoih-prog/Websockets2_Generic

[WS] WebsocketsClient::connect: base64Authorization = ********
[WS] WebsocketsClient::doestStartsWith: str = HTTP/1.1 101 Switching Protocols

[WS] WebsocketsClient::doestStartsWith: prefix = HTTP/1.1 101
[WS] WebsocketsClient::generateHandshake: key = Server
[WS] WebsocketsClient::generateHandshake: value = nginx/1.10.3 (Ubuntu)
[WS] WebsocketsClient::generateHandshake: key = Date
[WS] WebsocketsClient::generateHandshake: value = Fri, 17 Jul 2020 00:04:17 GMT
[WS] WebsocketsClient::generateHandshake: key = Connection
[WS] WebsocketsClient::generateHandshake: value = upgrade
[WS] WebsocketsClient::generateHandshake: key = Upgrade
[WS] WebsocketsClient::generateHandshake: value = websocket
[WS] WebsocketsClient::generateHandshake: key = Sec-WebSocket-Accept
[WS] WebsocketsClient::generateHandshake: value = ********
Connected!
Got Message: {"deviceId":"012345678901234567890123","action":"setPowerState","value":"ON"}
Turn on device id: 012345678901234567890123
Got Message: {"deviceId":"012345678901234567890123","action":"setPowerState","value":"OFF"}
Turn off Device ID: 012345678901234567890123
  1. This is terminal debug output when running 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.
Starting WebSockets2_Generic nRF52-Ethernet-Server on NRF52840_ITSYBITSY_EXPRESS
Ethernet using ENC28J60 and UIPEthernet Library
[SETUP] BOOT WAIT 4
[SETUP] BOOT WAIT 3
[SETUP] BOOT WAIT 2
[SETUP] BOOT WAIT 1
ENC28J60_CONTROL_CS =10
SS =5
SPI_MOSI =24
SPI_MISO =23
SPI_SCK =25
WebSockets Server Running and Ready on NRF52840_ITSYBITSY_EXPRESS
IP address: 192.168.2.95, Port: 8080
H[WS] WebsocketsServer::recvHandshakeRequest: value = 192.168.2.95
[WS] WebsocketsServer::recvHandshakeRequest: value = ********
[WS] WebsocketsServer::recvHandshakeRequest: value = websocket
[WS] WebsocketsServer::recvHandshakeRequest: value = Upgrade
[WS] WebsocketsServer::recvHandshakeRequest: value = 13
[WS] WebsocketsServer::recvHandshakeRequest: value = TinyWebsockets Client
[WS] WebsocketsServer::recvHandshakeRequest: value = Basic 
[WS] WebsocketsServer::recvHandshakeRequest: value = https://github.com/khoih-prog/Websockets2_Generic
Got Message: Hello to Server from ESP8266
[WS] WebsocketsServer::recvHandshakeRequest: value = 192.168.2.95
[WS] WebsocketsServer::recvHandshakeRequest: value = ********
[WS] WebsocketsServer::recvHandshakeRequest: value = websocket
[WS] WebsocketsServer::recvHandshakeRequest: value = Upgrade
[WS] WebsocketsServer::recvHandshakeRequest: value = 13
[WS] WebsocketsServer::recvHandshakeRequest: value = TinyWebsockets Client
[WS] WebsocketsServer::recvHandshakeRequest: value = Basic 
[WS] WebsocketsServer::recvHandshakeRequest: value = https://github.com/khoih-prog/Websockets2_Generic
Got Message: Hello to Server from ESP8266
HHHHHHHHH

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 and Running Http and Websocket Servers concurrently. Thanks to bug report and persistence of Jake.
  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

|500x203

New in v1.0.5

  1. Sync with ArduinoWebsockets v0.4.18 to fix ESP8266 SSL bug.

New in v1.0.4

  1. Add support to all STM32F/L/H/G/WB/MP1 (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.)
  2. Add support to Seeeduino SAMD21/SAMD51 boards (SEEED_WIO_TERMINAL, SEEED_FEMTO_M0, SEEED_XIAO_M0, Wio_Lite_MG126, WIO_GPS_BOARD, SEEEDUINO_ZERO, SEEEDUINO_LORAWAN, SEEED_GROVE_UI_WIRELESS, etc.)
  3. Add sample Packages_Patches for STM32 stm32 (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8)
  4. Add Packages' Patches for Seeeduino SAMD to enable displaying BOARD_NAME
  5. Add many examples

New in v1.0.3

  1. Add support to STM32F boards with built-in Ethernet such as :
  2. Nucleo-144 (F429ZI, F767ZI)
  3. Discovery (STM32F746G-DISCOVERY)
  4. All STM32F Boards with Built-in Ethernet LAN8742A

  5. Add support to STM32F1,2,3,4,7 boards (with 64+K Flash) using Ethernet W5x00, ENC28J60 or LAN8742A

  6. Add Packages' Patches to Adafruit nRF52, SAMD, Arduino SAMD to enable displaying BOARD_NAME

  7. Enhance examples and update README.md

Major Release v1.1.0

  1. Add support to Teensy using Ethernet libraries such as Ethernet, Ethernet2, Ethernet3, EthernetLarge, EthernetENC, UIPEthernet
  2. Add support to Teensy 4.1 using NativeEthernet library. Thanks to arnoson code posted on ArduinoWebsockets release 0.5.0
  3. Add Version String

New in v1.0.7

  1. Add support to ENC28J60 Ethernet using EthernetENC Library
  2. Add Ethernet Library Patches for UIPEthernet v2.0.9 and Ethernet2
  3. Update Platform.ini to support PlatformIO 5.x owner-based dependency declaration

Release v1.2.2

  1. Add support to new ESP32-C3 boards (Arduino ESP32C3_DEV). Check HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE.

Release v1.2.1

  1. Add support to new ESP32-S2 boards (SparkFun ESP32-S2 Thing Plus; Adafruit Metro ESP32-S2, MagTag 2.9, FunHouse, Feather ESP32-S2 (no PSRAM)). Drop support to UM ProS2
  2. Add HTTP and WebSockets Server support to ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.)

Major Release v1.2.0

  1. Add limited (client-only) support to LAN8720 Ethernet for STM32F4 (F407xx, NUCLEO_F429ZI) and STM32F7 (DISCO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG) boards.
  2. Add LAN8720 examples
  3. Add Packages’ Patches for STM32 to use LAN8720 with STM32Ethernet and LwIP libraries
  4. Update echo.websocket.org fingerprint add CA Certificate for ESP8266 and ESP32. Check Secured-Esp32-Client Example not works on NodeMcu32s (Esp32s) #16
  5. Add limited (client-only) support to ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.)
  6. Update HOWTO Install esp32-s2 core for ESP32-S2 to accomodate Latest esp32 core v1.0.6
  7. Update README to reflect LittleFS_esp32 library has been included in Latest esp32 core v1.0.6 and many steps are not necessary anymore