Configuring Wireless hotspot and DHCP server with Hostapd
This will allow the RotorHazard race timer to broadcast an active WiFi network and allow users and admins to connect to the timer wirelessly using the on board wireless interface. This will also allow other slave timers to connect wirelessly to the RotorHazard timer with the new 2.1.0 beta.1 version at the time of this article for split lap timing.
First, we will update the system as usual.
sudo apt-get update sudo apt-get upgrade
Now, we begin installing HostAPD and dnsmasq. HostAPD will put the wifi interface into host mode and dnsmasq will provide clients with DHCP.
sudo apt-get install dnsmasq hostapd
Now, we will make sure that both the HostAPD and dnsmasq services are not running as they have not yet been configured.
sudo systemctl stop dnsmasq sudo systemctl stop hostapd
Now, lets configure a static IP for the wlan0 interface.
sudo nano /etc/dhcpcd.conf
Copy and paste the following lines.
interface wlan0 static ip_address=192.168.10.1/24
You can make the IP address whatever you like, but we need to configure DHCP to offer address within the same subnet. Now we will restart the dhcpcd daemon.
sudo service dhcpcd restart
To test your configuration.
Should now print this.
get the output
Now, lets setup the DHCP server. We will move the default dnsmasq configuration file and create a blank file with the DHCP settings we need.
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
Now lets edit the dnsmasq configuration file.
sudo nano /etc/dnsmasq.conf
Paste the text below and hit ctrl+x and Y to save.
As you can see, we are specifying which interface to listen on for incoming requests. This will be wlan0. We state the start and end address range offered to clients and have also specified a lease time of 24 hours.
We are also only giving out leases between 50 and 100. This is to allow for a static range that will not be issued by DHCP. This could be salve timers or anything else statically connected. This will also allow for 50 DHCP clients which is more then enough.
Now, lets setup the WiFi SSID and password. We will edit the hostapd config file and change the SSID and password for the wireless network.
sudo nano /etc/hostapd/hostapd.conf
Paste the following and replace SSID with the name you wish to have broadcast as the SSID. Do the same with the WPA Passphrase.
interface=wlan0 driver=nl80211 ssid=racetimer hw_mode=g channel=7 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=racetimer wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Additional options can be changed but are not required. You can use a WiFi spectrum analyzer on your phone to scan the best available WiFi channels with the least noise if you like, and set hostapd to use that channel. Hit crtl+x to save and Y.
Now, we will tell raspian to use the hostapd file as the daemon file.
sudo nano /etc/default/hostapd
Replace #DAEMON_CONF with the line below. Save and exit. Make sure you remove the # from the beginning of the line so its not commented out.
Now, we are ready to start the services and test.
sudo service hostapd start sudo service dnsmasq start
After a short time, you should see your WiFi SSID being broadcast. Try and connect to it and see if you can get DHCP. If so, navigate to the static IP address that we set earlier and the port which the RotorHazard web GUI is running on.
If the WiFi network fails to broadcast, try restarting the PI. If that fails we may need to remove the wpa_supplicant.conf file. To do this
cd /etc/wpa_supplicant/ sudo rm wpa_supplicant.conf
Now, restart the PI and try again!
To view issued DHCP leases
To remove leases
sudo service dnsmasq stop sudo rm /var/lib/misc/dnsmasq.leases sudo service dnsmasq start
If say you wanted to deleted individual leases
sudo service dnsmasq stop sudo nano /var/lib/misc/dnsmasq.leases
Delete the desired leases and save with crtl + x then restart the dnsmasq service.
sudo service dnsmasq start
Check out the next page for the Raspberry PI WiFi antenna mod for extended range.