gilmaimon / ArduinoWebsockets

A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
GNU General Public License v3.0
482 stars 97 forks source link

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

Open Fagge40 opened 1 year ago

Fagge40 commented 1 year ago

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

include

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: \\"\\") { timestamp power consumption } }\" }"; client.send(subscription); }

void loop() { client.poll();

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

mawoka-myblock commented 1 year ago

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

KaleRakker commented 1 year ago

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

Aditya-Bhardwaj-99 commented 1 year ago

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