How to make the connection between the broker and an external network? - mosquitto

I’m new in this field and I’m trying to create a device using arduino WiFi Rev 2 and the broker mqtt Mosquitto on an external network.
I’ve already installed Mosquitto on my PC and started it by the prompt. I changed the configuration file of Mosquitto in order to allow the listener on port 1883 and then run on prompt the command mosquitto -c mosquitto.conf -v and it worked.
But when I run netstat-a on the prompt, the port 1883 doesn’t appear on the address of the external network. What can I do to fix it ?
There’s the conf file I added
per_listener_settings true
listener 1883
protocol mqtt
allow_anonymous true
listener 8083
protocol websockets
allow_anonymous true
Thanks for the your attention, hope to find a solution!

With the configuration you have provided, mosquitto will bind to ALL addresses, this will be signified by it binding to 0.0.0.0:1883 (and 0.0.0.0:8083)
So there is nothing to fix. Assuming no firewall/NAT between the Arduino and the machine running the broker it should just connect.

Related

I can't get any data from my broker with mosquitto_sub over the internet

in localhost, my broker works great, but when I use broker IP on another device to connect over the internet that's not work,
Websocket is fine
I use this command to subscribe on topic and get the retained messages
mosquitto_sub -h *.*.*.* -p 1883 -t mrt_connections/#
in localhost and when I used VPN I get current information, but when I use broker IP to use with another device over the internet I can't get any data
this log when I used Ip over the internet
1673794013: New connection from ****.****.***.**** on port 1883.
1673794013: New client connected from ****.****.***.**** as auto-48259EF8-9CF7-9CF5-3C2C-20FA8265C33A (p2, c1, k60).
1673794013: No will message specified.
1673794013: Sending CONNACK to auto-48259EF8-9CF7-9CF5-3C2C-20FA8265C33A (0, 0)
1673794017: New connection from *.*.*.* on port 1883.
I guessed that maybe port 1883 is blocked by ISP but another broker with the same port working, I test many IP but the problem is still alive,
can anybody explain to me what is a problem
thanks
I used version 2.0.15
config file
allow_anonymous true
listener 1883 *.*.*.*
log_type all
log_dest topic
log_dest stdout
Finally, I found the problem, the port was blocked by ISP and now MQTT works fine on port 443

Publishing or subscribing data via external IP

I am running Mosquitto MQTT broker on the localhost of my PC and I want to publish or subscribe data through MQTT with Mosquitto from a remote IP (another PC). Both the PCs are connect to the same Wifi public network. I have disable the firewall of the two PCs and I am able to ping one another on command prompt. I have look up on several websites and tried editing the config file of the Mosquitto MQTT broker by adding these two lines.
listener 1883
allow_anonymous true
I have started the Mosquitto broker by executing mosquitto -c mosquitto.conf -v
The following is the log appear the mosquitto start.
C:\Program Files\mosquitto>mosquitto -c mosquitto.conf -v
1665133477: mosquitto version 2.0.15 starting
1665133477: Config loaded from mosquitto.conf.
1665133477: Opening ipv6 listen socket on port 1883.
1665133477: Opening ipv4 listen socket on port 1883.
1665133477: mosquitto version 2.0.15 running
However, on the publishing PC, it prompts the error below.
C:\Program Files\mosquitto>mosquitto_pub -h XXX.XXX.XX.X -t Test -m "Hello World" -p 8883 -d
Error: No connection could be made because the target machine actively refused it.
The situation is same for subscribing. I am currently using the latest version of Mosquitto 2.0.15. Can anyone help me on this situation? Your help would be much appreciated. Thanks in advance!

Setting up Mosquitto on home server

