Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Arduino UNO WIFI 4 #894

Merged
merged 10 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ a WebSocket Server and Client for Arduino based on RFC6455.
- ATmega328 with enc28j60 (ATmega branch)
- ATmega2560 with Ethernet Shield (ATmega branch)
- ATmega2560 with enc28j60 (ATmega branch)
- Arduino UNO [R4 WiFi](https://github.com/arduino/ArduinoCore-renesas)

###### Note: ######

Expand Down
109 changes: 109 additions & 0 deletions examples/arduino_renesas/arduino_uno_r4_wifi/arduino_uno_r4_wifi.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <Arduino.h>
#include <stdarg.h>
#include <stdio.h>

#include "WiFiS3.h"
#include <WebSocketsClient.h>

#define WIFI_SSID ""
#define WIFI_PASS ""

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_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();

for (uint8_t t = 4; t > 0; t--) {
Serial.println("[SETUP] BOOT WAIT ...");
Serial.flush();
delay(1000);
}

// 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");
}

Serial.println("[Wifi]: Connecting");

int status = WL_IDLE_STATUS;

// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("[Wifi]: 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);

delay(1000);
}

Serial.println("Connected!");

// 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();
}
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"keywords": "wifi, http, web, server, client, websocket",
"license": "LGPL-2.1",
"name": "WebSockets",
"platforms": "atmelavr, espressif8266, espressif32, raspberrypi",
"platforms": "atmelavr, espressif8266, espressif32, raspberrypi, renesas_uno",
"repository": {
"type": "git",
"url": "https://github.com/Links2004/arduinoWebSockets.git"
},
"version": "2.4.2"
}
"version": "2.5.1"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=WebSockets
version=2.4.2
version=2.5.1
author=Markus Sattler
maintainer=Markus Sattler
sentence=WebSockets for Arduino (Server + Client)
Expand Down
17 changes: 17 additions & 0 deletions src/WebSockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
#define WEBSOCKETS_YIELD() yield()
#define WEBSOCKETS_YIELD_MORE() delay(1)

#elif defined(ARDUINO_UNOWIFIR4)

#define WEBSOCKETS_MAX_DATA_SIZE (15 * 1024)
#define WEBSOCKETS_YIELD() yield()
#define WEBSOCKETS_YIELD_MORE() delay(1)

#else

// atmega328p has only 2KB ram!
Expand All @@ -114,6 +120,7 @@
#define NETWORK_ESP32 (4)
#define NETWORK_ESP32_ETH (5)
#define NETWORK_RP2040 (6)
#define NETWORK_UNOWIFIR4 (7)

// max size of the WS Message Header
#define WEBSOCKETS_MAX_HEADER_SIZE (14)
Expand All @@ -132,6 +139,9 @@
#elif defined(ARDUINO_ARCH_RP2040)
#define WEBSOCKETS_NETWORK_TYPE NETWORK_RP2040

#elif defined(ARDUINO_UNOWIFIR4)
#define WEBSOCKETS_NETWORK_TYPE NETWORK_UNOWIFIR4

#else
#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100

Expand Down Expand Up @@ -224,6 +234,13 @@
#define WEBSOCKETS_NETWORK_SSL_CLASS WiFiClientSecure
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer

#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_UNOWIFIR4)

#include <WiFiS3.h>

#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer

#else
#error "no network type selected!"
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/WebSocketsVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#ifndef WEBSOCKETSVERSION_H_
#define WEBSOCKETSVERSION_H_

#define WEBSOCKETS_VERSION "2.4.2"
#define WEBSOCKETS_VERSION "2.5.1"

#define WEBSOCKETS_VERSION_MAJOR 2
#define WEBSOCKETS_VERSION_MINOR 4
#define WEBSOCKETS_VERSION_PATCH 2
#define WEBSOCKETS_VERSION_MINOR 5
#define WEBSOCKETS_VERSION_PATCH 1

#define WEBSOCKETS_VERSION_INT 2004002
#define WEBSOCKETS_VERSION_INT 2005001

#endif /* WEBSOCKETSVERSION_H_ */
Loading