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