Open Fagge40 opened 1 year ago
You have to add the following line: using namespace websockets;
I have the exact example copied with using namespace websockets;
. I still get this error. Any ideas?
@KaleRakker A bit late I guess but using namespace websockets;
should be added before calling WebsocketsClient client;
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); } } `