Arduino with mosquitto mqtt - mqtt

When I ran the Mosquitto (MQTT) broker for the first time there was no issue. However when running it for the second time using the default config I could not run the code successfully because of the following error on Windows 8:
1379497253: mosquitto version 1.2 (build date 2013-09-17 17:59:39+0530) starting 1379497253: Using default config. 1379497253: Opening ipv6 listen socket on port 1883. 1379497253: Error: Address already in use
How can I resolve this error, or more importantly what does this error mean?

Address already in use usually means that the port (in your case 1883) is already being used by another process. The most likely situation given your description is that another copy of mosquitto is already running. If you want to run two (or more) you'll need to configure each to use a separate port number.

You have to check the mosquitto.conf in a bin folder in which you installed the mosquitto server.
Make sure all lines are commented with '#' especially the following line,
port 1883 or listener 1883.
then, find some available port or whether the port 1883 is used by using command like netstat.
In windows, you can use this,
netstat -an| findStr 1883
You have to change your default port on mosquitto when found any message from the prompt.
Append some specific number on the line below which is indicating the port whatever you prefer to.
listener XXX
protocol mqtt

Related

Paho C++ MQTT Client unable to connect to Mosquitto on Ubuntu Docker Image (Python Client Works)

I am facing this issue for a couple of days and I am unable to reproduce it outside the Ubuntu Docker container.
Please refer to this simplified diagram of my architecture:
As you can see, I have everything running inside the Docker container.
This is not the typical issue of not being able to connect to inside the container, the whole application runs on the local network of the Docker container.
The Ubuntu Image is the official one with just some packages installed so that everything works (nothing too fancy, just python3 and some c++ tools).
It is running Mosquitto 2.0.15 with the following configuration:
listener 1883
protocol mqtt
allow_anonymous true
log_dest file /home/user/mosquitto.log
So, in summary, I am running an unsecured MQTT broker in the default port 1883. I also added a log file in an attempt to debug what is going on.
On my Python Client, the connection is made in the simplest way possible:
...
self.mqtt_client = mqtt.Client(client_id="Client Id")
self.mqtt_client.connect("localhost", 1883, 6000)
...
self.mqtt_client.loop_start()
...
This Client is able to connect to the broker with no issue at all.
Subscribe and Publish works perfectly too!
On my C++ Client, I try to keep it simple as well:
...
mqtt::async_client MQTTClient("tcp://localhost:1883", "Another Client Id");
MQTTClient.connect()->wait();
...
Yet, this Client fails every attempt to connect to the broker:
terminate called after throwing an instance of 'mqtt::exception'
what(): MQTT error [-1]: TCP/TLS connect failure
Aborted (core dumped)
Although it looks like a SSL/TLS error, this is actually the generic error for when the MQTT broker is not found (If I stop the broker on my local machine I get the same error).
Checking the MQTT broker logs (verbose ON), it does not record anything regarding the attempt to connect from C++ Client:
1672874968: mosquitto version 2.0.15 starting
1672874968: Config loaded from /etc/mosquitto/conf.d/default.conf.
1672874968: Opening ipv4 listen socket on port 1883.
1672874968: mosquitto version 2.0.15 running
(I do get log messages when connecting with Python Client)
On my own Linux machine I am unable to reproduce this issue. Both clients work fine.
I am using the same configuration for the Mosquitto broker and the Clients are exactly the same.
Already tried to play with the IP used to connect to the broker (localhost/127.0.0.1/0.0.0.0) and using different ports, the result is the same.
It is weird that the Python Client can connect with no issue at all.
At this point, I am fairly confident that the issue must be something Docker-specific and how it handles TCP sockets. But I am unable to find anything helpful online.
I can easily check that the port is open:
lsof -i -P -n | grep :1883
mosquitto 56 user 5u IPv4 1633274841 0t0 TCP 127.0.0.1:1883 (LISTEN)
Any ideas what is going on? Or debug tools ideas?
Thanks in advance!
I have tried:
Playing with IP and port of the broker;
Stating the preferable MQTT version (tried with every version);
Run Client with strace and try to find something unusual;
Verify if I am running the exact same Client as my Linux machine;
I finally found out what my issue was.
I had a HTTP proxy configured and Paho C will automatically use this proxy.
It is detecting by checking if "http_proxy" environment variable is set.
My solution was simply unset this variable:
unset http_proxy
Interestingly, the Python MQTT client does not have this behavior.
And for that reason, it worked perfectly!

Error code 80c6 occurs when tia portal connects to mosquitto broker [duplicate]

