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?