The Troubles of Networks in an Organisation
Sometimes it’s hard to find an easy networking method while working with a Single Board Computer (SBC) like Raspberry Pi. If you are working on the Raspberry Pi at home probably things might be little simpler. After all it’s your house, your network, your internet and your PCs/Laptops; mostly you may have control over those all. It may not be that hard to get things right if somewhere it goes wrong and you can get the support from your house members who have the access to it. That being said, people often find troubles in network connectivity of the Raspberry Pi at some point. Here, we shall discuss about the in-and-outs of the networking issues and getting the internet access to the Raspberry Pi. It’s very common that, if you are a student and you have to work with RasPi inside your School, College or University but you fail miserably in connecting it with their network. There are many Institutions in which Raspberry Pi or any other SBCs are part of their curriculum. If that the case, there is a high chance that they might have already prepared their network to accommodate the student’s Raspberry Pi boards.
I’ve personally came across on these kind of problems in every Institution I’ve gone to teach students the Raspberry Pi. Though, their Network Administrators supported me very well but, still I’ve faced several issues with the Institution’s Network. They usually have strict rules/policies on using their network. To my surprise, majority of the institutions won’t allow Wi-Fi connectivity to the students; at least in India. Other thing is, all of their systems might be configured with static IPs. If they allocate the IP addresses tightly to accommodate the total number of systems in each departments, getting few static IPs from the network administrator is still a problem; but not an ‘impossible-task’. Few dynamic IPs might be there for immediate connectivity; usually with some restrictions.
Supplying Wi-Fi Configuration through Boot partition
For latest versions of Raspbian Jessie images, the simplest solution is placing a Wi-Fi configuration file in the /boot directory in the SD card. If a wpa_supplicant.conf file is placed into the /boot/ directory, this will be moved to the /etc/wpa_supplicant/ directory the next time the system is booted, overwriting the network settings; this allows a Wi-Fi configuration to be preloaded onto a card from a Windows or other machine that can only see the boot partition.
Windows users, create a new file using Notepad++ or similar editor which works well with Linux files. Follow the below steps to make a Linux/Unix friendly file using the Notepad++.
- Start a New File
- Select Preferences from the Settings Menu.
- At the bottom of the Editor window, check for the setting “Windows (CR LF)”. Double click on it to change it to “Unix (LF)”.
- Put the below content inside the file. Edit the ssid and psk values according to your network.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="Your_Network_SSID" psk="Your_ Network _password" }
- Click Save and name the file as ‘wpa-supplicant.conf’ and save it inside the SD card.
The earlier Raspbian distributions lack this feature and which may trouble you for several reasons including ‘having an old back up image’. Continue to next section if you fail in this method.
Finding Another Better Networking Solution
Using a keyboard, mouse and monitor would be an easy method to get started along with an Ethernet cable. Using a monitor will be another problem where most of the monitors have VGA ports and your RasPi supports HDMI (I’m ignoring analogue output). Getting a HDMI-to-VGA converter cable is the solution here. Now you’ve 2 options to get connected to wired network,
- Connect to the Network Router using Ethernet cable.
- Direct Ethernet cable connection to your Laptop/Desktop. Learn how…
What if you want to connect through your Raspberry Pi’s Wi-Fi? Again, you’ve 2 options.
- Connect to the Network Wi-Fi.
- Connect to your Laptop (or Desktop with Wi-Fi) through a Hotspot of your Mobile phone/Tablet. Learn how…
Before getting into the process of doing all these let’s take a look at some scenarios below. I think this is the better way to deal with different kind of problems you may encounter.
Catching up with the Situation
As a Raspberry Pi user, you know well that there are accessories which you should have along with your favourite RPi board. Some of them are RJ45 LAN Cable, USB Cable, USB Hub, RCA Cables, HDMI Cable, HDMI-to-VGA Converter, 3.5mm Audio Cable, USB Wi-Fi Dongle, USB Bluetooth Dongle, USB-TTL Module (if you are into hardware), USB Power Adapter/Power Bank, Raspi Casing, Heat sink, Micro SD Card, USB Audio Dongle etc. I would recommend few things here for your networking support,
- USB Wi-Fi Dongle (if you do not have Raspberry Pi 3, Raspberry Pi Zero W or the built-in Wi-Fi doesn’t work)
- RJ45 LAN/Ethernet Cable
- HDMI-to-VGA Converter Cable
- USB-TTL Module (make sure it has 3.3V compatibility)
- A Network Port Switch (If you don’t have any network and you want to connect more than 1 Raspi with your computer)
These are listed to just remind you that, make sure you have a plan before you start working on your Institution’s network. Since your situation may differ from others, it’s not easy to stick with one solution for all. Find a suitable scenario from the below which best suits yours and go ahead with it. You can always try other alternatives if you fail in one solution. All connection methods are explained after the Scenario listing.
Scenario – 1
“I’ve a Raspberry Pi board without any Wi-Fi support, Monitor/TV or USB-TTL module.”
It’s a common scenario with basic setup in hand. You’ve 2 options,
Method 1: Connect to the Network Router using Ethernet cable. (Static or Dynamic IP)
Method 2: Establish a Direct Ethernet Connection with the Laptop and enable Internet Connection Sharing (ICS). Learn how…
Scenario – 2
“I’ve a Raspberry Pi board with Wi-Fi support, but no Monitor or TV and I want to connect to the Network through Wi-Fi; not Ethernet.”
What if you cannot connect to the Institution’s router using Ethernet cable or the Laptop and Raspberry Pi gets two different networks? If you failed miserably in getting the connection between the Laptop and Raspberry Pi using the Ethernet and you are sure that you can connect both of them through Wi-Fi, here are some alternative methods. The aim is to provide the Wi-Fi Network configuration setting to the Raspberry Pi. Find an appropriate method to establish an SSH session with Raspberry Pi and change Wi-Fi setting.
Method 1: Establish a Direct Ethernet Connection with the Laptop. Learn how…
Method 2: Use a USB-TTL Module to establish a Serial communication with the Raspberry Pi Learn how…
Scenario – 3
“I’ve a Raspberry Pi board with Wi-Fi support, Monitor with HDMI-to-VGA cable, but cannot connect to any Wi-Fi network.”
It’s straight forward if you’ve Monitor, Keyboard and Mouse. Below methods are applicable with or without Monitor setup. Decision is up to you.
Method 1: Connect to the Network Router using Ethernet cable. (Static or Dynamic IP)
Method 2: Establish a Direct Ethernet Connection with the Laptop. Learn how…
Method 3: Connect to your Laptop (or Desktop with Wi-Fi) through a Hotspot of your Mobile phone/Tablet. (You must update the Wi-Fi settings in the RPi before doing this). Learn how…
Scenario – 4
“I’ve a Raspberry Pi board with a Raspbian image created using Matlab Hardware Support Package Installer and I’ve a headphone with me.”
Your SSH session can be established using either Hostname/IP address or Serial Connection. The below methods assume you don’t have a Monitor setup. To get the IP address of the RPi, follow any of these methods.
Method 1: Use a USB-TTL Module (if you’ve one) to establish a Serial communication. Type ifconfig to get IP address. Learn how…
Method 2: Hear the IP address of Raspberry Pi using Headphone or any other Audio instrument. The Matlab Hardware Support Package Installer writes the Raspbian image with the eSpeak TTS engine preinstalled. An associated start up script allows the Raspberry Pi to speak out the IP address through the standard audio output.
Method 3: Find the IP address from Target Hardware Options settings in Simulink. Open any Raspberry Pi Simulink example and go to Tools -> Run on Target Hardware -> Options…
The Module Parameter Configuration windows will pop up. Note the IP address from Target Hardware Resources section.
You can also configure Raspberry Pi Hardware to email you whenever IP address changes. Read this to know how to configure the Mail Setting.
Note: The Hostname of the Raspberry Pi is always modified to make it unique by the Matlab Hardware Support Package Installer. Note down the Hostname when the Installer finishes the process. This will make things easy if your Laptop has Bonjour installed already. Just put this Hostname in the PuTTY to get SSH; no need to know the IP address or if it changes every time.
Direct Ethernet Cable Connection to Your Laptop/Desktop
To establish a Direct Ethernet Connection with the Laptop. Follow these steps,
Step 1: Setup a Direct Connection using an Ethernet Cable with your Laptop. The Direct Connections are made with the help of “Ethernet Crossover Cables” traditionally. But these days, our Network Switches, Routers and other Network Cards are intelligent enough to detect the connection and twist the Rx-Tx pairs internally. It is often called Auto MDI-X ports on newer network interfaces detect if the connection would require a crossover, and automatically chooses the MDI or MDI-X configuration to properly match the other end of the link." data-placement="top" style="border: none !important;">Auto MDI-X capability.
The Raspberry Pi also can handle this and you can use any Straight through (regular ‘patch cables’) or Crossover RJ45 Cable for this purpose.
Don’t worry about any Network settings in your Laptop or Raspberry Pi, leave it as it is. The thing is recent Raspbian distributions automatically manages to assign its own IP even if the Laptop has Static IP.
Step 2: Find a way to figure out the IP address of Raspberry Pi. You have two options here,
- Option A: Install Bonjour for mDNS service. It can be found in “C:\Program Files (x86)\Bonjour” folder if you are on Windows OS. If you are an Apple iTunes user, you don’t need to install this as Bonjour is bundled with iTunes by default.
- Option B: Install any Network IP Scanner Tool like Fing, Angry IP Scanner, Advanced IP Scanner, Wireless Network Watcher etc.
Note: Disable Wi-Fi temporarily or disconnect from any wireless networks to avoid “multiple networks” related issues or getting confused yourself. Once you are done with the Direct Ethernet connection with the Raspberry Pi, you can switch back.
Step 2: Start an SSH session. If you have Bonjour installed, try typing the hostname of the Raspberry Pi in the Hostname field of PuTTY. The default hostname is ‘raspberrypi’.
You can find the IP address of the Raspberry Pi using the ‘Wireless Network Watcher’ or similar tool. Input the IP address in the Hostname field of PuTTY if you fail to connect using the Hostname of the Raspberry Pi.
Step 3: Connect to Raspberry Pi and enter the Wi-Fi configuration details.
Open the wpa-supplicant configuration file in nano:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Go to the bottom of the file and add the following:
network={ ssid="Your_Network_SSID" psk="Your_ Network _password" }
Now save the file by pressing Ctrl+X then Y, then finally press Enter to exit from nano editor and close the SSH session.
Step 4: Remove the Ethernet Cable and restart the Raspberry Pi.
Step 5: Use your Mobile phone or Laptop to get the IP address of the Raspberry Pi. Run any Network IP Scanner Tool. I use Wireless Network Watcher in Windows PC and Fing on Mobile phone (available for iOS and Android). Make sure your Mobile phone/Laptop connected to the same network.
SSH Over Serial Communication
The Serial Console is enabled in Raspbian by default. It means that you can login to Raspberry Pi console using a Standard Serial Communication interface if it is a fresh Raspbian install or you didn’t change the setting previously. You can get a USB-TTL module for just Rs 200. Since Raspberry Pi pins are at 3.3V level, make sure you have a USB-TTL Module that has same voltage level. Most of the available modules in the market are 3.3V and 5V compatible, even then it is good to check the specs before you buy.
Step 1: Connect the USB-TTL cable to the Raspberry Pi’s GPIO. Only three pin connections are needed to establish a serial connection with the Raspberry Pi.
1. RasPi Rx – Module Tx
2. RasPi Tx – Module Rx
3. RasPi GND – Module GND
Find the Rx and Tx pins in the pin-header on Raspberry Pi board and connect as per the above using jumper wires(mostly, Female-to-Female) to the corresponding pins on the USB-TTL Module.
Step 2: Now insert the USB-TTL Module to any available USB port on your computer. I assume, you’ve the knowledge of installing drivers in your computer for new hardware. There are few USB serial chips available in the market. PL2303, CP2102, FT232R and CH340G are some leading chips. Find the appropriate driver from manufacturer and install. My personal suggestion is CP2102 due to lower cost and better performance. Market is bloated with cheapest PL2303HXA chips which I don’t recommend for several reasons but if you find PL2303HXD or PL2303TA, go for it. CH340G is another cheaper Chinese chip which is ‘OK’ for the purpose. FTDI chips are too costly but those are the robust chips among the listed.
If your USB-TTL is ready with successful driver installation, find out the COM port assigned to the currently connected USB-TTL Module. Windows users open the Device Manager and expand the ‘Ports’ section. It is easy to figure out the COM port of your module as the listed peripherals usually be described with the chip manufacturer name or chip number.
Step 3: Now, open PuTTY or your other favourite terminal program and input the below parameters along with your modules COM port number.
Port: COM3 (just an example, replace with yours)
Baud rate: 115200
Below setting is optional:-
Bits: 8
Parity: None
Stop Bits: 1
Flow Control: None
Step 4: Once you complete the setup, power on your Raspberry Pi. You’ll be able to see the booting sequence and finally login prompt will be displayed.
Now, you can edit your network settings to work with Ethernet or W-Fi.
Creating a Standalone Network Using Wi-Fi Hotspot
There are some prerequisites if you want to connect Raspberry Pi to Wi-Fi Hotspot. Go to Mobile Phone’s Hotspot settings to change Hotspot’s Network name (SSID), Pass key and other parameters. Check below screenshots to get an idea.
Note: You’ll be able to see the IP address of the Raspberry Pi once it gets connected to the Hotspot.
Now, you need to enter this SSID and Pass key info in Raspberry Pi. We have seen previously several methods to change the Wi-Fi configuration. Let’s check once again,
Option 1: Supply Wi-Fi Configuration file through Boot partition
Option 2: Connect Monitor, Keyboard and Mouse. Connect to Wi-Fi Hotspot after entering desktop.
Option 3: Establish a Direct Ethernet Connection with the Laptop to change Wi-Fi setting.
Option 4: Use a USB-TTL Module to establish a Serial communication with the Raspberry Pi to change Wi-Fi setting.
Once you finish editing the Wi-Fi details, the Raspberry Pi should connect automatically. If not, restart the Raspberry Pi Wi-Fi interface or reboot the RPi.
To stop the Wi-Fi interface type,
sudo ifdown wlan0
Command to start it,
sudo ifup wlan0
This will help you to have your own network without disturbing the Institution’s network. Only thing is, you should be having a good Internet Pack to support the Raspberry Pi’s huge demand if you are onto serious business.
Note: You don’t need mobile internet to create this network. If you don’t care about internet in Raspberry Pi, the network just works fine.
Conclusion
So here we are, with lots of options to make a network that works well with the demand. I tried to make things clearer in terms of working with ‘Headless Boot Setup’ of the Raspberry Pi. Hope you find this useful.
Happy networking!