Help with RPi Access Point and iPhone tether

Thank you in advance to anyone who is able to help me with my current project.

I am trying to run a Raspberry Pi (with no internet connection) as an access point that an iPhone can connect to. Once connected, I would like the Pi to be able to access the internet through the iPhone’s cellular. I have heard of projects/iOT devices that accomplish this, but I am by no means a networking expert and have had some difficulty.

I am able to run the RPi in AP mode and I can connect the phone to the Pi using the SSID I establish. However, when I do this, both the Pi and iPhone do not have internet access. This article implies that I should modify dnsmasq.confsetting dhcp-option=3, but that file is in a read-only partition. Is there a work-around for this?

Hello,

From what I understand you want the rpi to connect to your iphone through wifi and use the phone’s cellular connection to access the Internet.

In order to do so, you need your rpi to act as a regular wifi client and your phone as an access point (not the contrary).

Just set up your iphone as an access point following this https://support.apple.com/guide/iphone/share-your-internet-connection-iph45447ca6/ios

Then connect your rpi to this wifi network using the ssid and password disaplyed on your phone.

Hello, thank you for the quick response. I do want to use the iPhone’s cellular connection but I want the Pi to act as the access point. I know it sounds backwards from what is normally done, but there are devices that do this. The motivation for doing it this way is that the iPhone personal hotspot tends to kick “inactive” devices (Apple doesn’t seem to share their guidelines for this), so if I connect a Pi to the phone’s hotspot it tends to lose that connection after a while. I’m trying to keep that connections alive and stable for as long as possible.

Hi Brett,

You can use our wifi-repeater project to do this: https://www.balena.io/blog/turn-a-raspberry-pi-into-a-wi-fi-access-point-or-repeater/
The repo is here: https://github.com/balenalabs-incubator/wifi-repeater

Hope this helps,
Phil

Hi Phil,

I took a look at the wifi-repeater project and I don’t think that’s quite what I want. It does setup the Pi in AP mode, but it does not route traffic through the phone’s cellular. In this setting my Pi will not be connected to ethernet or WiFi itself, so it needs to route its traffic through the phone’s cellular. Do you know if there if a way to modify dnsmasq.conf? I’ve read that I will likely need to configure dnsmasq and hostapd, but unfortunately my knowledge in this arena is limited to googling :slight_smile:

Update: I am able to make this happen on a RPi running the latest Raspbian distro (December 2020). However, this requires that I modify dnsmasq.conf, hostapd.conf, and dhcpcd.conf. The Pi is also not running NetworkManager, of course. Given the above, I’m not sure how to make this run on Balena. I’m open to any and all suggestions! :slight_smile:

Hello Brett,

I think the wifi-repeater project (in repeater mode) is worth a second look. If I understand your requirements, you want the Pi in AP mode and then route any traffic through your phone’s cellular? So if you connect the Pi dongle to your phone’s hotspot, the devices connected to the Pi AP would be routed through that internet connection. However I think you also mentioned that you don’t want to use the iPhone personal hotspot. If that’s the case, by what means do you want to connect to your phone’s cellular internet connection? Feel free to elaborate more if I’m misunderstanding what you’re trying to accomplish!

Hi Alan,

I’m now realizing that I may have misspoken before. Sorry about that, I must need more coffee today. I just want a local connection between the phone and Pi.

In summary:

  • Pi acts as AP
  • phone connects to Pi
  • Pi sends data locally to the phone
  • Phone sends data to cloud using its cellular

The way I’m doing this on Raspbian is by having the Pi effectively black hole any packets it receives. So the phone connects to the Pi using the standard wifi menu in settings. Once connected, it realizes that the AP isn’t connected to the internet and uses its own cellular. I can still access the web on my iPhone, and I can run a simple program on the Pi to send data to the phone. I apologize if I’m being confusing. Let me know if I can clear any of this up.

As a follow-up: might this be something that I can do from within a container? I saw some articles on the balena forums where people install dnsmasq and hostapd within their container and run a configuration script. The reason I bring this up being that I can’t modify /etc/dnsmasq.conf on BalenaOS because it’s a read-only partition.

Hi Brett,

Isn’t it better to let the Pi connect via Wi-Fi to the hotspot of your iPhone? That way, the iPhone shares its cellular with the Pi and can send data. I know iPhone has the ability to use cellular when Wi-Fi is slow/not available, but I don’t think you can send data to your iPhone via the Pi’s Access Point connection and instruct the iPhone to pass it forward via cellular. Changing the flow, so the iPhone becomes the Access Point and the Pi connects to your iPhone, is probably better and achieves what you want without creating an app or something on your iPhone.

About the /etc/dnsmasq.conf, you’ve to run a container with dnsmasq installed and give the container access to the host’s network (network_mode: host), so that the container manages the DNS of a specific interface. This post contains almost everything to help you get started with that!


Edit
I saw that you would like to achieve this for a reason. Only thing I can think of is creating a webserver or something on the RPI and let that act as the interface between your RPI and iPhone. Only thing is, I don’t know how you can force your iPhone to send data via cellular, other than changing your flow.

But nonetheless, I’m very curious if you can find a way to achieve this!

1 Like

Hi Bart,

Thank you for sharing that link, I believe it may be what I was looking for. I will let you know if I get it to work :slight_smile: