Send data from PC to Raspberry PI over the internet

Thread Starter

JerryNa

Joined Feb 15, 2010
32
Hi,
I'd like to connect the Raspberry PI to router A (via Ethernet), and PC to router B (via Ethernet), and send a short message ("turn on GPIO #23) from the PC to the Raspberry PI.

Once the PC and R-PI get each an IP, how do I send a short message over the internet from the PC to the R-PI?

I believe I'd need to do that via Port 80 to avoid any blocking issue due to security - but how do i send a message from PC to R-PI via Port 80?

Thank you.
 
Last edited:

bjamis

Joined Dec 19, 2013
1
Jerry,

Check out webiopi. It is a very simple way to do exactly what you want using a web interface from the remote machine.

Lots of tutorials on how to set it up.
 

Markd77

Joined Sep 7, 2009
2,806
There's no guarantee that port 80 is not blocked by your ISP for incoming connections. Your router is almost certainly set to block incoming by default, you also need to set up the router to forward anything on port 80 to the pi, so you need to make sure the PI always has the same local IP address, you can either set the pi to have a fixed IP or set the router to always give it the same IP using DHCP.
So long as the ISP doesn't block it, it's not too difficult, but there are a few steps that need to be got right for it to work.
 

djsfantasi

Joined Apr 11, 2010
9,156
Also, realize that no matter what port you choose, you are likely to receive unexpected input. That is because hackers are always looking for open and listening ports. So your code must validate all messages.

I have a program that can control an animatronic penguin over the Internet. It uses a non-standard port as one level of defense. But since hackers will scan for ANY open port, all input is strictly validated. Thirdly, I used a dynamic DNS service to get an IP address that is not dependent on my ISP. Google for that to learn how it works.

In my case, I was looking for one way communications only. Two way will have different challenge.

Are you looking for communication from remote locations, or possibly within your house or office? If the two devices are on the same network (connect to router A and router B on the same network for example, the whole exercise may be easier. Is this the case?
 

Thread Starter

JerryNa

Joined Feb 15, 2010
32
Hi guys,
Thank you for your great comments.

Hi Djs
Thank you for sharing.

In my application -
- RPI - connected to Router A of my company in USA
- PC - connected to Router B of my company in Europe
(PCs in Europe can access PCs and USA, and vise versa - it means its the same network?)
- one way communcation is enough - PC sends to RPI "turn ON GPIO" or "turn OFF GPIO"

How would you handle the application?

After spending a lot of reading, I'm thinking of setting up light webserver on the RPI, perhaps create an On/Off button using PHP, and the PC will press the button when it wishes, and the RPI will poll for the button's status.
 

djsfantasi

Joined Apr 11, 2010
9,156
If the PCs in both locations can access each other, then they are either on the same network, or you don't need to worry about routing through the public Internet.

Do both devices have or can be assigned a static IP address? If so, it can be easy to communicate. Just hardcode the destination address in the sending device.
 

Markd77

Joined Sep 7, 2009
2,806
On the pi, type ifconfig, you should get something like this:
inet addr:192.168.0.13
That's your local IP address (local could include anything on your companies internal network)
On the PC in Europe, type ping 192.168.0.13 (or whatever it is) and if you get success then you just need to make sure the pi keeps the same IP address, and get port 80 unblocked and forwarded to the PI on the European router. If the European router has a webserver attached to it already things get a bit trickier, might want to change to a different port to avoid taking down your website.
 

Thread Starter

JerryNa

Joined Feb 15, 2010
32
Thank you guys.

I currently don't have the RPI installed, but -
I pinged from Europe PC to USA PC, using the 10.*.*.* local IP Address of the USA PC,
and the Europe PC got replies from the USA PC,
so it seems I don't need to use the public internet, right? (the USA R-PI will be connected to same router of the USA PC).

I only need one-way communcation - from many PCs to the USA R-PI - so all I'd need to do is set Static IP Address for the R-PI, right?

Regarding how to actually send a message from many PCs in Europe office to the RPI in USA.

There will be several RPIs worldwide eventually, in different countries in EU and USA.

So, How should I transfer packets to the USA RPI from the Europe PCs?

In every Router which has R-PI connected, I should forward all incoming packets for a specifc port to the R-PI?

I don't think I could use Port-80, because the other PCs connected to the USA Router (to which the R-PI is connected) should also be able to surf the web and I'm afraid if I set the USA Router to forward all incoming Port-80 traffic to the R-PI, it'd interfere with their operation.
 

djsfantasi

Joined Apr 11, 2010
9,156
I currently don't have the RPI installed, but -
I pinged from Europe PC to USA PC, using the 10.*.*.* local IP Address of the USA PC, and the Europe PC got replies from the USA PC, so it seems I don't need to use the public internet, right? (the USA R-PI will be connected to same router of the USA PC).
That particular form of the IP address is not a public address, so your assumption is likely correct.

I only need one-way communcation - from many PCs to thoe USA R-PI - so all I'd need to do is set Static IP Address for the R-PI, right?
Right!

Regarding how to actually send a message from many PCs in Europe office to the RPI in USA.

There will be several RPIs worldwide eventually, in different countries in EU and USA.

So, How should I transfer packets to the USA RPI from the Europe PCs?

In every Router which has R-PI connected, I should forward all incoming packets for a specifc port to the R-PI?
Not necessarily. Since you know the IP address of the Pi, the routing will be automatic. The issue is how locked down your routers are. They may not allow your selected port through. In that case, rules on the routers would have to be added to allow that port through.

We have been talking about routers. Some of these configurations may be defined on a router, but you also may have firewalls in the network path. Rules to allow access may need to be defined there as well.

I don't think I could use Port-80, because the other PCs connected to the USA Router (to which the R-PI is connected) should also be able to surf the web and I'm afraid if I set the USA Router to forward all incoming Port-80 traffic to the R-PI, it'd interfere with their operation.
In this case, it is not the PCs connected surfing the web that would be affected. Surfing the web does not require incoming traffic on port 80. It is if you have any web sites on the internal network that would be affected. Even then, with the proper configuration it could be done, but ignore that scenario for now.

I am curious if you have several PCs connecting to the Pi, how are you identifying from which one the data is coming?
 

nerdegutta

Joined Dec 15, 2009
2,684
I am curious if you have several PCs connecting to the Pi, how are you identifying from which one the data is coming?
Just jumping in, with a thought after reading...

Is the R-PI receiving commands from one PC at the time, or are multiple users sending commands simultaneously?
 
Top