mirror of
				https://github.com/luc-github/ESP3D.git
				synced 2025-10-24 11:50:52 -07:00 
			
		
		
		
	Update WebSocket library
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/ci/prepare-libs.sh
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/ci/prepare-libs.sh
									
									
									
									
										vendored
									
									
								
							| @@ -7,7 +7,7 @@ ls $HOME | ||||
| # Make sure we are inside the github workspace | ||||
| cd $GITHUB_WORKSPACE | ||||
| cp -r ./libraries/ESP32SSDP-2.0.2 $HOME/arduino_ide/libraries/ | ||||
| cp -r ./libraries/arduinoWebSockets-2.5.2 $HOME/arduino_ide/libraries/ | ||||
| cp -r ./libraries/arduinoWebSockets-2.6.1 $HOME/arduino_ide/libraries/ | ||||
| cp -r ./libraries/DHT_sensor_library_for_ESPx-1.0.6 $HOME/arduino_ide/libraries/ | ||||
| cp -r ./libraries/esp8266-oled-ssd1306-4.3.0 $HOME/arduino_ide/libraries/ | ||||
| cp -r ./libraries/TFT_eSPI-2.5.43 $HOME/arduino_ide/libraries/ | ||||
|   | ||||
| @@ -129,6 +129,7 @@ | ||||
| // TYPE_ETH_PHY_DM9051 | ||||
| // TYPE_ETH_PHY_KSZ8041 | ||||
| // TYPE_ETH_PHY_KSZ8081 | ||||
| // TYPE_ETH_PHY_W5500 | ||||
| #define ESP3D_ETH_PHY_TYPE TYPE_ETH_PHY_LAN8720 | ||||
|  | ||||
| // Ethernet board Clock mode | ||||
|   | ||||
							
								
								
									
										11
									
								
								libraries/arduinoWebSockets-2.6.1/.github/dependabot.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								libraries/arduinoWebSockets-2.6.1/.github/dependabot.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # To get started with Dependabot version updates, you'll need to specify which | ||||
