Set up a Pi with no router, no cable, and no peripherals

nichartley

Nic Hartley

Posted on April 3, 2019

Set up a Pi with no router, no cable, and no peripherals

If you're at uni and you've tried to set up a Raspberry Pi, you've probably hit an error. Ditto if you don't own your router and your ISP (or landlord) won't give you access to the control page. That issue is that you somehow need to get your RPi's IP address, but you don't have any way to get it!

So instead of using your normal router, well... why not make your own? Sure, you could go out and buy one, but chances are you already have a device capable of generating a hotspot. Your laptop can probably do it, as can your phone. Why not use them?

Note: if you're already experienced with setting up RPis headlessly, you can probably skip the rest of the tutorial. That last paragraph was the big secret. The rest of this is just applying the normal techniques to this specific case.

Requires

  1. An RPi. I'll be using a Raspberry Pi 3 Model B+, but this should work with any Raspbian-capable machine. This should work on any Raspbian machine, though. Also, you will still need the normal mandatory accessories for your RPi -- a power cable, an SD card, etc.
  2. Any device which supports mobile hotspots. I'm using my Android phone for this tutorial, but the instructions will be similar regardless.
  3. An SSH client. I use the CLI packaged with the Windows Subsystem for Linux because it's convenient, but there are dozens, and literally any will work.

Instructions

Get your Pi ready

The first thing you need to do is get your Pi ready. There are a ton of tutorials on flashing Raspbian to your SD card; you can follow literally any of them.

Note: Do not install NOOBS! NOOBS is great if you have a monitor and keyboard to attach to your Pi. If you do, you should use it! This tutorial, however, is built on the premise that you don't, so make sure that you install Raspbian, not NOOBS.

Once you have Raspbian installed on the SD card, you'll need to add two files, both in the root directory of the SD card:

  1. An empty file called ssh
  2. wpa_supplicant.conf (see below)

Open up wpa_supplicant.conf in your favorite editor, and

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
     ssid="TODO"
     psk="TODO"
     key_mgmt=WPA-PSK
}

Keep that text editor open. We'll be setting the values of ssid and psk by replacing the TODOs on those lines.

Note: If you're not in the US, you should change the country= line to match your country's ISO 3155-1 alpha-2 code. I have yet to see things break when the wrong country is supplied, but that doesn't mean they can't.

Setting up your router

The exact steps for this vary by the product you're using as your router. I'll describe the process for a couple of common systems, but there are definitely tutorials online for what you're using, even if it's not here.

In general, though:

  1. Create a hotspot.
  2. Set ssid to the SSID of the network.
  3. Set psk to the network's password.

Windows

A Windows 10 machine will require an internet connection or some fiddling to create a hotspot, but it gives you the same benefits: Open your WiFi menu and look in the bottom-right or bottom-middle for a button labeled "Mobile Hotspot". Click it. You now have a hotspot starting.

Once that turns blue, right-click it, click "Go to Settings"1, and find the section showing the network name and password. Back in wpa_supplicant.conf, set ssid to the value next to "Network name", and psk to the value next to "Network password". Make sure you get all of the characters exactly right, including case.

Android

Note: Most phones allow this; however, yours might not, or might have slightly different names for things. Use your best judgement.

Open Settings. Find the category labeled "Connections" or "Network & internet" and tap it. Tap the option labeled "Mobile Hotspot and Tethering", or something similar. Tap the switch next to the option labeled "Mobile Hotspot" or "Wi-Fi Hotspot". Before you connect to it, go into the settings and try to find something labeled "WiFi sharing" -- this will keep you from accidentally using mobile data while you have your RPi connected. With my phone, once I turn WiFi sharing on, I can actually turn WiFi entirely off (or at least disconnect from my local WiFi) and still use it, but this may not work with yours.

As before, you'll nede to set ssid and psk to the network name and password, respectively. Both should be visible on the main screen, but if you're having trouble finding them, try tapping the three-dot menu icon in the top corner, then "Configure Mobile Hotspot". Each of the fields will be labeled nicely.

You should also look at the Security dropdown. Chances are it'll be WPA2-PSK, and if that's the case, you don't need to do anything. If it's something else, you'll need to learn more about wpa_supplicant.conf to correctly configure your RPi.

Putting the two together

Now that you have your 'router' running and your RPi's SD card configured, put the SD card in the RPi and plug in the power cable. Give it some time to start up -- it'll take a little while.

Eventually, you should see the RPi pop up on the list of devices connected to your network. On a Windows 10 hotspot, you'll see the device's name, IP address, and MAC address in a table. On your phone, you might just see a name -- try tapping it or tapping-and-holding to bring up extra information about it.

You need to get your RPi's IP address for the next step. It should be clearly labeled. Be sure to copy it exactly; any typos will be annoying to spot.

Connecting to the Pi

This is actually the easiest step. Using the machine you'll control the RPi with, connect to the same network that the RPi is on. SSH into the IP address you just got, as the user pi with password raspberry. Congratulations! You're now in the RPi, and can do anything with it that you could with a normal terminal setup.

Remember to change the default username and password for your RPi, by the way! Even if you don't now plan on using it for anything that's accessible to others, it's better to get into the habit of changing default passwords than to learn the hard way that you forgot.

One important caveat, by the way: Connecting to a different network with either the RPi or your man machine will break the SSH connection. If you change the network your RPi is on, your connection will break before the other connection is established.

Next steps

From here, you have full control over your RPi. If your router connects to the internet, you can even install things from the internet. If you're brave, you could even set up X11 forwarding so you can graphically control your RPi. You can even walk away and leave the RPi to do its own thing for a while -- when you come back, it'll automatically reconnect to the WiFi in its wpa_supplicant.conf and you can access it like before.

It's trickier if you want it to connect to another network, though. You can, of course, just change wpa_supplicant.conf to point to the other network, reboot, and leave it be -- assuming you got all the details right, it'll connect to that network perfectly well. The trouble is when you want to get control over it.

If you have your RPi phoning home, you can of course write that system such that it can deliver commands like "reconnect to my hotspot" from your server. You could also have a script scanning the locally available WiFi and, if your hotspot is available, reconnecting to it. There are quite a few ways, and none of them are necessarily better than the others. It just depends on what you're trying to do, and what your resources are.

Good luck!

💖 💪 🙅 🚩
nichartley
Nic Hartley

Posted on April 3, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related