0
votes

I have installed Mosquitto on a brand new Raspberry Pi. OS is Raspbian. I followed the instructions on the Owntracks website.

The broker is listening on port 1883 on localhost. Using a username and password I can run mosquitto_sub in one ssh session to the Pi, and receive messages sent by mosquitto_pub from another ssh session.

The broker is also listening on port 8883. I created certificates using the script in the Owntracks repository.

When I run mosquitto_pub on the Pi, using the hostname or IP-address I get an error "Error: Connection refused". When I use localhost or 127.0.0.1 the error is "A TLS error occurred.".

If I run mosquitto_pub on my desktop computer (which is in the same LAN as the Pi), the error is "Connection refused". The command I run here is

mosquitto_pub -t owntracks/test -m Test -h pi1 --cafile ca.crt

where pi1 is the hostname of the Pi running the broker. The ca.crt file is copied from the Pi to the desktop computer.

The Mosquitto log is not showing why the connections are refused.

The TLS setup in the Mosquitto config looks like this:

listener 1883 127.0.0.1

listener 8883

cafile /etc/mosquitto/ca_certificates/ca.crt

certfile /etc/mosquitto/certs/server.crt

keyfile /etc/mosquitto/certs/server.key

require_certificate false

What is wrong in my setup?

2

2 Answers

0
votes

if you try to use TLS with mosquitto you must add this option to your command "-p 8883" to indicate the port and you don't need to put "-h localhost or pi " because you use the client command mosquitto_pub in the same machine that run mosquitto broker then your command we'll be : "mosquitto_pub -d -u username -P password -t /path/to/the/topic --cafile /path/to/the/certificate -p 8883 don't forgot to comment this line

listener 1883

in your mosquitto.conf

0
votes

Recreating all certificates solved the problem. Apparently I did something wrong with including local vs. remote IP-addresses and host names. The TLS error messages are not very informative, but that probably has to do with security precautions.