| # package ecosystems to update and where the package manifests are located. | ||||
| # Please see the documentation for all configuration options: | ||||
| # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||||
|  | ||||
| version: 2 | ||||
| updates: | ||||
|   - package-ecosystem: "github-actions" | ||||
|     directory: "/" | ||||
|     schedule: | ||||
|       interval: "weekly" | ||||
							
								
								
									
										10
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/arduino-lint.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/arduino-lint.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| name: Arduino library compliance (Lint) | ||||
| on: [push, pull_request] | ||||
| jobs: | ||||
|   lint: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - uses: actions/checkout@v4 | ||||
|       - uses: arduino/arduino-lint-action@v1 | ||||
|         with: | ||||
|           library-manager: update | ||||
							
								
								
									
										69
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/compile-arduino_wifinina-examples.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/compile-arduino_wifinina-examples.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| name: Compile Arduino WiFiNINA Examples | ||||
|  | ||||
| # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows | ||||
| on: | ||||
|   push: | ||||
|     paths: | ||||
|       - ".github/workflows/compile-arduino_wifinina-examples.yaml" | ||||
|       - "examples/arduino_wifinina/**" | ||||
|       - "src/**" | ||||
|   pull_request: | ||||
|     paths: | ||||
|       - ".github/workflows/compile-arduino_wifinina-examples.yaml" | ||||
|       - "examples/arduino_wifinina/**" | ||||
|       - "src/**" | ||||
|   schedule: | ||||
|     # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). | ||||
|     - cron: "0 8 * * TUE" | ||||
|   workflow_dispatch: | ||||
|   repository_dispatch: | ||||
|  | ||||
| jobs: | ||||
|   build: | ||||
|     name: ${{ matrix.board.fqbn }} | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     env: | ||||
|       SKETCHES_REPORTS_PATH: sketches-reports | ||||
|  | ||||
|     strategy: | ||||
|       fail-fast: false | ||||
|  | ||||
|       matrix: | ||||
|         board: | ||||
|           - fqbn: arduino:samd:mkrwifi1010 | ||||
|             platforms: | | ||||
|               - name: arduino:samd | ||||
|             artifact-name-suffix: arduino-samd-mkrwifi1010 | ||||
|             libraries: | | ||||
|               - name: WiFiNINA | ||||
|           - fqbn: arduino:samd:nano_33_iot | ||||
|             platforms: | | ||||
|               - name: arduino:samd | ||||
|             artifact-name-suffix: arduino-samd-nano_33_iot | ||||
|             libraries: | | ||||
|               - name: WiFiNINA | ||||
|     steps: | ||||
|       - name: Checkout repository | ||||
|         uses: actions/checkout@v4 | ||||
|  | ||||
|       - name: Compile examples | ||||
|         uses: arduino/compile-sketches@v1 | ||||
|         with: | ||||
|           fqbn: ${{ matrix.board.fqbn }} | ||||
|           platforms: ${{ matrix.board.platforms }} | ||||
|           libraries: | | ||||
|             # Install the library from the local path. | ||||
|             - source-path: ./ | ||||
|             ${{ matrix.board.libraries }} | ||||
|           sketch-paths: | | ||||
|             - examples/arduino_wifinina/arduino_wifinina.ino | ||||
|           enable-deltas-report: true | ||||
|           sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} | ||||
|  | ||||
|       - name: Save sketches report as workflow artifact | ||||
|         uses: actions/upload-artifact@v4 | ||||
|         with: | ||||
|           if-no-files-found: error | ||||
|           path: ${{ env.SKETCHES_REPORTS_PATH }} | ||||
|           name: sketches-report-${{ matrix.board.artifact-name-suffix }} | ||||
							
								
								
									
										81
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/compile-seeed-studio-examples.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/compile-seeed-studio-examples.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,81 @@ | ||||
| name: Compile SeedStudio Examples | ||||
|  | ||||
| # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows | ||||
| on: | ||||
|   push: | ||||
|     paths: | ||||
|       - ".github/workflows/compile-seeed-studio-examples.yaml" | ||||
|       - "examples/seeed-studio/**" | ||||
|       - "src/**" | ||||
|   pull_request: | ||||
|     paths: | ||||
|       - ".github/workflows/compile-seeed-studio-examples.yaml" | ||||
|       - "examples/seeed-studio/**" | ||||
|       - "src/**" | ||||
|   schedule: | ||||
|     # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). | ||||
|     - cron: "0 8 * * TUE" | ||||
|   workflow_dispatch: | ||||
|   repository_dispatch: | ||||
|  | ||||
| jobs: | ||||
|   build: | ||||
|     name: ${{ matrix.board.fqbn }} | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     env: | ||||
|       SKETCHES_REPORTS_PATH: sketches-reports | ||||
|  | ||||
|     strategy: | ||||
|       fail-fast: false | ||||
|  | ||||
|       matrix: | ||||
|         board: | ||||
|           - fqbn: Seeeduino:samd:seeed_XIAO_m0:usbstack=arduino,debug=off | ||||
|             platforms: | | ||||
|               - name: Seeeduino:samd | ||||
|                 source-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json | ||||
|             libraries: | | ||||
|               - name: Seeed Arduino rpcWiFi | ||||
|               - name: Seeed Arduino rpcUnified | ||||
|               - name: Seeed_Arduino_mbedtls | ||||
|               - name: Seeed Arduino FS | ||||
|               - name: Seeed Arduino SFUD | ||||
|             artifact-name-suffix: seeeduino-xia0 | ||||
|           - fqbn: Seeeduino:samd:seeed_wio_terminal | ||||
|             platforms: | | ||||
|               - name: Seeeduino:samd | ||||
|                 source-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json | ||||
|             libraries: | | ||||
|               - name: Seeed Arduino rpcWiFi | ||||
|               - name: Seeed Arduino rpcUnified | ||||
|               - name: Seeed_Arduino_mbedtls | ||||
|               - name: Seeed Arduino FS | ||||
|               - name: Seeed Arduino SFUD | ||||
|             artifact-name-suffix: seeeduino-wio_terminal | ||||
|  | ||||
|     steps: | ||||
|       - name: Checkout repository | ||||
|         uses: actions/checkout@v4 | ||||
|  | ||||
|       - name: Compile examples | ||||
|         uses: arduino/compile-sketches@v1 | ||||
|         with: | ||||
|           github-token: ${{ secrets.GITHUB_TOKEN }} | ||||
|           fqbn: ${{ matrix.board.fqbn }} | ||||
|           platforms: ${{ matrix.board.platforms }} | ||||
|           libraries: | | ||||
|             # Install the library from the local path. | ||||
|             - source-path: ./ | ||||
|             ${{ matrix.board.libraries }} | ||||
|           sketch-paths: | | ||||
|             - examples/seeed-studio/xio-wio-terminal/WebSocketClient | ||||
|           enable-deltas-report: true | ||||
|           sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} | ||||
|  | ||||
|       - name: Save sketches report as workflow artifact | ||||
|         uses: actions/upload-artifact@v4 | ||||
|         with: | ||||
|           if-no-files-found: error | ||||
|           path: ${{ env.SKETCHES_REPORTS_PATH }} | ||||
|           name: sketches-report-${{ matrix.board.artifact-name-suffix }} | ||||
							
								
								
									
										60
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/compile-unor4wifi-examples.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								libraries/arduinoWebSockets-2.6.1/.github/workflows/compile-unor4wifi-examples.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| name: Compile Arduino UNO R4 WiFi Examples | ||||
|  | ||||
| # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows | ||||
| on: | ||||
|   push: | ||||
|     paths: | ||||
|       - ".github/workflows/compile-unor4wifi-examples.yaml" | ||||
|       - "examples/arduino_renesas/**" | ||||
|       - "src/**" | ||||
|   pull_request: | ||||
|     paths: | ||||
|       - ".github/workflows/compile-unor4wifi-examples.yaml" | ||||
|       - "examples/arduino_renesas/**" | ||||
|       - "src/**" | ||||
|   schedule: | ||||
|     # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). | ||||
|     - cron: "0 8 * * TUE" | ||||
|   workflow_dispatch: | ||||
|   repository_dispatch: | ||||
|  | ||||
| jobs: | ||||
|   build: | ||||
|     name: ${{ matrix.board.fqbn }} | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     env: | ||||
|       SKETCHES_REPORTS_PATH: sketches-reports | ||||
|  | ||||
|     strategy: | ||||
|       fail-fast: false | ||||
|  | ||||
|       matrix: | ||||
|         board: | ||||
|           - fqbn: arduino:renesas_uno:unor4wifi | ||||
|             platforms: | | ||||
|               - name: arduino:renesas_uno | ||||
|  | ||||
|     steps: | ||||
|       - name: Checkout repository | ||||
|         uses: actions/checkout@v4 | ||||
|  | ||||
|       - name: Compile examples | ||||
|         uses: arduino/compile-sketches@v1 | ||||
|         with: | ||||
|           fqbn: ${{ matrix.board.fqbn }} | ||||
|           platforms: ${{ matrix.board.platforms }} | ||||
|           libraries: | | ||||
|             # Install the library from the local path. | ||||
|             - source-path: ./ | ||||
|           sketch-paths: | | ||||
|             - examples/arduino_renesas/arduino_uno_r4_wifi | ||||
|           enable-deltas-report: true | ||||
|           sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} | ||||
|  | ||||
|       - name: Save sketches report as workflow artifact | ||||
|         uses: actions/upload-artifact@v4 | ||||
|         with: | ||||
|           if-no-files-found: error | ||||
|           path: ${{ env.SKETCHES_REPORTS_PATH }} | ||||
|           name: sketches-report-${{ matrix.board.artifact-name-suffix }} | ||||
| @@ -17,7 +17,7 @@ jobs: | ||||
|   check_version_files: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v4 | ||||
| 
 | ||||
