How to connect your Raspberry Pi to your iPhone WiFi hotspot via Raspbian Stretch Lite

Raspberry Pi 3 and Raspberry Pi Zero W connecting to iPhone WiFi hotspot

Raspberry Pis with WiFi are very useful for building prototypes that connect to services on the Internet.

In case you need a Raspberry Pi with in-built WiFi, you can get one of these:

An operating system is needed for running your Raspberry Pi and Raspbian Stretch Lite is an ideal choice for server based applications.

Although Raspbian Stretch Lite does not have a graphical user interface, it is not difficult to get it to connect to a WiFi hotspot.

If you wish to use your iPhone as a WiFi hotspot for your Raspberry Pi prototype, read this post to find out how to connect Raspbian Stretch Lite to your iPhone hotspot.

Enable Personal Hotspot on your iPhone

First, turn on WiFi Personal hotspot on your iPhone. Once the WiFi Personal hotspot is turned on, you will be able to connect WiFi devices to it.

The SSID (or WiFi hotspot name) and password of your iPhone WiFi Personal hotspot will be needed to connect Raspbian Stretch Lite. You can get the SSID and password of your WiFi Personal hotspot at the Personal Hotspot screen.

For example, in the sample screenshot below, the SSID is MyiPhone and the password is apassword:

Cropped Personal Hotspot screen with Personal Hotspot turned on with SSID and password boxed

If the SSID is the default given by your iPhone, you should change your WiFi SSID of your iPhone hotspot to one without spaces and a-strophes.

For the purpose of this guide, let's assume that your iPhone WiFi hotspot's SSID is MyiPhone and the password is apassword.

Connecting Raspbian Stretch Lite to your iPhone hotspot

Here are three ways to connect Raspbian Stretch Lite to your iPhone hotspot:

  1. Including a wpa_supplicant.conf file inside the microSD card right after you had installed Raspbian Stretch Lite onto the microSD card.
  2. Using the raspi-config tool from a terminal session with Raspbian Stretch Lite after it boots up.
  3. Editing the wpa_supplicant.conf file located in the /etc/wpa_supplicant directory from a terminal session with Raspbian Stretch Lite after it boots up.

Including a wpa_supplicant.conf file inside the microSD card right after you had installed Raspbian Stretch Lite onto the microSD card

As I had mentioned in how to setup Raspbian Stretch Lite with remote configuration over WiFi on first boot, making Raspbian Stretch Lite connect to a WiFi network is useful for projects based on Raspberry Pi Zero W.

You can follow the steps mentioned in that post to get Raspbian Stretch Lite to connect to your iPhone hotspot when it boots up for the first time.

Using the raspi-config tool from a terminal session with Raspbian Stretch Lite after it boots up

So what if you wanted to connect a previous installation of Raspbian Stretch Lite to your iPhone WiFi hotspot? In this situation, you can use the raspi-config tool from a terminal session to connect to your iPhone hotspot.

First, run the following command to start raspi-config tool:

sudo raspi-config

After raspi-config starts, follow through the following screenshots to get Raspbian Stretch Lite to connect to your iPhone hotspot:

Raspbian Stretch Lite 2018-06-27 raspi-config with Network Options selected

Raspbian Stretch Lite 2018-06-27 raspi-config with N2 WiFi selected

Raspbian Stretch Lite 2018-06-27 raspi-config with MyiPhone input as SSID for connecting WiFi

Raspbian Stretch Lite 2018-06-27 raspi-config with password input for connecting WiFi

Editing the wpa_supplicant.conf file located in the /etc/wpa_supplicant directory from a terminal session with Raspbian Stretch Lite after it boots up

The manual way to connecting an Raspbian Stretch Lite after it boots up is to edit the wpa_supplicant.conf file directly. This file is located in the /etc/wpa_supplicant directory. Therefore, you can run the following command to edit it:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Once the editor loads the file, add in the following content to the end of the file:

network={
        ssid="MyiPhone"
        psk="apassword"
}

Since Raspbian Stretch Lite can connect to different WiFi networks, there can be multiple network blocks inside wpa_supplicant.conf.

After you had added in your iPhone WiFi details, run the following command to get Raspbian Stretch Lite to take in the new network configurations:

wpa_cli -i wlan0 reconfigure

When Raspbian Stretch Lite is able to reconfigure the WiFi adapter with the new configurations, you should see OK after you ran the command.

In addition, Raspbian Stretch Lite will connect to your iPhone WiFi hotspot when your iPhone and Raspberry Pi are in contactable range.

About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people. All views expressed belongs to him and are not representative of the company that he works/worked for.