I have setup mosquitto on docker (raspberry pi 4) using certificates to secure the connection. I have no username and password configured in mosquitto. I am using this code to connect my wemos d1 mini to mosquitto with pubsubclient.
I do not use the secrets.h file, but I tried it before with the same result.
After inserting my credentials, mqtt data and ca.crt i get the following serial output:
Attempting to connect to SSID: MYSSID ... connected!
Setting time using SNTP.done!
Current time: Wed Feb 19 13:53:17 2020 Time: Wed Feb 19 13:53:17 2020
MQTT connecting ... failed, status code =-2. Try again in 5 seconds.
MQTT connecting ... failed, status code =-2. Try again in 5 seconds.
MQTT connecting ... failed, status code =-2. Try again in 5 seconds.
mosquitto gives the following log:
1582138400: New connection from 192.168.0.8 on port 8883.
1582138405: Socket error on client <unknown>, disconnecting.
1582138405: New connection from 192.168.0.8 on port 8883.
1582138413: New connection from 192.168.0.8 on port 8883.
1582138418: Socket error on client <unknown>, disconnecting.
1582138418: New connection from 192.168.0.8 on port 8883.
1582138424: Socket error on client <unknown>, disconnecting.
1582138424: New connection from 192.168.0.8 on port 8883.
1582138429: Socket error on client <unknown>, disconnecting.
1582138429: New connection from 192.168.0.8 on port 8883.
1582138434: Socket error on client <unknown>, disconnecting.
1582138435: New connection from 192.168.0.8 on port 8883.
1582138440: Socket error on client <unknown>, disconnecting.
1582138440: New connection from 192.168.0.8 on port 8883.
1582138443: Client <unknown> has exceeded timeout, disconnecting.
At least I get the last line: disconnected because of timeout. And 192.168.0.8 is the wemos D1 mini. I used the MQTTfx to connect to mosquitto with the ca.crt file before and it worked fine.
my mosquitto.conf:
allow_anonymous true
port 8883
cafile /ca.crt
keyfile /server.key
certfile /server.crt
tls_version tlsv1.2
persistence true
persistence_location /mosquitto/data/
why does mosquitto not recognise the client name that I have specified in the code? Why can I not connect to mosquitto? And how can I solve this?
I have also tried it with username and password with the same result!