|       - name: check version | ||||
|         run: | | ||||
| @@ -26,7 +26,7 @@ jobs: | ||||
|   prepare_example_json: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v4 | ||||
| 
 | ||||
|       - name: generate examples | ||||
|         id: set-matrix | ||||
| @@ -61,7 +61,7 @@ jobs: | ||||
|       ARDUINO_DIRECTORIES_DATA: /home/runner/arduino_ide | ||||
| 
 | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v4 | ||||
| 
 | ||||
|       - name: Get hash | ||||
|         id: get-hash | ||||
| @@ -69,7 +69,7 @@ jobs: | ||||
|           echo "hash=$(/bin/date -u "+%Y%m%d")-$(md5sum ".github/workflows/main.yml" | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | ||||
|         shell: bash | ||||
| 
 | ||||
|       - uses: actions/cache@v3 | ||||
|       - uses: actions/cache@v4 | ||||
|         id: cache_all | ||||
|         with: | ||||
|           path: | | ||||
| @@ -116,7 +116,7 @@ jobs: | ||||
| 
 | ||||
|     # Steps represent a sequence of tasks that will be executed as part of the job | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v4 | ||||
| 
 | ||||
|       - name: install libgtk2.0-0 | ||||
|         run: | | ||||
| @@ -128,7 +128,7 @@ jobs: | ||||
|           echo "hash=$(/bin/date -u "+%Y%m%d")-$(md5sum ".github/workflows/main.yml" | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | ||||
|         shell: bash | ||||
| 
 | ||||
