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
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.
@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.
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:
STL conflict:
Ameba core defines min/max as macros, which break <vector> and <algorithm>.
→ Error: macro "min" passed 3 arguments
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!"
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:
Is there any official or recommended WebSocket Client library for Ameba Pro 2?
Does the Ameba SDK support standard C++ STL cleanly (without Arduino macro conflicts)?
If WebSocket is not well-supported, is switching to HTTP polling via WiFiClient a better option?