I am a newbie to networking.

I have a Rpi-A connected to internet via 3G surf-stick and Rpi-B connected to internet via a WiFi hotspot.

I noticed that Rpi-A has a public IP address and Rpi-B has local/private IP. Both raspberry Pi's are on different networks.

I want to send binary data from Rpi-A to Rpi-B. Any suggestions on how can this be achieved?

update: I used the below code to test the MQTT connection. replacing XX.XX.XX.XX with public IP of raspberry Pi. Still I end up getting this error---> error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. what might be the possible reason for this error ? Is there anything missing in my code

import paho.mqtt.client as mqtt
import time

def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc))

client = mqtt.Client()
client.on_connect = on_connect

client.connect("xx.xx.xxx.x", 1883, 60)


while True:
  print "publish.."

If your running RPi B on a hotspot that is not controlled by you. You would either create a reverse connection from Pi B to Pi A (something like ncat should work) and send data accross that way or use something like a OpenVPN server in the cloud and route between the 2 Pi.

If you have access to the Wi-Fi hotspot configuration port forward something like ssh to Pi B. (General port 22/tcp if using the standard configuration)

  • Thank you for the answer @ITAIfs. I have access to Wi-Fi router so I can do port forwarding. I guess I need to open port 1883 since I want to use MQTT. – Spark Sep 27 '17 at 8:04

On the RPi-B's network there must be a router that is using NAT to let RPI-B connect to internet through a public address.

Like this:

enter image description here

You have to get into the configuration of that router and open an specific port (for example 22) and forward all the incoming traffic to that port to the RPi-B's IP address.

RPi-B will be accesible to the public internet through the combination of RPI-B's public IP address and port 22.

Now, from RPi-A you can use SFTP to send data to RPi-B.

  • Okay I will definitely try this and post the result. Any idea how can this be done using MQTT ? – Spark Sep 27 '17 at 7:37
  • @Spark Yes. The port for MQTT is 1883, and port 8883 is MQTT over SSL. – jcbermu Sep 27 '17 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.