Echo Example Websocket Ethernet Client failed

Hello ,

I try to connect Ethernet arduino to webSocket and I get this error

no matching function for call to 'WebSocketClient::WebSocketClient()

here is my code

#include "Arduino.h"
#include <Ethernet.h>
#include <SPI.h>
#include <WebSocketClient.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "echo.websocket.org";
WebSocketClient client;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac);
  client.connect(server);
  client.setDataArrivedDelegate(dataArrived);
  client.send("Hello World!");
}

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

void dataArrived(WebSocketClient client, String data) {
  Serial.println("Data Arrived: " + data);
}

The compiler indicated an error in 8th line

WebSocketClient client;

Here is the WebSocketClient.h file

#ifndef WEBSOCKETCLIENT_H
#define WEBSOCKETCLIENT_H_

#include <string.h>
#include <stdlib.h>
#include <WString.h>
#include <Ethernet.h>
#include "Arduino.h"

//Uncomment this to use WIFLY Client
#define WIFLY true

class WebSocketClient {
	public:
		typedef void (*DataArrivedDelegate)(WebSocketClient client, String data);
		bool connect(char hostname[], char path[] = "/", int port = 80);
        bool connected();
        void disconnect();
		void monitor();
		void setDataArrivedDelegate(DataArrivedDelegate dataArrivedDelegate);
		void send(String data);
	private:
        String getStringTableItem(int index);
        void sendHandshake(char hostname[], char path[]);
        EthernetClient _client;
        DataArrivedDelegate _dataArrivedDelegate;
        bool readHandshake();
        String readLine();
};


#endif

Post a link to where you got the WebSocketClient library from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Thank you for te reply.

Here is the link from where I got the example https://github.com/krohling/ArduinoWebsocketClient/tree/master/examples/EchoExample

My goal is to send data from Ethernet arduino module to ESP8266 wirelessly in a local network.

Assuming that there is a router and I'm using a private IP address at the university,I couldn't connect to the cloud using MQTT.

I tried websockets solution and started with this echo example to test the ethernet module communication.

I asked about the library, not the sketch. Where did you get the WebSocketClient library you're using?

My search returns multiple libraries of this name. If you're using an example sketch not written for the library (or library version) you're using that could definitely cause this error.

I used WebSocketClient library from this link

Firstly is it a good choice to use websockets in such situation ?

Which version of the Arduino IDE are you using? That's a very outdated library.

I'm using 1.8.5 version

Should I use simply arduino with Xbee shield to receive data from Ethernet module instead of ESP8266 ?

Here the main parts of my project:

  • Ethernet arduino module to read data from a solar controller using Modbus TCP/IP protocol.
  • Need for a wireless module to receive data from Ethernet module in a local network

Could you please give me recommendations to choose the best and simple method to ensure communication in real time between the two modules ( Etherent and wireless module ) ?

That's strange. I get a bunch of errors related to the use of unsupported PROGMEM types that haven't been usable since Arduino IDE 1.0.x. You can see the necessary fixes someone did in their fork of the library here:
https://github.com/fallafeljan/ArduinoWebsocketClient/commit/2dd5bb14fd5fe15bb2bbbc5fbe2726a62dd0c18f

Thank you for the link.

Should I post a new topic related to questions asked here

Should I use simply arduino with Xbee shield to receive data from Ethernet module instead of ESP8266 ?

Here the main parts of my project:

  • Ethernet arduino module to read data from a solar controller using Modbus TCP/IP protocol (done)
  • Need for a wireless module to receive data from Ethernet module in a local network

Could you please give me recommendations to choose the best and simple method to ensure communication in real time between the two modules ( Etherent and wireless module ) ?

Yeah, I think it's better to keep this thread only about errors encountered using the WebSocketClient library. I could probably help more with that if you decide to proceed with using this library.

Start a new thread for your questions that extend beyond the scope of that topic and hopefully that will draw in people who can answer it. I can't because I have no experience with that.

Many thanks for your help and advice !