Do you allow this site to use Cookies?

An easy installer script for my AutoHotspot and Static Hotspot setups.  Allows a Raspberry Pi to automatically create a WiFi Hotspot when you are out or connect to your home network when you are home.

This script is for installing a Raspberry Pi WiFi setup where the Pi will connect to a previously configured Wifi network when the Pi is in range of the router or Automatically setup a Raspberry Pi WiFi Hotspot/access point when a known wifi network is not in range.
This can also be run manually or with a timer to switch without a reboot.

There are three guides on this website which show the steps on how to install a permanent Static Hotspot or two setups that can switch between a Raspberry Pi Hotspot or Network connection without a reboot.

These three guides are now available in an Installer. This guide goes through the steps to setup the installer and what features are available.

Intro:

If you have not used the Autohotspot setup's before here is a brief intro to what they can do.

Aim:

  • When you're home:   On starting the Raspberry Pi it connects to your home routers wifi
  • When you're out: On starting, if any known wifi connection is not found it will generate a hotspot so a direct wifi connection can be made to the Raspberry Pi by a tablet, phone or laptop.
  • While in Hotspot mode:  if an ethernet cable is connected the Raspberry Pi, then it will have internet access along with any wifi device connected to the Hotspot.

Additional Features:

Using a Cron, a timer can be setup so the wifi connection can be regularly checked. It will switch between a wifi router and a hotspot without a reboot depending on the results. This is useful for

  • Raspberry Pi in car entertainment systems
  • Raspberry Pi Dash Cams
  • If the RPi looses wifi connection in your garden or near your home when using the camera or sensors.
  • You run a script or program at home connected to your router and wish to monitor it while you are out. As a hotspot is generated without a reboot the script/program is not interrupted.

It is also possible to run the script from a GPIO button so you can manually run the script to switch depending on where you are.

 Requirements:

