nodejs · raspberry pi

Easily turn your PI3 into a Wifi Router!!! (Raspberry PI 3 as a Host AP – in code!)


How can the PI be a Wifi Access Point???

The Linksys hardware pictured above is synonymous with wifi routers.  Under the covers its just a dedicated Linux box and some fancy software.  Turns out your PI can be that “dedicated Linux box” piece.  In this post, we will cover turning your Raspberry PI into something that provides Wireless access to its internet connection to other computers within its radio’s range. (Sorry no fancy guis or admin tools here – that’s what you pay Linksys for. 😉

Get my repo…

git clone

Then cd into the kidpi/apmagic directory:

cd kidpi
cd apmagic

Install a few things…

You’ll need nodejs to use the code. There are a couple of ways to get that:

Installing NodeJS on a Raspberry PI

Or try running the script:

chmod 755
sudo ./

That should do most of the work for you.  After its complete try:

node --version

If it installed correctly you should see a version greater than 6.10.0.  If you see 0.10 or something similar – you’re running a version that is too old.

Linux utilities you’ll need…

There are several software chunks you’ll need to make this thing work:

  • iptables
    • Takes care of routing the packets from one internet interface to another
  • hostapd
    • This is the chunk of software that uses the Raspberry’s wifi hardware as a hotspot
  • dnsmasq
    • This hands out IP addresses to any would-be client on your network.

So lets install those:

sudo apt-get install -y iptables hostapd dnsmasq

After a successful install, go ahead and reboot your PI.

Now install the pre-reqs for the node program through npm (from within the apmagic directory):

npm install

Setup the PI…

The Raspberry PI should now be connected to the internet through the Ethernet Port.

That’s the internet connection its going to share with all of its wireless clients, its also the one, if you are ssh’ing, you should be connected through… because the wireless connection is about to drop!

Running the software…

Now that you have all of the prerequisites… lets run the NodeJS program as root, and see if you’ve got the AP (again from within the apmagic directory):

sudo node index.js

You should see a couple of debug output statements, then there should be a shiny new Wifi AP called: MattWuzHere

Try to connect to it with the password “easypeazie” visible in the code.

If everything worked…

Congrats!  You’ve successfully created an AP!   Now lets make it happen every time the PI starts up.  There is a SystemD configuration file there.  Install that config:

sudo systemctl enable /home/pi/kidpi/apmagic/apmagic.service
sudo systemctl start apmagic.service

Now reboot your PI:

sudo reboot

When the PI fully reboots, your Access Point should automatically restart, and you can join it and get to the internet.


Now that you’ve successfully set this up using the default options.   Open up the index.js file.  Then look for the lines containing:

        ssid: "MattWuzHere',
        password: 'easypeazie'

Change the MattWuzHere to the name you’d prefer for your new access point, then change the password too.  Save the file.

Reboot the PI again, and your new name and password should take hold.

If something goes wrong…

If you have trouble – leave a comment!  I’ll do my best to address any bugs or missed details.


3 thoughts on “Easily turn your PI3 into a Wifi Router!!! (Raspberry PI 3 as a Host AP – in code!)

  1. I can connect to the network using a mac but cannot connect using a PC. It says it cannot connect to this network. What should i be changing to get this to work?


  2. I’m not entirely sure what is happening in your case. The networking stack on windows is very different, and there are soooo many things that can be configured funny when working with networking.

    Does it say it cannot connect for a particular reason? For instance, the things I’d check are:
    1) Did the wireless connect, but you weren’t given an IP
    2) You were given an IP, but were not given an IPV6 address, and your system only wants IPV6
    3) You were given an IP, but were not given a DNS server.
    4) The given DNS doesn’t work for windows?

    Check your network settings for the wireless and see if you can see anything different between this connection (to the macback) and your connection to a “professional” AP. That might provide some clue on what to attack on your system.

    Good luck!


Leave a Reply

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

You are commenting using your 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