3D224
Posts: 2
Joined: Fri Jul 05, 2019 10:58 am

How to control several Raspberry pi s from faraway ( From UK to India)

Mon Jul 29, 2019 9:26 am

Hi,

I am a PhD student in UK, as part of my project I need to install around 12 air quality measuring devices ( raspberry pi + 5 different sensors) in some schools in India.
The devices will be connected to the schools' WiFi.
I need to know how can I control the devices if some issues happen. I need to know the IP address of the specific Raspberry pi 's that have that issue and be able to fix it from UK.

Thanks in Advance for you support.

User avatar
B.Goode
Posts: 8849
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to control several Raspberry pi s from faraway ( From UK to India)

Mon Jul 29, 2019 10:34 am

Welcome to the Raspberry Pi forums.


3D224 wrote:
Mon Jul 29, 2019 9:26 am
Hi,

I am a PhD student in UK, as part of my project I need to install around 12 air quality measuring devices ( raspberry pi + 5 different sensors) in some schools in India.
The devices will be connected to the schools' WiFi.
I need to know how can I control the devices if some issues happen. I need to know the IP address of the specific Raspberry pi 's that have that issue and be able to fix it from UK.

Thanks in Advance for you support.


Official Raspberry Pi documentation about Remote Access can be found here: https://www.raspberrypi.org/documentati ... te-access/


It may be worth noting that using RealVNC (installed as part of the Raspbian Operating System) does not require you to know the IP addresses of the remote devices. That is significant because otherwise accessing an individual RPi device on a remote school network will need cooperation from the network administrator in each school to modify their boundary router configuration.

Of course, any plan to offer remote fault fixing requires that the target device be up and running and communicating via the network... Some 'issues' may prevent that.

User avatar
emsquared
Posts: 9
Joined: Tue May 15, 2018 9:58 am
Location: Atlanta, GA
Contact: Website

Re: How to control several Raspberry pi s from faraway ( From UK to India)

Mon Jul 29, 2019 5:11 pm

Summary: Set up a public server. Then have the Raspberry Pi's ssh into the public server with a reverse ssh tunnel. Then ssh into your public server, and hop from there to any of the Raspberry Pi's.

Here's how:

Have the Pi's connect to the public server. That way you don't have to worry about getting through a firewall to get to your Pi's. Note that each of the Pi's should have a unique reverse port number, say 4001 through 40012 for example.

Here's the connection code for one of the Raspberry Pi's that must automatically run when the Pi boots up:

Code: Select all

// run on the Pi:
$ ssh my-public-server -i my-private-ssh-key-file.rsa -R 4001:localhost:22
To access to this Pi, ssh into your public server. Note the "-A" to carry your auth agent with you - the agent gets reused for the 2nd ssh connection, the hop from your public server to the Pi:

Code: Select all

// run on your personal computer:
$ ssh -A -i my-other-ssh-key-file.rsa my-public-server
// run on the public server after you ssh into it:
$ ssh localhost -p 4001
See which Pi's are connected to the public server:

Code: Select all

// run on the public server after you ssh into it:
$ netstat -plnt
... and look for port numbers in the 40xx range.

A few miscellaneous notes:
* Create a new user on the Pi (or use the built-in Pi user - but that's not very secure). This new user must be able to connect to the Pi over ssh. For security, I recommend limiting ssh access to private key authentication.
* Create a user on the public server for the Raspberry Pi's to ssh into. It can be a single user for all of the Pi's to share. Once again, I recommend limiting the ssh access to private key authentication. Also for security, this ssh key should be a DIFFERENT key than the ones for the Pi user accounts. Limit what this public server user can do since anyone that gets their hands on your Pi can get on the public server.
* Use Systemd to make the connection script run at startup.
* Test the connection mechanism BEFORE shipping the Pi's to India :D
Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration. ~Stan Kelly-Bootle

User avatar
sapnho
Posts: 212
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: How to control several Raspberry pi s from faraway ( From UK to India)

Mon Jul 29, 2019 5:56 pm

I used this rather simple solution for a Raspberry Pi picture frame: https://www.thedigitalpictureframe.com/ ... taplicity/
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

User avatar
rpdom
Posts: 15371
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How to control several Raspberry pi s from faraway ( From UK to India)

Mon Jul 29, 2019 6:24 pm

emsquared wrote:
Mon Jul 29, 2019 5:11 pm
Summary: Set up a public server. Then have the Raspberry Pi's ssh into the public server with a reverse ssh tunnel. Then ssh into your public server, and hop from there to any of the Raspberry Pi's.
I use something like this, but using VPN instead of SSH tunnels and two public virtual servers. One of my home Pis connects to my external servers' VPNs. Then I can connect to the VPN on either server from anywhere and I am on my home network with an appropriate local 192.168.42.x IP address. The VPN software I use will automatically connect to the servers and it doesn't matter if either is unavailable it will switch between them automatically.

User avatar
Roken
Posts: 306
Joined: Sun Dec 31, 2017 4:35 pm
Location: UK

Re: How to control several Raspberry pi s from faraway ( From UK to India)

Mon Jul 29, 2019 6:48 pm

If you can get port forwarding set up in India - use a different port than 22 on each Pi (and a different port for each) then have that ssh port forwarded to the respective Pis.

Then when you log in, you specify the correct port and it will connect to the correct Pi.
Headless PI. OMG, someone cut it's head off. Oh, hang on. it didn't have one to start with.

blimpyway
Posts: 184
Joined: Mon Mar 19, 2018 1:18 pm

Re: How to control several Raspberry pi s from faraway ( From UK to India)

Mon Jul 29, 2019 7:34 pm

I just set up a PiVPN to see how hard it is.. what a breeze!

That's an OpenVPN server. It can run on your own PI at home or it can be any of the Pi you want to send in India.

Then all other machines connecting the same VPN need to install an OpenVPN client. There some advice on how to set OpenVPN client in this forum too.

Only the server needs its router set up to forward a specific UDP port to VPN server.

You can have as many clients you like, you find downloads for phones, windows, linuxes.

All clients connected to the same vpn network "see" each other as if they-re connected in a local IP.

Which is great you can not only ssh in but use whatever internal networking you need.

PS before installing PiVPN, this video convinced me it shouldn't be hard: https://www.youtube.com/watch?v=9RSHSt4RuLk

PS2 To keep the VPN up, the machine you chose as server should - obviously - be the most reliable of them, one you are confident will have a high uptime.

Return to “Advanced users”