Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Fagge40 opened this issue Mar 13, 2023 · 3 comments
Open

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

Fagge40 opened this issue Mar 13, 2023 · 3 comments

Comments

@Fagge40
Copy link

Fagge40 commented Mar 13, 2023

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

void loop() {
client.poll();

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

@mawoka-myblock
Copy link

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

@KaleRakker
Copy link

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

@Aditya-Bhardwaj-99
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants