WebSocket doesn't compile

Hi everyone!
My arduino is a uno r4 wifi
I’m trying to add webSocket to a project of mine. But I have some problems… this is the code:

https://gist.github.com/.../5ac49225bb451026793b9f162bc53581

And these are the errors from the compiler:

In file included from C:\Users\Dino\OneDrive\Documenti\Arduino\libraries\ArduinoWebsockets\src/ArduinoWebsockets.h:6:0,

from C:\Users\Dino\OneDrive\Documenti\Arduino\Arduino_Http_testWebSocket\Arduino_Http_testWebSocket.ino:19:

C:\Users\Dino\OneDrive\Documenti\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/server.hpp:10:40: error: expected ')' before '*' token

WebsocketsServer(network::TcpServer*, server = new WSDefaultTcpServer);

^

C:\Users\Dino\OneDrive\Documenti\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/server.hpp:26:14: error: 'TcpServer' in namespace 'websockets::network' does not name a type

network::TcpServer* _server;

^~~~~~~~~

exit status 1

Compilation error: exit status 1

Could somebody help me? !:pray:t2:

Try adding parenthesis to instantiate the class object...???

= new WSDefaultTcpServer());
1 Like

Oh.. no, looks like there is no named variable here...???

1 Like

In the code that you could have easily included in your post thusly:

/*
	Esp32 Websockets Client

	This sketch:
        1. Connects to a WiFi network
        2. Connects to a Websockets server
        3. Sends the websockets server a message ("Hello Server")
        4. Prints all incoming messages while the connection is open

	Hardware:
        For this sketch you only need an ESP32 board.

	Created 15/02/2019
	By Gil Maimon
	https://github.com/gilmaimon/ArduinoWebsockets

*/

#include <ArduinoWebsockets.h>
#include <WiFiS3.h>

const char* ssid = ""; //Enter SSID
const char* password = ""; //Enter Password
const char* websockets_server_host = ""; //Enter server adress
const uint16_t websockets_server_port = ; // Enter server port

using namespace websockets;

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);
    }

    // Check if connected to wifi
    if(WiFi.status() != WL_CONNECTED) {
        Serial.println("No Wifi!");
        return;
    }

    Serial.println("Connected to Wifi, Connecting to server.");
    // try to connect to Websockets server
    bool connected = client.connect(websockets_server_host, websockets_server_port, "/");
    if(connected) {
        Serial.println("Connected!");
        client.send("Hello Server");
    } else {
        Serial.println("Not Connected!");
    }
    
    // run callback when messages are received
    client.onMessage([&](WebsocketsMessage message){
        Serial.print("Got Message: ");
        Serial.println(message.data());
    });
}

void loop() {
    // let the websockets client check for incoming messages
    if(client.available()) {
        client.poll();
    }
    delay(500);
}

I noticed this in the program header:

	Esp32 Websockets Client
.
.
.
	Hardware:
        For this sketch you only need an ESP32 board.

And when I went to the Github repository that the code came from, the "About" section read:

A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)

Although there is an ESP32 on the Uno R4 Wifi, the sketch you are compiling does not run on the ESP32; it runs on the Renesas RA4M1 processor.

It is perhaps not reasonable to expect an example entitled "ESP32-Client" from a library written to support ESP8266 and ESP32 to compile and run on a Renesas RA4M1 processor.

Additionally, there are dozens of open issues with that library going back a few years. Is it possible that the example simply doesn't work? Have you tried compiling it for an ESP32 board to check that?

1 Like

It may need updating (e.g. change ESPAsyncWebServer to ESPAsyncWebSrv)

1 Like

Thanks for all advice. I'm actually a noob about arduino and c++.
Nope, unfortunaly I haven't an ESP32 to check.

Your problem was that the code did not compile. My suggestion was to try compiling for an ESP32, not actually running the code on one. You don't actually need an ESP32 to compile the code. Success or failure in that scenario would give you an indication of the state of the example and library themselves with their intended processor.

This post has been long time ago. However, I commented and hope it is helpful for OP or newbies, who reach this thread by searching solution on the internet.

For Arduino Uno R4, It is quite new, and at the time wrote this comment, there is not many tutorials about WebSocket with Arduino Uno R4. You can use mWebSockets library. The library enables Ethernet Shield be default, To change to WiFi, A little modification is needed in the config.h file. You can see the detailed instruction in this Arduino Uno R4 WebSocket Tutorial

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