Posts

How to setup the Wifi on a Raspberry Pi using an Access Point?

This tutorial will help you set up an access point that you can connect to in order to setup Wifi on the Raspberry Pi. This is very useful especially if you are planning to use the raspberry pi in a product or a project that someone else will use but is not tech savvy.

Download and Install Raspbian

Download the latest image of Raspbian from www.raspberrypi.org website. I’m using the “RASPBIAN STRETCH LITE” version for this tutorial.

Configure SSH & Wifi

You can follow this tutorial that walks you thru this process of configuring SSH and Wifi.

Clone the Gateway Wifi Setup repository

Make sure you are in the home directory of the pi user. You can confirm that by typing the commandpwd. That should display. /home/pi – Now clone the repository using the following command.

git clone https://github.com/eddieespinal/gateway-wifi-setup.git

Setup

Once you finish cloning the repository, change directory to the gateway-wifi-setup by typing:

cd gateway-wifi-setup﻿

Now, you need to install the NodeJs dependancies for this project. Run the following command:

npm install

Install AP mode

Install the software we need to host an access point but make sure it does not run by default each time we boot. Run the following commands, one at a time.

sudo apt-get install hostapd
sudo apt-get install dnsmasq

Now, let’s disable them.

sudo systemctl disable hostapd
sudo systemctl disable dnsmasq

Configuration Files

Let’s configure the hostapd and dnsmasq that we just installed. Edit `/etc/default/hostapd`

sudo nano /etc/default/hostapd

and uncomment DEAMON_CONF="" add the following line:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

You can save the changes by pressing Ctrl+x then press Enter

Next, copy config/hostapd.conf to /etc/hostapd/hostapd.conf. This config file defines the access point name “DASH Wifi Setup“. Edit it if you want to use a different name.

Make sure you are inside the gateway-wifi-setup folder. /home/pi/gateway-wifi-setup then run the following command.

sudo cp config/hostapd.conf /etc/hostapd/hostapd.conf

Next, copy config/dnsmasq.conf to /etc/dnsmasq.conf

sudo cp config/dnsmasq.conf /etc/dnsmasq.conf

Configure server to run on startup

Copy config/mozilla-gateway-wifi-setup.service to /lib/systemd/system, edit it to set the correct paths for node and for the server code, and then enable the service with systemd:

sudo cp config/mozilla-gateway-wifi-setup.service /lib/systemd/system

Enable it:

sudo systemctl enable mozilla-gateway-wifi-setup

Test it out

Let’s make sure that we have setup everything correctly. You need to remove the current wifi info we provided in the wpa_supplicant.conf file. Todo that, let’s edit that file, but first let’s create a back up of it:

IMPORT: Make sure that this file hasupdate_config=1 in order to be able to modify it later using the gateway-wifi-setup AP.

Reboot

sudo reboot

Once your Raspberry Pi reboots, you should see a new Wifi network on your computer or phone. It will look something like this:

Connect to the DASH Wifi Setup Access Point. Then open your browser and navigate to:

http://192.168.220.1:8080

If everything was setup correctly, you should see the following page in your browser.

Once you enter your WiFi password, the access point will be disabled and it will automatically disconnect you from it. At this point, your Raspberry Pi should be connected to the internet and you should be able to SSH to it.