ArduinoWebSockets issue

Im using the following code in the Arduino IDE with the Arduino GIGA R1 WIFI to connect to a websocketserver and receive messages and send messages.

#include <WiFi.h>
#include <ArduinoWebsockets.h>

const char* ssid = "ssid"; //Enter SSID
const char* password = "password"; //Enter Password
const char* websockets_server = "ws://serveradress.com:8080"; //server adress and port

using namespace websockets;

void onMessageCallback(WebsocketsMessage message) {
    Serial.print("Got Message: ");
    Serial.println(message.data());
}

void onEventsCallback(WebsocketsEvent event, String data) {
    if(event == WebsocketsEvent::ConnectionOpened) {
        Serial.println("Connnection Opened");
    } else if(event == WebsocketsEvent::ConnectionClosed) {
        Serial.println("Connnection Closed");
    } else if(event == WebsocketsEvent::GotPing) {
        Serial.println("Got a Ping!");
    } else if(event == WebsocketsEvent::GotPong) {
        Serial.println("Got a Pong!");
    }
}

WebsocketsClient client;
void setup() {
    Serial.begin(115200);
    // Connect to wifi
    WiFi.begin(ssid, password);

    // Wait some time to connect to wifi
    for(int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
        Serial.print(".");
        delay(1000);
    }

    // Setup Callbacks
    client.onMessage(onMessageCallback);
    client.onEvent(onEventsCallback);
    
    // Connect to server
    client.connect(websockets_server);

    // Send a message
    client.send("Hi Server!");
    // Send a ping
    client.ping();
}

void loop() {
    client.poll();
}

And i am receiving the following errors:

\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/server.hpp:10:40: error: expected ')' before '*' token
     WebsocketsServer(network::TcpServer* server = new WSDefaultTcpServer);

Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/server.hpp:26:14: error: 'TcpServer' in namespace 'websockets::network' does not name a type
     network::TcpServer* _server;

Is there anyone that knows how to fix this or that has a alternative solution that works for the Arduino GIGA R1 WIFI?

You don't provide a link to the library you're using but it seems you're using this library.

The README clearly states:

Currently (version 0.5.*) the library only works with ESP8266, ESP32 and Teensy 4.1.

Your board is not in that list.

That is indeed the correct library, GitHub - gilmaimon/ArduinoWebsockets: A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)

Arduino Websockets, but i should be able to use it since it’s esp32 right and the arduino giga r1 wifi uses the esp32 module as well it’s the same in the wifi documentation.

If not do you know a library that works with this for the arduino giga r1 wifi or another way to receive and send data from a webserver.

Thank’s for the quick response.

It does use the a Cypress chipset for WiFi and is not compatible in any way with the ESP32.

This library uses a generic Client object to do the network stuff, so it should work with almost any networking implementation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.