I have a virtual machine that is supposed to be the host, which can receive and send data. The first picture is the error that I'm getting on my main machine (from which I'm trying to send data from). The second picture is the mosquitto log on my virtual machine. Also I'm using the default config, which as far as I know can't cause these problems, at least from what I have seen from other examples. I have very little understanding on how all of this works, so any help is appreciated.
What I have tried on the host machine:
Disabling Windows defender
Adding firewall rules for "mosquitto.exe"
Installing mosquitto on a linux machine
Starting with the release of Mosquitto version 2.0.0 (you are running v2.0.2) the default config will only bind to localhost as a move to a more secure default posture.
If you want to be able to access the broker from other machines you will need to explicitly edit the config files to either add a new listener that binds to the external IP address (or 0.0.0.0) or add a bind entry for the default listener.
By default it will also only allow anonymous connections (without username/password) from localhost, to allow anonymous from remote add:
allow_anonymous true
More details can be found in the 2.0 release notes here
You have to run with
mosquitto -c mosquitto.conf
mosquitto.conf, which exists in the folder same with execution file exists (C:\Program Files\mosquitto etc.), have to include following line.
listener 1883 ip_address_of_the_machine(192.168.1.1 etc.)
By default, the Mosquitto broker will only accept connections from clients on the local machine (the server hosting the broker).
Therefore, a custom configuration needs to be used with your instance of Mosquitto in order to accept connections from remote clients.
On your Windows machine, run a text editor as administrator and paste the following text:
listener 1883
allow_anonymous true
This creates a listener on port 1883 and allows anonymous connections. By default the number of connections is infinite. Save the file to "C:\Program Files\Mosquitto" using a file name with the ".conf" extension such as "your_conf_file.conf".
Open a terminal window and navigate to the mosquitto directory. Run the following command:
mosquitto -v -c your_conf_file.conf
where
-c : specify the broker config file.
-v : verbose mode - enable all logging types. This overrides
any logging options given in the config file.
I found I had to add, not only bind_address ip_address but also had to set allow_anonymous true before devices could connect successfully to MQTT. Of course I understand that a better option would be to set user and password on each device. But that's a next step after everything actually works in the minimum configuration.
For those who use mosquitto with homebrew on Mac.
Adding these two lines to /opt/homebrew/Cellar/mosquitto/2.0.15/etc/mosquitto/mosquitto.conf fixed my issue.
allow_anonymous true
listener 1883
you can run it with the included 'no-auth' config file like so:
mosquitto -c /mosquitto-no-auth.conf
I had the same problem while running it inside docker container (generated with docker-compose).
In docker-compose.yml file this is done with:
command: mosquitto -c /mosquitto-no-auth.conf

Cant connect to External IP

I'm trying to connect to my public IP http://34.125.119.106:8080/, where I have a Jenkins service running but I can't and don't know why.
I've create firewall rule to allow tcp traffic on port 8080, which is the port exposed to Jenkins, but I still cannot connect. I looked into the /etc/default/jenkins file, to see if everything inside was configured correctly. I tried to line in this file like 'HTTP_HOST=127.0.0.1', like some people advise to do ,but it doesn't work for my case. Does anyone know how to solve this?
Sorry for my bad English.
enter image description here
i made a test and it successfully connected,but i still cant connect to my external Ip
Use the default settings, because HTTP_HOST=127.0.0.1 locks you out:
HTTP_HOST=0.0.0.0
HTTP_PORT=8080
HTTPS_HOST=0.0.0.0
HTTPS_PORT=443
Listing to all interfaces with 0.0.0.0 is fine, but HTTP_PORT should be -1.
As a first step my recommendation is to check if your service is exposed and through what port number. For this you can use command sudo netstat -plntu. You should be looking for an output similar to:
tcp6 0 0 :::8080 :::* LISTEN 17917/java
If its not, change your /etc/default/jenkins file to port 8080
After that from inside your GCP project, you can run a connectivity test having as source one of the IP addresses you are using to reach your Server and as destination your Servers VM instance IP address. This test will simulate traffic and tell you where it's getting stuck whether if it's stuck on the way to your Server or if your server is not correctly configured. You can get a good reference in this document.
If you have already configured your ingress firewall rule, just make sure its applied to your VM, it sometimes happens that you have a network tag on your VM instance and another tag on your firewall rule.

Sonoff RF Bridge to Mosquitto (on Windows) Configuration

I've been searching high and low for a simple explanation for this. What configuration settings do I use to connect my Sonoff RF bridge to the Mosquitto server on my computer? I'm sure it's a configuration issue but most of the tutorials out there are for rPi. My skill level in this is basic and I'm sure it may be obvious to someone what's wrong.
I'm running Mosquitto on Windows 10 and have verified that the Mosquitto server is running using netstat -a (I can see the broker is listening at 0.0.0.0:1883.
I've installed Tasmota Eclipse on my Sonoff RF Bridge and have verified it is receiving signal from my door sensor by opening the UI in my browser and viewing the console. I've tried multiple host addresses in the configuration menu; localhost, 0.0.0.0, 10.0.0.1, however Tasmota only seems to connect when I leave the host field blank.
I've tried to use MQTTlens to verify that the broker is receiving messages on port 1883 and nothing seems to be coming through.
0.0.0.0 is a short hand to tell mosquitto to listen on all the available interfaces on the machine it is running on. It is meaningless to use it in the client configuration.
Likewise, localhost always means the same machine that the code making the request is running on, so in this case it would be the Sonoff device it's self.
It looks like 10.0.0.1 is the address of your local router, unless mosquitto is actually running on the router (it is very unlikely your windows machine is your router) this again is not going to be useful.
You need to use the IP address of the Windows machine that mosquitto is running on, this is going to start with 10.0.0. running ipconfig on the command line in windows is probably the quickest/simplest way to find that address.

HiveMQ error when I run it: Could not bind to all interfaces and port 1883, because it is already in use

I'm developing an MQTT based application using HiveMQ, an enterprise broker. I installed it as per the instructions here- http://www.hivemq.com/docs/hivemq/2.0.1/
When I run it using ./bin/run.sh, the server connection is immediately closed due to the error - Could not bind to all interfaces and port 1883, because it is already in use. Stopping HiveMQ
As far as I'm aware, nothing else is using this port. This happens even when I restart my computer and nothing else is running. I'm running in root mode.
Why am I getting this error?
To check if something is already running on the port, please type the following into the terminal if you happen to run a Linux / BSD / OSX:
netstat -an|grep 1883
If you're running a Windows System, type the following:
netstat -an|find "1883"
After running that command you should see which application is using port 1883.
Alternatively you could edit the configuration.properties file in you conf folder of the HiveMQ installation and set the global.port property to a port of your choice.
From those results, do you have d-bus daemon installed? I don't know much about d-bus, but have you tried disabling it or modifying the config and then see if you can restart hivemq on port 1883.

Resources