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.

Hello! Have you made any progress? I was hoping to stream video via WebSocket.

Hi @MatheusMarkies

Websocket viewer for streaming is available for FreeRTOS SDK. Please refer to the following folder for example:
Ameba-AIoT/ameba-rtos-pro2: media_websocket_viewer

For Arduino SDK is still under process.

Arduino SDK 有開發成功了嗎
或是有其他非官方版本可以使用的WebSocket庫

Title: AmebaPro2Ameba Pro 2AmebaPro2 WebSocket Client fails to compile due to STL/ESP header conflicts — what’s the recommended solution?

Body:

Hardware: Ameba Pro 2 (AMB82-Mini / HUB-8735 Ultra)
IDE: Arduino IDE 2.x
Goal: Use WebSocket to exchange JSON and images with a Python Flask server.

Issue Summary:

I tried using the WebSockets library by Markus Sattler (v2.6.1), but it fails to compile on Ameba Pro 2 due to multiple conflicts:

  1. STL conflict:
    Ameba core defines min/max as macros, which break <vector> and <algorithm>.
    → Error: macro "min" passed 3 arguments

  2. Wrong platform detection:
    The library sees WiFi.h and assumes ESP8266/ESP32, forcing ESPAsyncTCP.h.
    → Error: fatal error: ESPAsyncTCP.h: No such file or directory
    → Error: #error "network type ESP8266 ASYNC only possible on the ESP mcu!"

  3. Cannot override network type via macros:
    Even after adding:

    #undef min
    #undef max
    #define WEBSOCKETS_NETWORK_TYPE WiFi
    #define WEBSOCKETS_NETWORK_CLASS WiFiClient
    
    

    the library still throws EthernetClient / network-type related errors.

Questions:

  1. Is there any official or recommended WebSocket Client library for Ameba Pro 2?

  2. Does the Ameba SDK support standard C++ STL cleanly (without Arduino macro conflicts)?

  3. If WebSocket is not well-supported, is switching to HTTP polling via WiFiClient a better option?