theelims / PsychicMqttClient

Fully featured asynchronous Arduino MQTT client for ESP32 with full support for SSL/TLS and MQTT over websocket
MIT License
18 stars 2 forks source link

MQTT via WebSokect secure cannot works well #7

Open renkun opened 1 week ago

renkun commented 1 week ago

I tried with MQTTS and MQTT via ws, it works well with PsychicMqttClient. However, as secure issue, my live server only support MQTT vi wss. I tried different ways with PsychicMqttClient, but it always report SSL issue (with same SSL works well with MQTTS). please see below logs:

[ 5377][I][main.cpp:121] setup(): Client Successfully connected to server! [ 6385][I][main.cpp:165] setup(): start MQTT Connect... [ 6392][I][[0t]m ther event id:7 E (6626) esp-tls-mbedtls: No server verification option set in esp_tls_cfg_t structure. Check esp_tls API reference E (6626) esp-tls-mbedtls: Failed to set client configurations, returned [0x8017] (ESP_ERR_MBEDTLS_SSL_SETUP_FAILED) E (6636) esp-tls: create_ssl_handle failed E (6639) esp-tls: Failed to open new connection E (6643) TRANSPORT_BASE: Failed to open a new connection E (6650) TRANSPORT_WS: Error connecting to host test.mosquitto.org:8091 E (6655) MQTT_CLIENT: Error transport connect [ 6841][I][PsychicMqttClient.cpp:528] _onError(): [PsychicMqttClient] MQTT_EVENT_ERROR [ 6861][E][PsychicMqttClient.cpp:9] log_error_if_nonzero(): [PsychicMqttClient] Last error reported from esp-tls: 0x8017 [ 6872][I][PsychicMqttClient.cpp:534] _onError(): [PsychicMqttClient] Last errno string (Success) [ 6882][I][PsychicMqttClient.cpp:410] _onDisconnect(): [PsychicMqttClient] MQTT_EVENT_DISCONNECTED

theelims commented 1 week ago

Can you please share how you include the certificates? It seems to fail at the authentication step. Which version of the ESP-IDF you are using?

You can check the docs whether the mqtt_config struct has some settings that could help with your problem. With getMqttConfig() you can access and modify it.

renkun commented 5 days ago

Thank you very much @theelims, I tried again and use the crt bundle and follow the example SSL_CA_Bundle_WiFiClientSecure, it works well now. Now it works well with MQTT via wss!!! Thank you again!