I have been trying to connect to the broker for a while. But I get the following error when I use the dns: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'ec2-x-x-x-x.us-east-2.compute.amazonaws.com'. (_ssl.c:1131)
When I use the ip address I get this: Error ! Result code 5
Here is my code:
import paho.mqtt.client as mqtt
devEUI = "8CF9572000023509"
appsKey = "6C1E294550045DCF651F4A33F2C01594"
appKey = "2B7E151628AED2A6ABF7158809CF4F3C"
devAddr = "005C0591"
MQTT_HOST = "ec2-x-x-x-x.us-east-2.compute.amazonaws.com"
BROKER_PORT = 2883
MQTT_KEEPALIVE_INTERVAL = 45
def on_log(client,userdata,level,buf):
print("log: ",buf)
def on_connect(client, userdata, flags, rc):
if int(rc) == 0:
print("Succesful connection")
client.subscribe("user/3/device/8cf9572000023509/uplink")
print("Error ! Result code {}".format(rc))
def on_message(client, userdata, msg):
print("ok")
client = mqtt.Client(client_id="",clean_session=True,userdata=None,transport="tcp")
client.tls_set(ca_certs="caCert.pem")
client.username_pw_set(username="xxxx",password="xxxxxxx")
client.on_log = on_log
# Define callback function for successful connection
client.connect(MQTT_HOST,BROKER_PORT,MQTT_KEEPALIVE_INTERVAL)
client.on_message = on_message
client.on_connect = on_connect
client.loop_forever()
The certificate is valid. How can I solve this problem?