Where is a simple WebSocketClient Example?

IoT devices usually work over websockets. Cannot get this basic code to compile:

#include <WiFi.h>
#include <WebSocketsClient.h>

// Replace with your network credentials
char* ssid = "ssid";
char* password = "pwd";

// Replace with the WebSocket server address and port
const char* serverAddress = "192.168.1.100"; // running on local NodeJS server
const uint16_t serverPort = 8880;  // Example port

void setup() {
  init_wifi();
  webSocket.begin(serverAddress, serverPort, "/");
}

void loop() {
  delay(1000);
}

void init_wifi() {
  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  Serial.print("Connecting to ");
  Serial.print(ssid);
  Serial.println("...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  delay(1000);
}

This fails to compile due to some unknown problem with WebSocketsClient. Can anyone provide a fix? Or a better library that can be used? Need at least a simple example with board being used as a websocket client

Hi @clutterlabs,

Currently our Arduino SDK do not have a websocket example, but if you want a secure connection, we have SSL client instead. We have plans to get one websocket example in the SDK, but this may take some time.

Thank you for your understanding.

@Kelvin_Huang can you point to an example with WiFiClient instead? An example on how to upgrade to websocket connection using an http POST will be very helpful.

Hi @clutterlabs,

Unfortunately we don’t have a websocket client yet.

The closest is for a secure connection is WifiSSL client example.

You may refer to this link for the example. WiFi – Set up SSL Client for HTTPS Communication – Realtek IoT/Wi-Fi MCU Solutions

Thank you.