-
Notifications
You must be signed in to change notification settings - Fork 99
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
unable to connect to wss with esp32 #101
Comments
Hi! I'm not actually sure, this might be a bug if you say it worked with earlier version of the esp libraries. Just to make sure I understand you, what do you mean by Consider sharing the relevant parts of your code, and double checking your setup.. Gil. |
on PlatformIO is called platform "Espressif 32" , 3.1 obviously is the version. The code :
|
I have the same issue, I used the Secured-Esp32-Client.ino example. Replaced |
Hi @doublep21, thanks for opening this issue and including your code. I suspect that the issue with your code is this commented line: // client.setCACert(ssl_ca_cert); You must provide some kind of certificate for the server you are connecting to (if it is done using SSL [wss]). Insecure connection might be unsupported for newer versions of the framework, as @JasXSL mentioned. This could be a nice feature to add (to remove the Gil. |
So the new ESP version is blocking the setInsecure method? |
If you're using
This is the terminal output when using new SSL Cert
Please also check the solved issue in Secured-Esp32-Client Example not works on NodeMcu32s (Esp32s) #16 |
Awesome! Do you like to open a PR and change the certificate in the example? I can do it myself, but I think you should get the credit. |
I've created a PR for the lib WebSockets2_Generic wich solve this problem => khoih-prog/WebSockets2_Generic#18 like the lib is based on this lib, the porting of it is really easy. Do you want me to create a PR for this for your lib ? |
I can also not connect to a secured websocket using the following code: #include <ArduinoWebsockets.h>
#include <WiFi.h>
const char* ssid = "XXX"; //Enter SSID
const char* password = "XXX"; //Enter Password
const char* websockets_connection_string = "wss://echo.websocket.org/"; //Enter server adress
const char echo_org_ssl_ca_cert[] PROGMEM = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIFMTCCBBmgAwIBAgISA+YsE2kLGzw6wgvSftCq4+JOMA0GCSqGSIb3DQEBCwUA\n" \
"MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD\n" \
"EwJSMzAeFw0yMTA1MjQxOTM1MzRaFw0yMTA4MjIxO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sgiaN9kTAAABeaAXBpYAAAQD\n" \
"AEgwRgIhAPMeO7rzATtXB6U/+nbTHSDYS9mmZmy8oNa0OecCRNVkAiEA1SkPJX6I\n" \
"w3+UjtI8McOKSXjoVS6QL7QtaDRMxDm0W10AdQD2XJQv0XcwIhRUGAgwlFaO400T\n" \
"GTO/3wwvIAvMTvFk4wAAAXmgFwcJAAAEAwBGMEQCIC/Mm6/4C09aTpvpdg9bcJ+R\n" \
"dn8H5a47q+k9IbDL0h/sAiB4zMDuivp8ohxf3B24w/gBmVy0V8JgTSHDWPbctnwq\n" \
"8DANBgkqhkiG9w0BAQsFAAOCAQEAgEh0VR4F44La1CbCMstxPDE/aTvirg+odT+f\n" \
"9U3SnsjDpBlifbOe/nby1EIHfwJ+h6sXCwsy9IupbNC8QkUO6Xb1eIstTxS/PhdV\n" \
"i9URTqIqOXgRHWfPGzuYjeQQIlsS/B0ma7NWeAzyipfrFVSt3AGKMZDox+ohbAyA\n" \
"Kqzbg193BrgBhNjtD4DpHbo2OXjcsXjneI6yNruQP8hwpucPb1E4pam3+h4zH6uv\n" \
"qzeCo2EqimtRsWlGbcLpY0t40Hlpa5jaV6pOiJFGqqMkJtiThgB03ycGp0TpG65Q\n" \
"DuXzWnD/cBQaSQ3kBu6KuYwTxftJNrCs0ANJLxjrhvC4r6Af/A==\n" \
"-----END CERTIFICATE-----\n";
using namespace websockets;
void onMessageCallback(WebsocketsMessage message) {
Serial.print("Got Message: ");
Serial.println(message.data());
}
void onEventsCallback(WebsocketsEvent event, String data) {
if(event == WebsocketsEvent::ConnectionOpened) {
Serial.println("Connnection Opened");
} else if(event == WebsocketsEvent::ConnectionClosed) {
Serial.println("Connnection Closed");
} else if(event == WebsocketsEvent::GotPing) {
Serial.println("Got a Ping!");
} else if(event == WebsocketsEvent::GotPong) {
Serial.println("Got a Pong!");
}
}
WebsocketsClient client;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
// Wait some time to connect to wifi
for(int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
Serial.print(".");
delay(1000);
}
// Check if connected to wifi
if(WiFi.status() != WL_CONNECTED) {
Serial.println("No Wifi!");
return;
}
client.setCACert(echo_org_ssl_ca_cert);
Serial.println("Connected to Wifi, Connecting to server.");
// try to connect to Websockets server
bool connected = client.connect(websockets_connection_string);
if(connected) {
Serial.println("Connected!");
client.send("Hello Server");
} else {
Serial.println("Not Connected!");
}
// run callback when messages are received
client.onMessage([&](WebsocketsMessage message){
Serial.print("Got Message: ");
Serial.println(message.data());
});
}
void loop() {
// let the websockets client check for incoming messages
if(client.available()) {
client.poll();
}
delay(500);
} I downloaded the current certificate from the website: echo | openssl s_client -servername echo.websocket.org -connect echo.websocket.org:443
I only get the following output:
|
I̶ ̶a̶l̶s̶o̶ ̶t̶e̶s̶t̶e̶d̶ ̶t̶h̶e̶ ̶l̶a̶t̶e̶s̶t̶ ̶v̶e̶r̶s̶i̶o̶n̶ ̶[̶2̶.̶0̶.̶0̶ ̶R̶C̶1̶]̶(̶h̶t̶t̶p̶s̶:̶/̶/̶g̶i̶t̶h̶u̶b̶.̶c̶o̶m̶/̶e̶s̶p̶r̶e̶s̶s̶i̶f̶/̶a̶r̶d̶u̶i̶n̶o̶-̶e̶s̶p̶3̶2̶/̶r̶e̶l̶e̶a̶s̶e̶s̶/̶t̶a̶g̶/̶2̶.̶0̶.̶0̶-̶r̶c̶1̶)̶,̶ ̶b̶u̶t̶ ̶i̶t̶ ̶d̶o̶e̶s̶n̶'̶t̶ ̶w̶o̶r̶k̶ e̶i̶t̶h̶e̶r̶.̶ ̶T̶h̶e̶ ̶[̶W̶e̶b̶S̶o̶c̶k̶e̶t̶s̶2̶_̶G̶e̶n̶e̶r̶i̶c̶]̶(̶h̶t̶t̶p̶s̶:̶/̶/̶g̶i̶t̶h̶u̶b̶.̶c̶o̶m̶/̶k̶h̶o̶i̶h̶-̶p̶r̶o̶g̶/̶W̶e̶b̶S̶o̶c̶k̶e̶t̶s̶2̶_̶G̶e̶n̶e̶r̶i̶c̶)̶ ̶l̶i̶b̶r̶a̶r̶y̶ ̶i̶s̶ ̶a̶l̶s̶o̶ ̶n̶o̶t̶ ̶w̶o̶r̶k̶i̶n̶g̶ ̶f̶o̶r̶ ̶m̶e̶,̶ ̶s̶o̶ m̶a̶y̶b̶e̶ ̶i̶t̶ ̶h̶a̶s̶ ̶t̶o̶ ̶d̶o̶ ̶s̶o̶e̶m̶t̶h̶i̶n̶g̶ ̶w̶i̶t̶h̶ ̶t̶h̶e̶ ̶b̶o̶a̶r̶d̶ ̶r̶e̶v̶ ̶o̶r̶ ̶s̶o̶?̶ I finally found the answer thanks to this comment. I was using the first certificate, but the second was needed. Sorry, my bad. The right command is: $ openssl s_client -showcerts -connect websocket.org:443 |
unable to connect to wss with esp32 after porting all project to a new pc , i think is a new version of something the issue .
i don't have a ca certificate in the code , before was working fine without.
[V][ssl_client.cpp:265] stop_ssl_socket(): Cleaning SSL connection.
[V][ssl_client.cpp:265] stop_ssl_socket(): Cleaning SSL connection.
[V][ssl_client.cpp:59] start_ssl_client(): Free internal heap before TLS 257808
[E][WiFiClientSecure.cpp:127] connect(): start_ssl_client: -1
[V][ssl_client.cpp:265] stop_ssl_socket(): Cleaning SSL connection.
[E][WiFiClient.cpp:309] setOption(): fail on fd -1, errno: 9, "Bad file number"
with esperiff 2.0 works fine
qith esperiff 3.1 do not work
is this a bug?
The text was updated successfully, but these errors were encountered: