ArduinoWebsockets icon indicating copy to clipboard operation
ArduinoWebsockets copied to clipboard

Compilation error: 'WebsocketsClient' does not name a type ??

Open Fagge40 opened this issue 2 years ago • 4 comments

Hi. Please help me understand why I am getting this error message. The hardware is an ESP32.

"Compilation error: 'WebsocketsClient' does not name a type"

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

const char* ssid = "YourWiFiSSID"; const char* password = "YourWiFiPassword";

const char* websockets_server = "websocket-api.tibber.com"; const int websockets_port = 443; const char* websockets_path = "/v1-beta/gql/subscriptions";

const char* tibber_token = "YourTibberToken";

WebsocketsClient client;

void setup() { Serial.begin(115200);

WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); }

Serial.println("Connected to WiFi");

client.setAuthorization("Bearer " + String(tibber_token)); client.setInsecure(); client.setReconnectInterval(5000);

Serial.println("Connecting to Websockets server..."); while (!client.connect(websockets_server, websockets_port, websockets_path)) { Serial.println("Failed to connect to Websockets server"); delay(5000); }

Serial.println("Connected to Websockets server");

String subscription = "{ "type": "subscription", "query": "subscription { liveMeasurement(homeId: \"<YourHomeId>\") { timestamp power consumption } }" }"; client.send(subscription); }

void loop() { client.poll();

while (client.available()) { String data = client.readString(); Serial.println(data); } } `

Fagge40 avatar Mar 13 '23 21:03 Fagge40

You have to add the following line: using namespace websockets;

mawoka-myblock avatar Apr 10 '23 08:04 mawoka-myblock

I have the exact example copied with using namespace websockets;. I still get this error. Any ideas?

KaleRakker avatar Jul 04 '23 15:07 KaleRakker

@KaleRakker A bit late I guess but using namespace websockets; should be added before calling WebsocketsClient client;

Aditya-Bhardwaj-99 avatar Nov 08 '23 14:11 Aditya-Bhardwaj-99