This has been tested on Raspbian Buster. To see which version you have enter the command lsb_release -a. The scripts via the manual guides below have been tested on Jessie and Stretch and work fine, just this installer has only been tested on Buster.  I would say it should work fine on Stretch and Jessie but a computer is involved so you can never be sure!

  • Raspberry Pi 3, RPi 3 B+, RPi4
  • Raspberry Pi 1 or 2 with a Wifi Dongle*,
  • Raspberry Pi Zero W and Zero with WiFi Dongle* (internet hotspot not useable as it has no ethernet port.
  • Wifi already configured for your home router

*some WiFi dongles don't work in adhoc mode or don't work with with the nl80211 driver used in this guide for RPi4, RPi 3, RPi 3B+ & Pi Zero W inbuilt wifi, so you may want to check this first before starting

The manual guides can be found here

Autohotspot with Net Access  https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/157-raspberry-pi-auto-wifi-hotspot-switch-internet
Autohotspot with NO Net Access  https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/158-raspberry-pi-auto-wifi-hotspot-switch-direct-connection
Permanent Static Hotspot with Internet access  https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/168-raspberry-pi-hotspot-access-point-dhcpcd-method

 Installer:

To use the installer:

open a terminal screen

Download the AutoHotspot-Setup.tar.gz archive to the current folder using the command

curl "https://www.raspberryconnect.com/images/hsinstaller/AutoHotspot-Setup.tar.gz" -o AutoHotspot-Setup.tar.gz
Unarchive the file to the curent folder using the command
tar -xzvf AutoHotspot-Setup.tar.gz
If you are using the Desktop then you can right click on the AutoHotspot-Setup.tar.gz file and select Extract Here

change directory to the Autohotspot folder with
cd Autohotspot
Run the script with the command
sudo ./autohotspot-setup.sh
This script will fail if sudo is not used.

You will presented with these menu option:

1 = Install Autohotspot with Internet for Connected Devices
2 = Install Autohotspot with No Internet for connected devices
3 = Install a Permanent Hotspot with Internet for connected devices
4 = Uninstall Autohotspot or Permanent Hotspot
5 = Add or Change a WiFi network (SSID)
6 = Autohotspot: Force to a Hotspot or Force to Network if SSID in Range
7 = Change the Hotspots SSID and Password
8 = Exit

Option 1: Install Autohotspot with Internet for Connected Devices

Once installed and after a reboot the Raspberry Pi will connect to a router that has previously been connected to and is listed in /etc/wpa_supplicant/wpa_supplicant.conf. If no router is in range then it will generate a WiFi hotspot.
This will have an SSID of RPiHotspot and password of 1234567890
Use option 7 to change the password and also the SSID if required
If an ethernet cable is connected to the Pi that gives access to the internet, then it will allow devices connected to the hotspot access to the internet or local network.
Once a connection to the hotspot has been made you can access the Raspberry Pi via ssh & VNC with
ssh This email address is being protected from spambots. You need JavaScript enabled to view it..5
vnc: 192.168.50.5::5900
for webservers use http://192.168.50.5/

Option 2: Install Autohotspot with No Internet for connected devices


This option is similar to option 1 but connected devices have no internet connection if an ethernet cable is connected.
This has been designed so you can access only the Pi from a Laptop, tablet or phone.
The hotspot SSID will be RPiHotspot with a password of 1234567890
Once a connection to the hotspot has been made you can access the Raspberry Pi via ssh & VNC with
ssh pi@10.0.0.5
vnc: 10.0.0.5::5900
for webservers use http://10.0.0.5/

Option 3: Install a Permanent Hotspot with Internet for connected devices


This is for a permanent WiFi hotspot with internet access for connected devices.
The Raspberry Pi will only have network or internet access when an ethernet cable is connected.
Once a connection to the hotspot has been made you can access the Raspberry Pi via ssh & VNC with
ssh This email address is being protected from spambots. You need JavaScript enabled to view it.
vnc: 192.168.50.10::5900
for webservers use http://192.168.50.10/

Additional setup is required if you wanted to use a second WiFi device to connect to the internet rather than a ethernet conection. This is a planned future option.

Option 4: Uninstall Autohotspot or Permanent Hotspot


This will disable the setup of any of the three setups and return the Raspberry Pi to default Wifi settings.
Hostapd & dnsmasq will not be uninstalled just disabled. This is so a hotspot setup can be re-installed without access to the internet.  

Option 5: Add or Change a WiFi network (SSID)


If you are using either of the autohotspot setups in hotspot modes and wish to connect to a local WiFi network. You will be unable to scan for any networks as the desktop wifi option will be disabled, shown as red crosses. You can manually add the details to /etc/wpa_supplicant/wpa_supplicant.conf if you know them.
This option will allow you to scan for local WiFi networks and update the Pi. If you then reboot or use the Force... option ,see below, then it will connect to the new WiFi network.
This option only works for WiFi networks where only a password is required. If a username is required this will not work. (Planned update)

Option 6: Autohotspot: Force to a Hotspot or Force to Network if SSID in Range

This option is only for the Autohotspot setups.
If you are at home and connected to your home network but would like to use the hotspot. This option will force the pi to hotspot mode and will ignore your home network until the next reboot. If you use this option again while in hotspot mode it will attempt to connect to a known network. This will go back to the hotspot if no valid WiFi network is found or there is a connection issue.

Option 7: Change the Hotspots SSID and Password

By default the hotspot ssid is RPiHotSpot with a password of 1234567890. Use this option to change either or both SSID and Password.
You will be prompted to change both but if you make no entry and press enter the existing setting will be kept.
The password must be at least 8 characters.

Option 8: Exit

Exit the script.

Complete the Setup:

If you have installed a hotspot setup with options, 1,2 or 3 then Reboot to activate the setup.

To test the Hotspot mode for the Autohotspot setups;  run the installer again and select option 6 to force the Pi into Hotspot mode. You can then test that everything is working ok.

When you have finished either choose option 6 again to reconnect to your router or reboot.

Switching Setups:

You can switch between options 1,2 & 3 at anytime. All configuration will be changed removing the config of the previous setup. Just be aware that each setup has a different IP address for the hotspot. If you have changed the Hotspots SSID from RPiHotspot or the password from 1234567890 (which is a good idea) it will be reset back to the defaults.

If you find this guide useful and wish to show your appreciation then you are welcome to make a donation or share a link to this article. There is no obligation to do so, this guide is free for use and support is available to everybody as long as I know the answer :)

RaspberryConnect.com

 

 

Trouble Shooting

If you are in range of your router but the Pi will only create a hotspot even after a reboot then there will be an issue with connecting to your router. This can be caused by an incorrect password or interference especially if you are using 5Mhz wifi on a PI 3B+ or Pi4. 

To check the password either use option 5 or check /etc/wpa_supplicant/wpa_supplicant.conf

If your are having interference issues or believe this setup is the cause then use option 4 to uninstall the setup. Reboot and try your Pi again. If you still have a connection issue it will be an issue within your home network.

If it is this setup then it may be the format of your SSID from your router. It can contain spaces and special characters but not a comma. so "My SSID" will be fine but "My,SSID" will fail.

