I’m trying to connect an H7 Plus to a HiveMQ cloud MQTT broker. The only connection option is via TLS, and the documentation for the MQTT library pretty much says nothing about how to create a TLS connection. Through trial and error (all error thus far), I’m trying this code, but it throws a UnicodeError (which make no sense).
KEY_PATH = “uberbroker.pem”
CERT_PATH = “uberbroker.der”
with open(KEY_PATH, ‘r’) as f:
key1 = f.read()
with open(CERT_PATH, ‘r’) as f:
cert1 = f.read()
client = MQTTClient(“openmv”, “01d1669a1147487bb24c993bec906228.s2.eu.hivemq.cloud”, port=8883, ssl=True, user=“<MyUser.”, password=“”,ssl_params={ “key”:key1, “cert”:cert1, “server_side”:False })
client.connect()
I generated a private key using openssl, then generated a PEM file, then a DER file.
To generate the key:
“C:\Program Files\OpenSSL-Win64\bin\openssl” genrsa -out uberbroker.key 2048
To convert to PEM:
“C:\Program Files\OpenSSL-Win64\bin\openssl” rsa -in uberbroker.key -text > uberbroker.pem
To generate the DER file:
“C:\Program Files\OpenSSL-Win64\bin\openssl” pkcs8 -topk8 -nocrypt -in uberbroker.pem -inform PEM -out uberbroker.der -outform DER
At this point I have literally no idea what the issue might be.