The use of the ESP8266 in the world of IoT

User avatar
By khoih-prog
#87940 url=https://github.com/khoih-prog/WebSockets2_Generic]WebSockets2_Generic[/url]

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. Example code ESP8266-Client_SINRIC

2. This is the terminal output when running ESP8266-Client_SINRIC example on NodeMCU:

Code: Select allStarting WebSockets2_Generic ESP8266-Client_SINRIC on ESP8266
......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::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 = Thu, 16 Jul 2020 21:42:29 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