I am trying to connect my MQTT Broker using Paho library. But now I am stucking with this error. My code is below:
import os
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt
import ssl
from configparser import ConfigParser
.....
try:
publishInfo = {
"parking": "test"
}
config = ConfigParser()
config.read('config.ini')
ipAddressMQTT = config['MQTT']['ipaddress']
port = config['MQTT']['port']
auth = {
'username': config['MQTT']['username'],
'password': config['MQTT']['password']
}
tls = {
'ca_certs': config['MQTT']['cakeypath'],
'certfile': config['MQTT']['certKeyPath'],
'keyfile': config['MQTT']['clientkeypath'],
'tls_version': ssl.PROTOCOL_TLSv1
}
publish.single(topic='parkingStatus', payload=publishInfo, retain=True, hostname=ipAddressMQTT, port=port, keepalive=60, auth=auth, tls=tls, protocol=mqtt.MQTTv311, transport='tcp')
except Exception as e:
self.showMessage(QMessageBox.Critical, "Error...", "Error "+str(e), "Error ")
and my config.ini file looks like:
[MQTT]
ipaddress = 172.18.0.3
port = 8883
username = parking
password = public
cakeypath = /home/atn/Documents/IUK/Abschlussarbeit/emqx_mqtt_cert/ca.pem
clientkeypath = /home/atn/Documents/IUK/Abschlussarbeit/emqx_mqtt_cert/parkingspot.pem
certkeypath = /home/atn/Documents/IUK/Abschlussarbeit/emqx_mqtt_cert/parkingspot.csr
[Geofence]
ipaddress = 172.18.0.4
port = 9851
The certificate was generated with the following commands:
openssl genrsa -out parkingspot.key 2048
openssl req -new -key parkingspot.key -out parkingspot.csr -subj "/C=DE/ST=NRW/L=Dortmund/O=EMQX/CN=client"
openssl x509 -req -days 3650 -in parkingspot.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out parkingspot.pem
After trying for hours, I decided to ask you guys. Give me a hand, pls.