I been trying to get my ESP8266 to connect to a websocket, but no luck so far. Things that are ruled out are:
- The ESP8266 is connected to WiFi and has access to Internet (checked using a HTTP request).
- Not a problem with the socket server, I spun up my own websocket server and it was not hit.
- Tried port 80 and 443.
My code is as follows, keeps printing
Not Connected!
:
#include <Arduino.h>
#include "WebSocketClient.h"
#include "ESP8266WiFi.h"
WebSocketClient ws(true);
void setup() {
Serial.begin(115200);
WiFi.begin("SSID", "PASSWORD");
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop() {
if (!ws.isConnected()) {
ws.connect("echo.websocket.org", "/", 80);
Serial.println("Not connected!");
} else {
ws.send("hello");
String msg;
if (ws.getMessage(msg)) {
Serial.println(msg);
}
}
delay(500);
}