I’ve been using a ESP32 device and trying to send messages to a Mosquitto Broker over SSL using the umqtt.simple library, but I keep struggling to establish the connection.
When I tried to use the client.crt and client.key files I got the “Invalid key” error.
And then I tried to convert those files to DER format and I got the “Invalid cert” error.
Those files are the same files that I use to connect using other clients, like paho-mqtt on my localhost machine, for example (except that with paho-mqtt I also used the ca.crt file)
Here is the function that is running on my ESP32:
Code: Select all
from umqtt.simple import MQTTClient
def connect_mqtt():
global client_id, mqtt_server
with open('client.key.der', 'rb') as f:
key_data = f.read()
with open('client.crt.der', 'rb') as f:
cert_data = f.read()
client = MQTTClient(client_id, mqtt_server, keepalive=120, ssl=True, ssl_params={'key':key_data, 'cert':cert_data})
client.connect()
print('Connected to %s MQTT broker' % (mqtt_server))
return client
Code: Select all
persistence true
persistence_location /mosquitto/data/
listener 8883 0.0.0.0
cafile /mosquitto/config/ca.crt
certfile /mosquitto/config/server.crt
keyfile /mosquitto/config/server.key
require_certificate false
log_dest file /mosquitto/log/mosquitto.log
Any ideas of what I might be missing here?
Thanks guys!