If your wpa_supplicant.conf file was created using a text editor on Microsoft Windows, though Cr (Carrage Returns) are handled,  there may be hidden formatting characters other than Cr that are causing the issue. Either just use notepad on Windows or backup and delete /etc/wpa_supplicant/wpa_supplicant.conf and create it again using the Raspbian desktop Wifi settings. Headerless setups can setup WiFi networks in raspi-config.  Option 5 will only work if wpa_supplicant.conf already exists.


NFtables Warning.


This setup uses iptables for routing the Hotspots to the internet, options 1 & 3. From Raspbian 10 Buster, IPtables are depreciated in place of NFtables. By default NFtables will handle IPtable rules.
If you know you are using NFtables for a Firewall or other routing rules then don't use the internet routed hotspots and only use option 2, Autohotspot without internet. Otherwise there will be a conflict with your routing tables.
NFtables will be implemented shortly in the next update of the installer and scripts.
Raspbian Stretch (9) & Jessie (8) only use IPtables.
You will be warned when you initally run the installer script if NFtables are active.

/etc/network/interfaces file:

many older hotspot and network setup guides online add entries to the /etc/network/interfaces file. This file is depreciated in Raspbian and any entry in this file is not compatible with these setups. This installer backups and remove any entries found in this file. They will be restored if the uninstall option is used.

 

 


Add comment


Comments  
# Nathan 2020-05-06 08:17
I really like your script. This is fantastic. I've wasted hours on this problem with less skill than you and so things go a lot slower :) I really really want to connect a second wireless card to connect to a network. I'm not using eth0, I just want the Pi to be able to access the internet through wlan1, and an AP hosted on wlan0. The idea being that I can login and administer the Pi through ssh and VNC but I don't need it to pass internet through to wlan0. Could you point me in the direction of the best way to accomplish this with your fantastic code. I'm going to plug in and try and just direct connect, or install wicd and try and use that to connect wlan1 to a network.
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-05-06 20:12
Hi Nathan. Thanks, i'm glad you found it useful.

A wlan0 to Wlan1 setup can only be done on the Permanent Hotspot (option 3) as the Autohotspots (option 1 & 2) shutdown the network wifi to work. This will make wlan1 unavailable to connect to your router.

For the Permanant Hotspot only:
in /etc/dhcpcd.conf replace all the lines under RaspberryConnect with

denyinterface wlan0
interface wlan0
static ip_address=192.168.50.10/24
nohook wpa_supplicant wlan0

This will allow wlan1 to be used alongside the permanent hotspot.
then in /etc/iptables-hs
replace the eth0 entries with wlan1


It looks like wicd is a network manager which won't work with the autohotspot scripts either as they work with dhcpcd only. I don't know if it will work with the permanent hotspot though.

I plan to add wlan1 support for the permanent hotspot and also see if the autohotspots can be adapted to do that as well at a later date.
Reply | Reply with quote | Quote | Report to administrator
# Nathan 2020-05-08 05:15
Thanks again, that solution worked beautifully. I was hoping to make one refinement: I would like to route traffic from localhost/wlan0 to eth0 if eth0 is connected, otherwise to wlan1.

I think this is accomplished mainly through /etc/iptables-hs

currently:
iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
iptables -A FORWARD -i wlan1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o wlan1 -j ACCEPT

should this be changed to:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
iptables -A FORWARD -i wlan1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o wlan1 -j ACCEPT
Reply | Reply with quote | Quote | Report to administrator
# Andy 2020-04-27 19:39
This is really helpful and very well done, thanks!
Reply | Reply with quote | Quote | Report to administrator
# Andy 2020-04-27 18:32
Page states:
ssh
code uses 196.168.50.5
Reply | Reply with quote | Quote | Report to administrator
# Andy 2020-04-27 18:27
I believe there is a bug in the /Autohotspot/config/hostapd file. This line:
DAEMON_CONF="/etc/hostapd/hostapd.config"
should be:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-04-27 19:25
Hi Andy
Thanks for pointing those out. The /default/hostapd file is not required in Buster so didn't show up. I presume you are using Stretch. That's fixed now.
I found the VNC line was 50.10 instead of 50.5 on option1 guide, so I presume that's what you mean. The others look fine. Thanks.
Reply | Reply with quote | Quote | Report to administrator
# Andy 2020-04-27 19:34
50.10 is showing on this page under the "Option 3" heading.
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-04-27 19:41
Hi Andy
that's correct for option 3. The static Hotspot is 50.10. The Auto with net is 50.5 and the auto direct is 0.5.
It's so I can tell them apart when using them and when people ask questions :)

You're welcome, Thanks
Reply | Reply with quote | Quote | Report to administrator