Simultaneous AP & Client on the Pi Zero W

The Raspberry Pi Zero W is a great platform for IoT projects, with a smattering of GPIO and onboard WiFi. However, security is an important consideration when it comes to the Internet of Things and it can be beneficial to keep your IoT devices on a separate network for safety’s sake. [Albert] wanted to do this all on board the Pi Zero W, and figured out how to get it acting as an access point and a client all at the same time.

[Albert] starts off with a fresh install of Raspbian Stretch, and sets the Pi up in OTG mode. This allows access to the Pi over a USB serial terminal. This is great for productivity when working on headless networking projects, as it can be frustrating trying to work with an SSH session that keeps dropping out when you change settings.

After creating a second named device (ap0) to go along with the one created automatically by the kernal (wlan0), DNSmasq is installed to act as a DHCP server for the AP. Hostapd is then installed to control the AP settings. Following this, like anything in Linux, a flurry of configuration files are edited to get everything humming along and starting up automatically after a reboot. For some reason, things don’t start up smoothly, so [Albert] has a cron job that fires 30 seconds after bootup and toggles the interfaces off and on again, and that’s done the trick.

It’s a useful hack, as it allows the Pi Zero to act as a hub for IoT devices, while also creating a bridge between them and the internet. Traffic can be managed to stop random internet users flicking your lights on and off and overspeeding your dishwasher.

We’ve seen the Pi Zero used for just about everything under the sun so far. If you’re just starting your own IoT build, perhaps you’d like to use the Pi Zero as a streaming camera?

 

32 thoughts on “Simultaneous AP & Client on the Pi Zero W

          1. In the same SSID you can assign clients different VLANs based on authentication (almost every mid to large enterprise does it this way since it’s easy to manager) or if you really want transmit multiple tagged VLANs on a single SSID or to a single client on a single SSID. 802.11 actually has a much large MTU than standard Ethernet so you can get away with a lot. You can also use a single VLAN/SSID in private mode if you don’t need direct peer to peer and want to use security lists for every flow.

  1. Author of the linked article here. While I appreciate the comedy of the snarky comments above, the purpose of my original post was due to the lack of information out there in getting Host+AP mode working properly on a Raspberry Pi Zero W, specifically. There are several existing tutorials out there, all of which have been lamented for not working for most people (myself included), and after figuring out a method that DID work, I decided to post/share it for the benefit of everyone else who had issues making it work as I did.

    1. This place is really getting to have some cynical snarky jerks. I don’t really care is something is or is not a hack, So long as it can somehow be related to my hobby I am happy.

      Your article is great, having a working Wi-Fi as both AP and Client is awesome and I can’t wait to mess around with it.

      1. Appreciate it. I was a little reticent to submit this to Hackaday, because it’s not a “hack” as you said, but there are plenty of RPi articles on here and knowing how easy it is to set up AP+Client mode on an ESP8266 compared to the PITA it turned out to be on the RPi, it seemed like information that might be useful to people.

        I appreciate the Hacakady blog commentary above delving into uses for this mode, but the primary purpose of my actual post was not that, it was just getting it working, which is harder than it should be, despite my having Linux knowledge and being an embedded programmer by trade.

        1. It’s a good article, albeec13. Anyone who uses Mac or Windows all the time would likely struggle with setting this up, and you have saved these people a lot of trouble.

          I think the snark may be due to the popularity of Linux as the fundamental computing base of many HoD readers. AP/client setup is something many people just experiment with out of boredom or to do an emergency caffeine burn, probably while being chewed out for not paying attention during staff meetings. Doing the same thing on an RP0W is no different than doing it on a laptop, so they’re wondering why someone would bother to document it. It’s really just the other side of a coin: excitement on one side, eyerolls on the other.

    2. It’s easy for people to overlook that not everyone has their reserves of knowledge. Sure, I may be able to figure out what needs to be changed from a basic Debian tutorial, but if I didn’t know WHAT to punch into Google… well… I’d be stuck. Where are the logs that tell you what failed to come up? That’s even if you know that you should look for logs in the first place.

      I’m sincerely applauding you for writing this up and sharing it. Others should stop complaining about a story on a free website that nobody forced them to read or review. I don’t read everything on here, that’s the point of having summaries.

      1. Thanks. I pretty much ran into just that. I saw a lot of people having problems getting this to work, and the only responses linked to 2-3 other posts that claimed to get it working, but they didn’t work for me nor for the people asking. I dug in and made it work, and thought it would be helpful to share the information since it appeared to be a popular problem.

  2. I’ve considered building a portable WiFi AP/bridge out of a Pi Zero W by combining the built in WiFi and a WiFi USB adapter, powered by a LiPo battery, bookmarking this article for future reference.

    And to head off the loony conspiracy theorist “RPi Zero is a scam/vaporware that doesn’t really exist because I can’t figure out how to use a web browser” trolls: in the US you can get a Zero W for $12 shipped without having to buy a pesky kit. (No I’m not affiliated, just happily sharing a reputable source with sane shipping (looking at you, Adafruit)).

    https://www.vilros.com/

      1. I live close enough to a Microcenter to do the same. My post was referring to the trolls who tend to drop in to any Pi Zero article complaining that they physically do not exist and are a MLM scam by the Foundation because they can be difficult to source online at times. The cognitive dissonance displayed by those people is baffling.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s