|       - uses: actions/cache@v3 | ||||
|       - uses: actions/cache@v4 | ||||
|         id: cache_all | ||||
|         with: | ||||
|           path: | | ||||
| @@ -33,6 +33,8 @@ a WebSocket Server and Client for Arduino based on RFC6455. | ||||
|  - ATmega2560 with Ethernet Shield (ATmega branch) | ||||
|  - ATmega2560 with enc28j60 (ATmega branch) | ||||
|  - Arduino UNO [R4 WiFi](https://github.com/arduino/ArduinoCore-renesas) | ||||
|  - Arduino Nano 33 IoT, MKR WIFI 1010 (requires [WiFiNINA](https://github.com/arduino-libraries/WiFiNINA/) library) | ||||
|  - Seeeduino XIAO, Seeeduino Wio Terminal (requires [rpcWiFi](https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi) library) | ||||
| 
 | ||||
| ###### Note: ###### | ||||
| 
 | ||||
| @@ -0,0 +1,100 @@ | ||||
| #include <Arduino.h> | ||||
| #include <SPI.h> | ||||
| #include <WiFiNINA.h> | ||||
| #include <WebSocketsClient.h> | ||||
|  | ||||
| #define WIFI_SSID "" | ||||
| #define WIFI_PASS "" | ||||
|  | ||||
| int status = WL_IDLE_STATUS; | ||||
| WiFiClient client; | ||||
| WebSocketsClient webSocket; | ||||
|  | ||||
| void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) { | ||||
|  | ||||
|   switch (type) { | ||||
|     case WStype_DISCONNECTED: | ||||
|       Serial.println("[WSc] Disconnected!"); | ||||
|       break; | ||||
|     case WStype_CONNECTED: | ||||
|       Serial.println("[WSc] Connected!"); | ||||
|  | ||||
|       // send message to server when Connected | ||||
|       webSocket.sendTXT("Connected"); | ||||
|       break; | ||||
|     case WStype_TEXT: | ||||
|       Serial.print("[WSc] get text:"); | ||||
|       Serial.println((char *)payload); | ||||
|  | ||||
|       // send message to server | ||||
|       // webSocket.sendTXT("message here"); | ||||
|       break; | ||||
|     case WStype_BIN: | ||||
|       // send data to server | ||||
|       // webSocket.sendBIN(payload, length); | ||||
|       break; | ||||
|     case WStype_ERROR: | ||||
|     case WStype_FRAGMENT_TEXT_START: | ||||
|     case WStype_FRAGMENT_BIN_START: | ||||
|     case WStype_FRAGMENT: | ||||
|     case WStype_PING: | ||||
|     case WStype_PONG: | ||||
|     case WStype_FRAGMENT_FIN: | ||||
|       break; | ||||
|   } | ||||
| } | ||||
|  | ||||
| void setup() { | ||||
|   Serial.begin(115200); | ||||
|  | ||||
|   while (!Serial) { | ||||
|     ;  // wait for serial port to connect. Needed for native USB port only | ||||
|   } | ||||
|  | ||||
|   Serial.println(); | ||||
|   Serial.println(); | ||||
|   Serial.println(); | ||||
|  | ||||
|   // check for the WiFi module: | ||||
|   if (WiFi.status() == WL_NO_MODULE) { | ||||
|     Serial.println("Communication with WiFi module failed!"); | ||||
|     // don't continue | ||||
|     while (true); | ||||
|   } | ||||
|  | ||||
|   String fv = WiFi.firmwareVersion(); | ||||
|   if (fv < WIFI_FIRMWARE_LATEST_VERSION) { | ||||
|     Serial.println("Please upgrade the firmware"); | ||||
|   } | ||||
|  | ||||
|   // attempt to connect to WiFi network: | ||||
|   while (status != WL_CONNECTED) { | ||||
|     Serial.print("Attempting to connect to SSID: "); | ||||
|     Serial.println(WIFI_SSID); | ||||
|     // Connect to WPA/WPA2 network. Change this line if using open or WEP network: | ||||
|     status = WiFi.begin(WIFI_SSID, WIFI_PASS); | ||||
|  | ||||
|     // wait 10 seconds for connection: | ||||
|     delay(10000); | ||||
|   } | ||||
|  | ||||
|   Serial.println("Connected to WiFi"); | ||||
|  | ||||
|   // print your board's IP address: | ||||
|   IPAddress ip = WiFi.localIP(); | ||||
|   Serial.print("IP Address: "); | ||||
|   Serial.println(ip); | ||||
|  | ||||
|   // server address, port and URL | ||||
|   webSocket.begin("192.168.0.123", 8011); | ||||
|  | ||||
|   // event handler | ||||
|   webSocket.onEvent(webSocketEvent); | ||||
|  | ||||
|   // try ever 5000 again if connection has failed | ||||
|   webSocket.setReconnectInterval(5000); | ||||
| } | ||||
|  | ||||
| void loop() { | ||||
|   webSocket.loop(); | ||||
| } | ||||
| @@ -42,8 +42,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length | ||||
|                 IPAddress ip = webSocket.remoteIP(num); | ||||
|                 USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); | ||||
| 
 | ||||
| 				// send message to client
 | ||||
| 				webSocket.sendTXT(num, "Connected"); | ||||
| 		// send message to client
 | ||||
| 		webSocket.sendTXT(num, "Connected"); | ||||
|             } | ||||
|             break; | ||||
|         case WStype_TEXT: | ||||
| @@ -62,12 +62,12 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length | ||||
|             // send message to client
 | ||||
|             // webSocket.sendBIN(num, payload, length);
 | ||||
