Raspberry PI ZERO WH- Hotspot

Raspberry PI (RasPi) Zero WH turn to WiFi HotSpot

My purpose is to connect a RasPi 0 WH through a WiFi network without router. Make it a DHCP server adding a static IP.

So I can access to it by selecting a WiFi hotspot and then through a web browser to control by a Python HTML sever program (such as Flask)

IMPORTANT: to avoid conflicts with connecting an existing WiFi setup such as a home network which controlled by “NetworkManager.” Turn NetworkManager OFF by editing “/etc/NetworkManager/NetworkManage.conf.

Add below:

[keyfile]
unmanaged-devices=interface-name:wlan0

So no network connection to start from, which means obviously you cannot remotely “ssh” to the RasPi. All configuration has to do within  the RasPi OS GUI with a monitor, mouse and keyboard to open a shell. Then access to the configured WiFi hotspot so you can ssh etc.

NOTE: It looks like you can set up “sudo raspi-config”.
System Options > Wireless LAN > Create hotspot.
But It didn’t work for me. I don’t know why.
Also using GUI (right top corner with WiFi mark) didn’t work neither…

  1. Instead of using an Old method “Ad-hoc (IBSS), I configured using Access Point (AP) mode.
    It requires to install 2 packages “hostapd” (WiFi AP) and “dnsmasq” (DHCP server).

sudo apt install hostapd dnsmasq

  1. Give a static IP

sudo nano /etc/dhcpd.conf

add lines at the bottom, 192.168.4.1 (whatever after 192.168)

interface wlan0
static ip_address=192.168.4.1/24
nohook wha_supplicant

  1. Configure “hostapd”

sudo nano /etc/hostapd/hostapd.conf

add lines at the bottom

interface=wlan0
driver=nl80211
ssid=MyPiNetwork
hw_mode=g
channel=6
wmm_enabled=0

auth_algs=1
wpa=2
wpa_passphrase=strongpassword123
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

Then link config:

sudo nano /etc/default/hostapd

DAEMON_CONF=”/etc/hostapd/hostapd.conf”

  1. Configure DHCP (dnsmaq)

first backup the original:

sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak

edit cdnsmasq.comf, add line at the bottom

interface=wlan0
dhcp-range=192.168.4.10,192.168.4.100,255.255.255.0,24h

  1. Enable and start

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl enable dnsmasq
sudo reboot

  • Check the status

ip a show wlan0

sudo systemctl status hostapd

  • Restart NetworkManager

sudo systemctl restart NetworkManager

  • Restart hostapd

sudo systemctl restart NetworkManager

  • Alternative: nmcli

Create hotspot with:

nmcli dev wifi hotspot ifname wlan0 ssid PiHotspot password YourPassword

lock it down:

nmcli connection modify Hotspot connection.autoconnect yes
nmcli connection modify Hotspot connection.autoconnect-priority 100

Disable existing WiFi connection if you have it on:

nmcli connection show

nmcli connection modify “YourWiFiName” connection.autoconnect no

Now finally you can select “YourWiFiName” from your computer or mobile device.

The PasPi provides a IP address when the connection is established.

NOTE: You cannot access to the internet since it’s just a closed network.