# Turn On Raspberry Pi Hotspot If Not Online
If you follow these steps there's no need to follow [[Turning Raspberry Pi Wi-Fi Off If Connected Over Ethernet]].
1. Run
	```shell
	sudo apt install hostapd dnsmasq
	sudo systemctl unmask hostapd
	sudo systemctl disable hostapd
	sudo systemctl disable dnsmasq
	```
2. Add `/etc/hostapd/hostapd.conf` (listed below). This file includes the SSID and the password of the hotspot
3. Set the following in `/etc/default/hostapd`:
	```ini
	DAEMON_CONF="/etc/hostapd/hostapd.conf"
	#DAEMON_OPTS=""
	````
4. Modify the `/etc/dnsmasq.conf` file by adding the following lines to the bottom
	```ini
	#AutoHotspot Config
	#stop DNSmasq from using resolv.conf
	interface=wlan0
	no-resolv
	bind-interfaces
	dhcp-range=10.0.0.50,10.0.0.100,12h
	````
5. Modify the` /etc/dhcpcd.conf` file by adding the following line to the bottom:
	`nohook wpa_supplicant`
6. Create `/etc/systemd/system/autohotspot.service` with the contents listed below
7. Run `sudo systemctl enable autohotspot.service`
8. Copy the `autohotspot` script (listed below) to `/usr/bin/autohotspot`
9. Run `sudo chmod +x /usr/bin/autohotspot`
## `/etc/hostapd/hostapd.conf`
```ini
#2.4GHz setup wifi 80211 b,g,n
interface=wlan0
driver=nl80211
ssid=RPiHotspot
hw_mode=g
channel=8
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=1234567890
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP TKIP
rsn_pairwise=CCMP
#80211n - Change GB to your WiFi country code
country_code=GB
ieee80211n=1
ieee80211d=1
```
## `/etc/systemd/system/autohotspot.service`
```ini
[Unit]
Description=Automatically generates a Hotspot when a valid SSID is in range
After=multi-user.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/autohotspot
[Install]
WantedBy=multi-user.target
```
## `autohotspot`
```bash
#!/bin/bash
#version 0.95-41-N/HS
#You may share this script on the condition a reference to RaspberryConnect.com 
#must be included in copies or derivatives of this script. 
#A script to switch between a wifi network and a non internet routed Hotspot
#Works at startup or with a seperate timer or manually without a reboot
#Other setup required find out more at
#http://www.raspberryconnect.com
wifidev="wlan0" #device name to use. Default is wlan0.
#use the command: iw dev ,to see wifi interface name 
IFSdef=$IFS
cnt=0
#These four lines capture the wifi networks the RPi is setup to use
wpassid=$(awk '/ssid="/{ print $0 }' /etc/wpa_supplicant/wpa_supplicant.conf | awk -F'ssid=' '{ print $2 }' ORS=',' | sed 's/\"/''/g' | sed 's/,$//')
wpassid=$(echo "${wpassid//[