I'm struggling with exposing Mosquitto that I setup on my Centos7 homeserver to the outside internet through my router.
Mosquitto runs fine on my localhost and post 1883 on the homeserver. I am able to pub/sub, and it is listening on the port as 127.0.0.1:1883 (tcp)
My home router has a dynamic IP (for now), say 76.43.150.206. On the router I port forwarded 1883 as both internal/external ports to my home server, say 192.168.1.100.
In the mosquitto.conf file, I have one simply line "listener 1883 76.43.150.206".
When I then attempt to pub/sub using a python client on an external computer as mqttc.connect("76.43.150.206", 1883), it says connection refused.
Any hints on what I'm doing wrong or how to get it working? BTW, my understanding of this setup is very basic and I've pretty much been going off blogs.
Here's how it will work:
1.) Setup mosquitto.conf as
listener 1883 0.0.0.0
#cafile <path to ca file>
#certfile <path to server cert>
#keyfile <path to server key>
#require_certificate false
0.0.0.0 binds the server to all interfaces present.
You can uncomment the code to enable TLS for better security. But you'll have to configure the client to use the same as well..
2.) Port forward router's 1883 port number to port 1883 of IP of machine running the broker.
3.) Start the broker and test your client!
You should not put the external address into the mosquitto config file.
You should probably not even have a listen line at all as mosquitto will bind to all available IP addresses on the machine it's running with the default port (1883).
If you really must use the listen directive (e.g. in order to set up SSL) then it should be configured with the internal IP address of the machine running the broker, in this case 192.168.1.100 and with a different port number so it does not clash with the default
listen 1884 192.168.1.100

Cant connect to mqtt musquitto on AWS EC2 instance

When I publish and subscribe at localhost its work fine.
When I try from my PC at home I just can't connect to the broker.
open TCP port in/out at security group - 1883 8883 8080
open the ports also at my ec2 instance firewall...
what is the problem? I use the public DNS by amazon as I think I should...
This is an exercise at diagnosing network problems:
1) netstat -a -n | grep 1883
will tell you whether your broker is configured correctly
2) wireshark packet capture will tell you whether your system is receiving packets at the specific port
You will not get an answer until you at least do those.

Mosquitto MQTT Bridge Error

I am trying to bridge my local (Windows) MQTT mosquitto broker to test.mosquitto.org. Unfortunately it raises a Unknown Error.
I am using the same configuration that is used in this question
Verify that local mosquitto MQTT Broker is bridged to test.mosquitto.org
Config file:
connection test
address test.mosquitto.org
topic oust_topicst_topic out 0
try_private false
notifications false
bridge_attempt_unsubscribe true
Output:
1489747961: mosquitto version 1.4.11 (build date 20/02/2017 23:24:29.40) starting
1489747961: Config loaded from Configurations/bridge.conf.
1489747961: Opening ipv6 listen socket on port 1883.
1489747961: Opening ipv4 listen socket on port 1883.
1489747961: Bridge local.NicolasJourdan.test doing local SUBSCRIBE on topic oust_topicst_topic
1489747961: Connecting bridge test (test.mosquitto.org:1883)
1489747961: Bridge NicolasJourdan.test sending CONNECT
1489747961: Error creating bridge: Unknown error.
1489747961: Warning: Unable to connect to bridge test.
1489747969: mosquitto version 1.4.11 terminating
What could produce this error? I am not running another instance of mosquitto and test.mosquitto.org is up
First question is whether you are running a local broker or just connecting as a client.
If you are running a broker try to first run mosquitto with -c "path to config file" to see whether your config file has an error in it. Run in terminal (example on linux):
mosquitto -c /etc/mosquitto/mosquitto.conf
If there is an error the console will show it and you take it from there.
Next, try to format your topics like this (it is called topic remapping):
topic test out 0 local/ local/
Now you can publish to local/test from your code or terminal, and the message will be published to local/test on the remote broker, which will receive messages by suscribing to the same topic.
Update September 2019
The bug on Windows as described below has reportedly been fixed in version 1.6.5 of Mosquitto.
There appears to be a bug with Mosquitto running on Windows that prevents bridging from working.
On Windows the socket is not ready before Mosquitto attempts to connect.
See https://github.com/eclipse/mosquitto/issues/478 and https://github.com/eclipse/mosquitto/issues/580. This describes the underlying issue on Windows:
After checking the code I found that the statement in bridge.c .... makes a non blocking socket connect.
...
So the the next command ... sometimes fails, since the connection has not been established, as the previous connect is non-blocking.

Resources