|             break; | ||||
| 		case WStype_ERROR:			 | ||||
| 		case WStype_FRAGMENT_TEXT_START: | ||||
| 		case WStype_FRAGMENT_BIN_START: | ||||
| 		case WStype_FRAGMENT: | ||||
| 		case WStype_FRAGMENT_FIN: | ||||
| 			break; | ||||
| 	case WStype_ERROR:			 | ||||
| 	case WStype_FRAGMENT_TEXT_START: | ||||
| 	case WStype_FRAGMENT_BIN_START: | ||||
| 	case WStype_FRAGMENT: | ||||
| 	case WStype_FRAGMENT_FIN: | ||||
| 	    break; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @@ -0,0 +1,105 @@ | ||||
| /* | ||||
|  * WebSocketClient.ino | ||||
|  * | ||||
|  *  Created on: 10.08.2024 | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include <Arduino.h> | ||||
| #include <rpcWiFi.h> | ||||
| #include <WiFiMulti.h> | ||||
| #include <WebSocketsClient.h> | ||||
|  | ||||
| WebSocketsClient webSocket; | ||||
| WiFiMulti wifiMulti; | ||||
|  | ||||
| #define USE_SERIAL Serial | ||||
|  | ||||
| void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) { | ||||
| 	const uint8_t* src = (const uint8_t*) mem; | ||||
| 	USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); | ||||
| 	for(uint32_t i = 0; i < len; i++) { | ||||
| 		if(i % cols == 0) { | ||||
| 			USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); | ||||
| 		} | ||||
| 		USE_SERIAL.printf("%02X ", *src); | ||||
| 		src++; | ||||
| 	} | ||||
| 	USE_SERIAL.printf("\n"); | ||||
| } | ||||
|  | ||||
| void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { | ||||
|  | ||||
| 	switch(type) { | ||||
| 		case WStype_DISCONNECTED: | ||||
| 			USE_SERIAL.printf("[WSc] Disconnected!\n"); | ||||
| 			break; | ||||
| 		case WStype_CONNECTED: | ||||
| 			USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); | ||||
|  | ||||
| 			// send message to server when Connected | ||||
| 			webSocket.sendTXT("Connected"); | ||||
| 			break; | ||||
| 		case WStype_TEXT: | ||||
| 			USE_SERIAL.printf("[WSc] get text: %s\n", payload); | ||||
|  | ||||
| 			// send message to server | ||||
| 			// webSocket.sendTXT("message here"); | ||||
| 			break; | ||||
| 		case WStype_BIN: | ||||
| 			USE_SERIAL.printf("[WSc] get binary length: %u\n", length); | ||||
| 			hexdump(payload, length); | ||||
|  | ||||
| 			// send data to server | ||||
| 			// webSocket.sendBIN(payload, length); | ||||
| 			break; | ||||
| 		case WStype_ERROR:			 | ||||
| 		case WStype_FRAGMENT_TEXT_START: | ||||
| 		case WStype_FRAGMENT_BIN_START: | ||||
| 		case WStype_FRAGMENT: | ||||
|     case WStype_PONG: | ||||
|     case WStype_PING: | ||||
| 		case WStype_FRAGMENT_FIN: | ||||
| 			break; | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| void setup() { | ||||
| 	// USE_SERIAL.begin(921600); | ||||
| 	USE_SERIAL.begin(115200); | ||||
| 	 | ||||
| 	USE_SERIAL.println(); | ||||
| 	USE_SERIAL.println(); | ||||
| 	USE_SERIAL.println(); | ||||
|  | ||||
| 	for(uint8_t t = 4; t > 0; t--) { | ||||
| 		USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); | ||||
| 		USE_SERIAL.flush(); | ||||
| 		delay(1000); | ||||
| 	} | ||||
|  | ||||
| 	wifiMulti.addAP("SSID", "passpasspass"); | ||||
|  | ||||
| 	//WiFi.disconnect(); | ||||
| 	while(wifiMulti.run() != WL_CONNECTED) { | ||||
| 		delay(100); | ||||
| 	} | ||||
|  | ||||
| 	// server address, port and URL | ||||
| 	webSocket.begin("192.168.0.123", 81, "/"); | ||||
|  | ||||
| 	// event handler | ||||
| 	webSocket.onEvent(webSocketEvent); | ||||
|  | ||||
| 	// use HTTP Basic Authorization this is optional remove if not needed | ||||
| 	webSocket.setAuthorization("user", "Password"); | ||||
|  | ||||
| 	// try ever 5000 again if connection has failed | ||||
| 	webSocket.setReconnectInterval(5000); | ||||
|  | ||||
| } | ||||
|  | ||||
| void loop() { | ||||
| 	webSocket.loop(); | ||||
| } | ||||
| @@ -16,10 +16,10 @@ | ||||
|     "keywords": "wifi, http, web, server, client, websocket", | ||||
|     "license": "LGPL-2.1", | ||||
|     "name": "WebSockets", | ||||
|     "platforms": "atmelavr, espressif8266, espressif32, raspberrypi, renesas_uno", | ||||
|     "platforms": "*", | ||||
|     "repository": { | ||||
|         "type": "git", | ||||
|         "url": "https://github.com/Links2004/arduinoWebSockets.git" | ||||
|     }, | ||||
|     "version": "2.5.2" | ||||
|     "version": "2.6.1" | ||||
| } | ||||
| @@ -1,5 +1,5 @@ | ||||
| name=WebSockets | ||||
| version=2.5.2 | ||||
| version=2.6.1 | ||||
| author=Markus Sattler | ||||
| maintainer=Markus Sattler | ||||
| sentence=WebSockets for Arduino (Server + Client) | ||||
| @@ -261,4 +261,4 @@ void SocketIOclient::handleCbEvent(WStype_t type, uint8_t * payload, size_t leng | ||||
|         case WStype_PONG: | ||||
|             break; | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -55,10 +55,12 @@ class SocketIOclient : protected WebSocketsClient { | ||||
|     void beginSSL(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5); | ||||
| #ifndef SSL_AXTLS | ||||
|     void beginSSLWithCA(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * CA_cert = NULL, const char * protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5); | ||||
|     void beginSSLWithCA(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", BearSSL::X509List * CA_cert = NULL, const char * protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5); | ||||
|     void setSSLClientCertKey(const char * clientCert = NULL, const char * clientPrivateKey = NULL); | ||||
| #if defined(SSL_BARESSL) | ||||
|     void beginSSLWithCA(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", BearSSL::X509List * CA_cert = NULL, const char * protocol = "arduino", uint32_t pingInterval = 60 * 1000, uint32_t pongTimeout = 90 * 1000, uint8_t disconnectTimeoutCount = 5); | ||||
|     void setSSLClientCertKey(BearSSL::X509List * clientCert = NULL, BearSSL::PrivateKey * clientPrivateKey = NULL); | ||||
| #endif | ||||
| #endif | ||||
| #endif | ||||
|     bool isConnected(void); | ||||
| 
 | ||||
| @@ -99,6 +99,18 @@ | ||||
| #define WEBSOCKETS_YIELD() yield() | ||||
| #define WEBSOCKETS_YIELD_MORE() delay(1) | ||||
| 
 | ||||
| #elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) | ||||
| 
 | ||||
| #define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024) | ||||
| #define WEBSOCKETS_YIELD() yield() | ||||
| #define WEBSOCKETS_YIELD_MORE() delay(1) | ||||
| 
 | ||||
| #elif defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0) | ||||
| 
 | ||||
| #define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024) | ||||
| #define WEBSOCKETS_YIELD() yield() | ||||
| #define WEBSOCKETS_YIELD_MORE() delay(1) | ||||
| 
 | ||||
| #else | ||||
| 
 | ||||
| // atmega328p has only 2KB ram!
 | ||||
| @@ -121,6 +133,8 @@ | ||||
| #define NETWORK_ESP32_ETH (5) | ||||
| #define NETWORK_RP2040 (6) | ||||
| #define NETWORK_UNOWIFIR4 (7) | ||||
| #define NETWORK_WIFI_NINA (8) | ||||
| #define NETWORK_SAMD_SEED (9) | ||||
| 
 | ||||
| // max size of the WS Message Header
 | ||||
| #define WEBSOCKETS_MAX_HEADER_SIZE (14) | ||||
| @@ -142,6 +156,12 @@ | ||||
| #elif defined(ARDUINO_UNOWIFIR4) | ||||
| #define WEBSOCKETS_NETWORK_TYPE NETWORK_UNOWIFIR4 | ||||
| 
 | ||||
| #elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) | ||||
| #define WEBSOCKETS_NETWORK_TYPE NETWORK_WIFI_NINA | ||||
| 
 | ||||
| #elif defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0) | ||||
| #define WEBSOCKETS_NETWORK_TYPE NETWORK_SAMD_SEED | ||||
| 
 | ||||
| #else | ||||
| #define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100 | ||||
| 
 | ||||
| @@ -237,6 +257,31 @@ | ||||
| #elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4) | ||||
| 
 | ||||
| #include <WiFiS3.h> | ||||
| #define WEBSOCKETS_NETWORK_CLASS WiFiClient | ||||
| #define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer | ||||
| 
 | ||||
| #elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) | ||||
| #if __has_include(<WiFiNINA.h>) | ||||
| #include <WiFiNINA.h> | ||||
| #else | ||||
| #error "Please install WiFiNINA library!" | ||||
| #endif | ||||
| 
 | ||||
| #define WEBSOCKETS_NETWORK_CLASS WiFiClient | ||||
| #define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer | ||||
| #define WEBSOCKETS_NETWORK_SSL_CLASS WiFiSSLClient | ||||
| 
 | ||||
| #elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED) | ||||
| #if __has_include(<rpcWiFi.h>) && __has_include(<rpcWiFiClientSecure.h>) | ||||
| #include <rpcWiFi.h> | ||||
| #include <rpcWiFiClientSecure.h> | ||||
| #else | ||||
| #error "Please install rpcWiFi library!" | ||||
| #endif | ||||
| 
 | ||||
| #define WEBSOCKETS_NETWORK_CLASS WiFiClient | ||||
| #define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer | ||||
| #define WEBSOCKETS_NETWORK_SSL_CLASS WiFiClientSecure | ||||
| 
 | ||||
| #define WEBSOCKETS_NETWORK_CLASS WiFiClient | ||||
| #define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer | ||||
| @@ -155,6 +155,7 @@ void WebSocketsClient::beginSSL(const char * host, uint16_t port, const char * u | ||||
|     _CA_cert      = NULL; | ||||
| } | ||||
| 
 | ||||
| #if defined(SSL_BARESSL) | ||||
| 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; | ||||
| @@ -166,14 +167,15 @@ void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const ch | ||||
|     beginSslWithCA(host, port, url, new BearSSL::X509List(CA_cert), protocol); | ||||
| } | ||||
| 
 | ||||
| void WebSocketsClient::setSSLClientCertKey(const char * clientCert, const char * clientPrivateKey) { | ||||
|     setSSLClientCertKey(new BearSSL::X509List(clientCert), new BearSSL::PrivateKey(clientPrivateKey)); | ||||
| } | ||||
| 
 | ||||
| void WebSocketsClient::setSSLClientCertKey(BearSSL::X509List * clientCert, BearSSL::PrivateKey * clientPrivateKey) { | ||||
|     _client_cert = clientCert; | ||||
|     _client_key  = clientPrivateKey; | ||||
| } | ||||
| 
 | ||||
| void WebSocketsClient::setSSLClientCertKey(const char * clientCert, const char * clientPrivateKey) { | ||||
|     setSSLClientCertKey(new BearSSL::X509List(clientCert), new BearSSL::PrivateKey(clientPrivateKey)); | ||||
| } | ||||
| #endif    // SSL_BARESSL
 | ||||
| 
 | ||||
| #endif    // SSL_AXTLS
 | ||||
| #endif    // HAS_SSL
 | ||||
| @@ -242,7 +244,12 @@ void WebSocketsClient::loop(void) { | ||||
|         if(_client.isSSL) { | ||||
|             DEBUG_WEBSOCKETS("[WS-Client] connect wss...\n"); | ||||
|             if(_client.ssl) { | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4) | ||||
|                 // does not support delete (no destructor)
 | ||||
| #else | ||||
|                 delete _client.ssl; | ||||
| #endif | ||||
| 
 | ||||
|                 _client.ssl = NULL; | ||||
|                 _client.tcp = NULL; | ||||
|             } | ||||
| @@ -256,6 +263,10 @@ void WebSocketsClient::loop(void) { | ||||
|                 _client.ssl->setCACert((const uint8_t *)_CA_cert, strlen(_CA_cert) + 1); | ||||
| #elif(defined(ESP8266) || defined(ARDUINO_ARCH_RP2040)) && defined(SSL_BARESSL) | ||||
|                 _client.ssl->setTrustAnchors(_CA_cert); | ||||
| #elif defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0) | ||||
|                 _client.ssl->setCACert(_CA_cert); | ||||
| #elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) | ||||
|                 // no setCACert
 | ||||
| #else | ||||
| #error setCACert not implemented | ||||
| #endif | ||||
| @@ -283,7 +294,11 @@ void WebSocketsClient::loop(void) { | ||||
|         } else { | ||||
|             DEBUG_WEBSOCKETS("[WS-Client] connect ws...\n"); | ||||
|             if(_client.tcp) { | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4) | ||||
|                 // does not support delete (no destructor)
 | ||||
| #else | ||||
|                 delete _client.tcp; | ||||
| #endif | ||||
|                 _client.tcp = NULL; | ||||
|             } | ||||
|             _client.tcp = new WEBSOCKETS_NETWORK_CLASS(); | ||||
| @@ -533,8 +548,12 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) { | ||||
|         event = true; | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) | ||||
|         client->status = WSC_NOT_CONNECTED; | ||||
| #else | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4) | ||||
|         // does not support delete (no destructor)
 | ||||
| #else | ||||
|         delete client->tcp; | ||||
| #endif | ||||
| #endif | ||||
|         client->tcp = NULL; | ||||
|     } | ||||
| @@ -48,8 +48,10 @@ class WebSocketsClient : protected WebSockets { | ||||
|     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"); | ||||
| #if defined(SSL_BARESSL) | ||||
|     void beginSslWithCA(const char * host, uint16_t port, const char * url = "/", BearSSL::X509List * CA_cert = NULL, const char * protocol = "arduino"); | ||||
|     void setSSLClientCertKey(BearSSL::X509List * clientCert = NULL, BearSSL::PrivateKey * clientPrivateKey = NULL); | ||||
| #endif | ||||
|     void setSSLClientCertKey(const char * clientCert = NULL, const char * clientPrivateKey = NULL); | ||||
| #endif | ||||
|     void beginSslWithCA(const char * host, uint16_t port, const char * url = "/", const char * CA_cert = NULL, const char * protocol = "arduino"); | ||||
| @@ -129,13 +131,20 @@ class WebSocketsClient : protected WebSockets { | ||||
| #define SSL_FINGERPRINT_NULL "" | ||||
| #else | ||||
|     const uint8_t * _fingerprint; | ||||
| #if defined(SSL_BARESSL) | ||||
|     BearSSL::X509List * _CA_cert; | ||||
|     BearSSL::X509List * _client_cert; | ||||
|     BearSSL::PrivateKey * _client_key; | ||||
| #endif | ||||
| #define SSL_FINGERPRINT_IS_SET (_fingerprint != NULL) | ||||
| #define SSL_FINGERPRINT_NULL NULL | ||||
| #endif | ||||
| 
 | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) | ||||
|     const char * _CA_cert; | ||||
|     const uint8_t * _CA_bundle; | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
|     WSclient_t _client; | ||||
| 
 | ||||
| @@ -25,6 +25,14 @@ | ||||
| #include "WebSockets.h" | ||||
| #include "WebSocketsServer.h" | ||||
| 
 | ||||
| #ifdef ESP32 | ||||
| #if defined __has_include | ||||
| #if __has_include("soc/wdev_reg.h") | ||||
| #include "soc/wdev_reg.h" | ||||
| #endif    // __has_include
 | ||||
| #endif    // defined __has_include
 | ||||
| #endif | ||||
| 
 | ||||
| WebSocketsServerCore::WebSocketsServerCore(const String & origin, const String & protocol) { | ||||
|     _origin                 = origin; | ||||
|     _protocol               = protocol; | ||||
| @@ -65,7 +73,11 @@ WebSocketsServerCore::~WebSocketsServerCore() { | ||||
| } | ||||
| 
 | ||||
| WebSocketsServer::~WebSocketsServer() { | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED) | ||||
|     // does not support delete (no destructor)
 | ||||
| #else | ||||
|     delete _server; | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
| @@ -83,10 +95,11 @@ void WebSocketsServerCore::begin(void) { | ||||
| 
 | ||||
| #ifdef ESP8266 | ||||
|     randomSeed(RANDOM_REG32); | ||||
| #elif defined(ESP32) && defined(WDEV_RND_REG) | ||||
|     randomSeed(REG_READ(WDEV_RND_REG)); | ||||
| #elif defined(ESP32) | ||||
| #define DR_REG_RNG_BASE 0x3ff75144 | ||||
|     randomSeed(millis()); | ||||
|     //randomSeed(READ_PERI_REG(DR_REG_RNG_BASE));
 | ||||
|     randomSeed(READ_PERI_REG(DR_REG_RNG_BASE)); | ||||
| #elif defined(ARDUINO_ARCH_RP2040) | ||||
|     randomSeed(rp2040.hwrand32()); | ||||
| #else | ||||
| @@ -540,6 +553,8 @@ void WebSocketsServerCore::dropNativeClient(WSclient_t * client) { | ||||
|         } | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) | ||||
|         client->status = WSC_NOT_CONNECTED; | ||||
| #elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_SAMD_SEED) | ||||
|         // does not support delete (no destructor)
 | ||||
| #else | ||||
|         delete client->tcp; | ||||
| #endif | ||||
| @@ -655,8 +670,13 @@ void WebSocketsServer::handleNewClients(void) { | ||||
|     while(_server->hasClient()) { | ||||
| #endif | ||||
| 
 | ||||
|         // store new connection
 | ||||
|         WEBSOCKETS_NETWORK_CLASS * tcpClient = new WEBSOCKETS_NETWORK_CLASS(_server->accept()); | ||||
| // store new connection
 | ||||
| #if(WEBSOCKETS_NETWORK_TYPE == NETWORK_WIFI_NINA) | ||||
|         WEBSOCKETS_NETWORK_CLASS * tcpClient = new WEBSOCKETS_NETWORK_CLASS(_server->available()); | ||||
| #else | ||||
|     WEBSOCKETS_NETWORK_CLASS * tcpClient = new WEBSOCKETS_NETWORK_CLASS(_server->accept()); | ||||
| #endif | ||||
| 
 | ||||
|         if(!tcpClient) { | ||||
|             DEBUG_WEBSOCKETS("[WS-Client] creating Network class failed!"); | ||||
|             return; | ||||
| @@ -1,6 +1,6 @@ | ||||
| /**
 | ||||
|  * @file WebSocketsVersion.h | ||||
|  * @date 29.07.2024 | ||||
|  * @date 06.09.2024 | ||||
|  * @author Markus Sattler | ||||
|  * | ||||
|  * Copyright (c) 2015 Markus Sattler. All rights reserved. | ||||
| @@ -25,12 +25,12 @@ | ||||
| #ifndef WEBSOCKETSVERSION_H_ | ||||
| #define WEBSOCKETSVERSION_H_ | ||||
| 
 | ||||
| #define WEBSOCKETS_VERSION "2.5.2" | ||||
| #define WEBSOCKETS_VERSION "2.6.1" | ||||
| 
 | ||||
| #define WEBSOCKETS_VERSION_MAJOR 2 | ||||
| #define WEBSOCKETS_VERSION_MINOR 5 | ||||
| #define WEBSOCKETS_VERSION_PATCH 2 | ||||
| #define WEBSOCKETS_VERSION_MINOR 6 | ||||
| #define WEBSOCKETS_VERSION_PATCH 1 | ||||
| 
 | ||||
| #define WEBSOCKETS_VERSION_INT 2005002 | ||||
| #define WEBSOCKETS_VERSION_INT 2006001 | ||||
| 
 | ||||
| #endif /* WEBSOCKETSVERSION_H_ */ | ||||
| @@ -9,7 +9,7 @@ For details, see http://sourceforge.net/projects/libb64 | ||||
| #include <core_esp8266_features.h> | ||||
| #endif | ||||
| 
 | ||||
| #if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) | ||||
| #if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0) | ||||
| #define CORE_HAS_LIBB64 | ||||
| #endif | ||||
| 
 | ||||
| @@ -9,7 +9,7 @@ For details, see http://sourceforge.net/projects/libb64 | ||||
| #include <core_esp8266_features.h> | ||||
| #endif | ||||
| 
 | ||||
| #if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) | ||||
| #if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(WIO_TERMINAL) || defined(SEEED_XIAO_M0) | ||||
| #define CORE_HAS_LIBB64 | ||||
| #endif | ||||
| 
 | ||||
		Reference in New Issue
	
	Block a user