How to create a very basic WiFi access point on CHIP

These notes came from a project that needed a small group (8) of CHIP computers to receive UDP messages via WiFi coming from a single CHIP. This does not describe how to create a WiFi router for internet sharing - it simple creates a convenient, insecure, local network for passing messages among machines.

In this scenario, the single CHIP that acts as a WiFi Access Point can be connected to another network (including the internet). This makes it convenient to ssh to the WAP CHIP from your laptop (from which you can then ssh to the others on the network).

The first step is to configure CHIP to provide IP addresses through DHCP leases on the wlan1 interface. We are also making sure that we don't provide leases on wlan0, since that is usually used by CHIP to connect to outside networks.

Install dnsmasq:

sudo apt-get install dnsmasq

the file /etc/default/dnsmasq has the enable flag for running as daemon, if needed.

Create a configure file to restrict DHCP injections on client network interface. With this wlan0 becomes a way to connect to a network, and wlan1 becomes CHIPs access point.

sudo nano /etc/dnsmasq.d/access_point.conf

add the lines

#If you want dnsmasq to listen for DHCP and DNS requests only on
#specified interfaces (and the loopback) give the name of the
#interface (eg eth0) here.
#Repeat the line for more than one interface.
interface=wlan1
#Or you can specify which interface not to listen on
except-interface=wlan0

we also want to set the range and time of leases:

#Uncomment this to enable the integrated DHCP server, you need
#to supply the range of addresses available for lease and optionally
#a lease time. If you have more than one network, you will need to
#repeat this for each network on which you want to supply DHCP
#service.
dhcp-range=172.20.0.100,172.20.0.250,1h

Create a file to set up a static IP for the access point:

sudo nano /etc/network/interfaces

and have the contents like so:

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
  
  source-directory /etc/network/interfaces.d
  
  auto wlan1
  
  iface wlan1 inet static
	address 172.20.0.1
	netmask 255.255.255.0
		

Confirm that the static IP is assigned:

sudo ifup wlan1

ip addr show wlan1

and you'll see the address listed

inet 172.20.0.1

now restart the DHCP server that dnsmasq provides

sudo /etc/init.d/dnsmasq restart

We have just tested the IP configuration portion.

Now we can configure the WiFi access point on wlan1.

Create a config file:

sudo nano /etc/hostapd.conf

and add the lines:

interface=wlan1
driver=nl80211
ssid=test_chip_ap
channel=1
ctrl_interface=/var/run/hostapd

then we can start the access point with

sudo hostapd /etc/hostapd.conf

You'll see the network come up on another device, like your laptop or tablet or phone:

test_chip_ap

Now we would like to configure CHIP to create the access point automatically on boot.

We can setup a systemd service to do our bidding. We give the service a unique name, so it doesn't conflict with the systemV stuff in init.d:

sudo nano /lib/systemd/system/hostapd-systemd.service

Fill the service file with these contents:

[Unit]
Description=hostapd service
Wants=network-manager.service
After=network-manager.service
Wants=module-init-tools.service
After=module-init-tools.service
ConditionPathExists=/etc/hostapd.conf

[Service]
ExecStart=/usr/sbin/hostapd /etc/hostapd.conf

[Install]
WantedBy=multi-user.target

Disable the existing systemV script for booting hostapd:

sudo update-rc.d hostapd disable

Now we can setup the systemd service with these commands:

sudo systemctl daemon-reload

sudo systemctl enable hostapd-systemd

Reboot or test with these commands:

sudo systemctl start hostapd-systemd

systemctl status hostapd-systemd

The access point and DHCP server should be accessible from other devices!

If you want to connect another CHIP to this access point, you can do it from a GUI, or with the command:

sudo nmcli d wifi connect test_chip_ap