andrea_giordano
Posts: 6
Joined: Thu Jun 29, 2017 5:44 pm

Can't reach mqtt broker on rpi3 from external network

Mon Oct 09, 2017 8:34 am

I have a MQTT broker installed on a raspberry pi 3 running inside a network owned by a Vodafone station revolution. In order to access to raspberry from a device located out of the network I enabled port forwarding on the station mapping the fixed local ip of the raspberry with a pair of internal-external port. So linking port 1880 (node-red server on rpi) I have access from the extern of the network using the public ip of the station and the public port. At this point everything works. This lied me to think port forwarding works correctly.

I've done the operation for the mqtt broker installed on the same rpi (rpi3-mqtt in the pic). I have a python script (running on a laptop outside the network) which publish data on it with this code:

Code: Select all

mqttClient = mqtt.Client()
mqttClient.connect(host=raspberry_MQTT_ip, port=1883)
mqttClient.publish("topic/sensorLCacc", jsonData)
where raspberry_MQTT_ip is the public ip of the vodafone station. Clearly I added port 1883 to port forwarding options in the station as already done with port 1880. Unfortunately in this case, when I execute the script it raise an exception when it tries to create the connection, as the ip was not reachable.

I used telnet public_ip 1883 and the connection is established. I disabled firewall on the vodafone station. Everything works if I try to reach the mqtt broker using the local ip of the raspberry.

I attached port forwarding options of the station.
5fcpW.png
5fcpW.png (115.31 KiB) Viewed 2750 times

error trace:

Code: Select all

Traceback (most recent call last):
  File "/Users/giordano/Dropbox/Andrea/tesi/sensorsScripts/simulatedsensors/LC-accSimulation.py", line 49, in <module>
    mqttClient.connect(host=raspberry_MQTT_ip, port=1883)
  File "/Library/Python/2.7/site-packages/paho/mqtt/client.py", line 760, in connect
    return self.reconnect()
  File "/Library/Python/2.7/site-packages/paho/mqtt/client.py", line 887, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
    raise err
socket.error: [Errno 61] Connection refused
where line 49 of simulatedsensors/LC-accSimulation.py is

Code: Select all

mqttClient.connect(host=raspberry_MQTT_ip, port=1883)
Any ideas?

User avatar
jadro
Posts: 323
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: Can't reach mqtt broker on rpi3 from external network

Thu Nov 09, 2017 10:37 am

How do you call your Raspberry Pi Broker?
What is the code to connect? I think you try to call outside from local network with ip 162.168.1.201 no?
If so, you need to add dinamic DNS software!

I have reverse situation where I can connect to broker with local IP. I have No-Ip DDNS software and from out of my home network I can cal my www.url.com or whatever it is. But from home, if I call www.url.com then it can connect to it. It is router problem I think, with older router I was able to do this from home. I have my ports forwarded.
Jadro
Oracle back-end database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

User avatar
DougieLawson
Posts: 33785
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Can't reach mqtt broker on rpi3 from external network

Thu Nov 09, 2017 1:03 pm

Two problems:
1. Most of the mobile phone networks stick your IPv4 address behind a CG-NAT.
2. Most mobile phone networks won't allow in-bound connections even if you're not behind a CG-NAT.

So you're dead in the water.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Krish5757
Posts: 1
Joined: Sat Jun 23, 2018 5:26 pm

Re: Can't reach mqtt broker on rpi3 from external network

Sat Jun 23, 2018 5:37 pm

I have similar issues I have nodered server running on my pi I did port forwarding when I am connected to same wifi I can access my nodered UI with public (1024 port) as well as private ip(1880 port).but when I try to access from internet I am not able to access nodered ui.I tried disabling firewall also my router is tplink.

Thanks in advance any help is highly appreciated thank you!!

Loopiso
Posts: 5
Joined: Tue Sep 04, 2012 8:43 am

Re: Can't reach mqtt broker on rpi3 from external network

Thu Jul 05, 2018 12:58 am

Ciao, have you solved your problem? I'm in the same trouble.

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 7 guests