Skip to content
Jordan Damron edited this page Mar 10, 2019 · 5 revisions

Connect your Raspberry Pi to your phone using WiFi Hotspot

Some phones (notably many Samsung devices in North America) do not support the Bluetooth Tethering option as recommended in omnipy setup. In this case you can use WiFi tethering from your phone to provide the connection between the phone and the raspberry pi.

If your phone supports Bluetooth Tethering it is recommended to use that as is is more battery efficient.

Step 1: Setup WiFi Hotspot on your phone

The exact steps to do this will depend on your phone model and Android version, but it is typically located in Settings->Connections->Mobile Hotspot and Tethering. The screenshots and notes below follow the Samsung Galaxy line running Android 8 or Android 9. Refer to documentation for your device for specific directions.

Click the toggle to enable Mobile Hotspot.

Tap Mobile Hotspot to configure the settings.

Tap the 3 dot menu in the top right and select Configure Mobile Hotspot

Give your network a name and a secure password.

Do not select Hide my device this can cause connection issues with the Raspberry Pi.

Do not select Use 5GHz band when available. The Raspberry Pi Zero W does not currently support 5GHz Wifi.

If you have the option to enable WiFi Sharing, it is recommended to enable it. This will allow your phone to connect to configured WiFi networks while the hotspot is enabled.

Step 2: Configure the Raspberry Pi to use the Hotspot

Note: Once this step is completed, the Raspberry Pi will be connected to the phone's network, not your local WiFi. If you are connecting to your Raspberry Pi using ssh on a computer, you will need to install an ssh client on your phone in order to access the device once this is completed. Juice SSH is a good client.

It's helpful to have local access (Keyboard and Monitor) when configuring network settings so you can still access the device in the case of misconfiguration.

Using your preferred text editor (nano is easy to use), edit the file /etc/wpa_supplicant/wpa_supplicant.conf

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Update the network to match the network name and password configured above.

network={
   ssid="Omnipy"
   psk="supersecret"
}

Reboot the Raspberry Pi.

After it is rebooted, you will see the Raspberry Pi listed under Connected devices in Mobile Hotspot settings on your phone. If you do not see it after a couple minutes, confirm that the network name and password match between the hotspot setup and the wpa_supplicant network configuration.

Tap the Raspberry Pi's name in the list to see its IP address. Note this address for entry in AndroidAPS settings.

Optional settings

Allow only the Raspberry Pi to connect to the hotspot

To secure your Hotspot, you can configure it to only allow specific devices to connect. This reduces the risk of unauthorized connections.

In the Mobile Hotspot settings on your phone, click the "+" beside your Raspberry Pi's name.

Click Add to add this device to the Allowed Devices list

Click the 3 dot menu in the top right and select Allowed Devices

Enable the toggle Allowed devices only

Add a fallback network in case the Hotspot is unavailable

You can add another network to the Raspberry Pi network settings to allow it to connect to a network other than the configured hotspot (e.g. a home network). Note that when it is connected to this network, AndroidAPS will not see the Raspberry Pi and the loop will not function unless you update the IP address in AndroidAPS.

This can be used to gain access to the Raspberry Pi if there are issues with the phone.

Edit the wpa_supplicant file as above.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add the second network. Use the parameter priority to tell the Raspberry Pi to connect to the secondary network only if the primary (phone hotspot) is unavailable. A higher number means higher priority. The default priority is 0. See wpa_supplicant.conf documentation for more configuration options

network={
   ssid="Omnipy"
   psk="supersecret"
   priority=1
}
network={
   ssid="HomeNetwork"
   psk="CorrectHorseBatteryStaple"
   priority=0
}
Clone this wiki locally