You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, i have an issue in using this library on a raspberry pico w, where i need to instantiate WebSocketClient dynamically.
Please check these two snippets below, the only difference being that Code B creates a new instance of WebSocketsClient using new.
Code A
#defineUSE_SERIAL Serial1
#include<Arduino.h>
#include<WebSocketsClient.h>
#include<Hash.h>
#include<SPI.h>
#include<WiFi.h>
IPAddress dns(8, 8, 8, 8);
WebSocketsClient webSocket;
char ssid[] = "xx";
char pass[] = "xx";
int status = WL_IDLE_STATUS;
voidwebSocketEvent(WStype_t type, uint8_t *payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED: {
Serial.printf("[WSc] Connected to url: %s\n", payload);
webSocket.sendTXT("Connected");
} break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload);
break;
case WStype_BIN:
Serial.printf("[WSc] get binary length: %u\n", length);
break;
}
}
voidsetup() {
Serial.begin(115200);
while (!Serial) {
Serial.println("Serial not ready");
}
if (WiFi.status() == WL_NO_SHIELD) {
while (true){
Serial.println("WiFi shield not present");
}
}
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
WiFi.setDNS(dns);
Serial.print("Dns configured.");
webSocket.beginSSL("echo.websocket.org", 443);
webSocket.onEvent(webSocketEvent);
}
voidloop() {
webSocket.loop();
}
Code B
#defineUSE_SERIAL Serial1
#include<Arduino.h>
#include<WebSocketsClient.h>
#include<Hash.h>
#include<SPI.h>
#include<WiFi.h>
IPAddress dns(8, 8, 8, 8);
WebSocketsClient *webSocket;
char ssid[] = "xx";
char pass[] = "xx";
int status = WL_IDLE_STATUS;
voidwebSocketEvent(WStype_t type, uint8_t *payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED: {
Serial.printf("[WSc] Connected to url: %s\n", payload);
webSocket->sendTXT("Connected");
} break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload);
break;
case WStype_BIN:
Serial.printf("[WSc] get binary length: %u\n", length);
break;
}
}
voidsetup() {
Serial.begin(115200);
while (!Serial) {
Serial.println("Serial not ready");
}
if (WiFi.status() == WL_NO_SHIELD) {
while (true){
Serial.println("WiFi shield not present");
}
}
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
WiFi.setDNS(dns);
Serial.print("Dns configured.");
webSocket=newWebSocketsClient();
webSocket->beginSSL("echo.websocket.org", 443);
webSocket->onEvent(webSocketEvent);
}
voidloop() {
webSocket->loop();
}
The first one works fine, it connects and it get some text from the webserver.
The second one hangs the board stopping the execution and requiring an hard reset.
From my tests it seems it enters but never exit the webSocket->loop().
Hello, i have an issue in using this library on a raspberry pico w, where i need to instantiate WebSocketClient dynamically.
Please check these two snippets below, the only difference being that Code B creates a new instance of WebSocketsClient using
new
.Code A
Code B
The first one works fine, it connects and it get some text from the webserver.
The second one hangs the board stopping the execution and requiring an hard reset.
From my tests it seems it enters but never exit the webSocket->loop().
This is my platformio.ini
The text was updated successfully, but these errors were encountered: