How to setup MQTT over SSL with ESP IDF
Posted: Thu Jun 02, 2022 9:57 pm
Description
We are trying to setup ESP IDF to connect with the build in MQTT server of thingsboard. We have setup the certificates as suggested in the tutorial by thingsboard with self signed certicates https://thingsboard.io/docs/user-guide/ ... generation. We can connect using MQTT explorer on a windows machine. I expect we need to do a mutual on the ESP side but whatever we have tried so far we can't connect.
As mentioned above the ESP IDF suggests https://docs.espressif.com/projects/esp ... t.html#ssl getting the cert_pem option by getting this using the following command
Of course the url here is replaced with our own. This certificate is then used as .cert_pem.
The error we are currently getting from ESP-MQTT is 0x8008 https://docs.espressif.com/projects/esp ... codes.html.
Environment
OS: Ubuntu + Docker
ThingsBoard: Latest (v3.3.4.1)
ESP-IDF: Stable (4.4.1)
Dockerfile (using a proxy for http(s)):
We are trying to setup ESP IDF to connect with the build in MQTT server of thingsboard. We have setup the certificates as suggested in the tutorial by thingsboard with self signed certicates https://thingsboard.io/docs/user-guide/ ... generation. We can connect using MQTT explorer on a windows machine. I expect we need to do a mutual on the ESP side but whatever we have tried so far we can't connect.
- esp_mqtt_client_config_t clientConfig = {
- .host = MQTT_HOST,
- .port = 8883,
- .client_id = NULL,
- .username = username,
- .disable_auto_reconnect = true,
- .user_context = context,
- .cert_pem = "-----BEGIN CERTIFICATE-----\n" // openssl command as suggested on ESP IDF
- "..."
- "-----END CERTIFICATE-----\0",
- .transport = MQTT_TRANSPORT_OVER_SSL,
- .skip_cert_common_name_check = true,
- };
- openssl s_client -showcerts -connect mqtt.eclipseprojects.io:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >mqtt_eclipse_org.pem
The error we are currently getting from ESP-MQTT is 0x8008 https://docs.espressif.com/projects/esp ... codes.html.
Environment
OS: Ubuntu + Docker
ThingsBoard: Latest (v3.3.4.1)
ESP-IDF: Stable (4.4.1)
Dockerfile (using a proxy for http(s)):
- version: '3'
- services:
- thingsboard:
- restart: unless-stopped
- image: thingsboard/tb-postgres
- environment:
- - TB_QUEUE_TYPE=in-memory
- - TZ=Europe/Amsterdam
- - MQTT_SSL_ENABLED=true
- - MQTT_SSL_CREDENTIALS_TYPE=PEM
- - MQTT_SSL_PEM_CERT=/certs/server.pem
- - MQTT_SSL_PEM_KEY=/certs/server_key.pem
- - MQTT_SSL_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT=true
- volumes:
- - type: bind
- source: ./thingsboard/data
- target: /data
- - type: bind
- source: ./thingsboard/logs
- target: /var/log/thingsboard
- - type: bind
- source: ./thingsboard/certs
- target: /certs
- ports:
- - 1883:1883
- - 8883:8883
- - 7070:7070
- - 5683-5688:5683-5688/udp