nodejs · raspberry pi

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

33-124-010-23

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 https://github.com/mamacker/kidpi.git

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 node.sh script:

chmod 755 node.sh
sudo ./node.sh

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.

Customizing…

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.

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

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