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

This installer is also available on GitHub at https://github.com/RaspberryConnect/AutoHotspot-Installer

 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  
# James 2020-10-24 02:57
Trying to use this with ExpressVPN I'm a total Raspberry Pi newb.

Basically I want to run this hotspot and connect to the vpn and then connect to the hotspot with my Roku so I can watch tv.

But as soon as I connect the VPN I can't connect to the internet.

If I disconnect from the VPN I can connect to the internet and stream with the hotspot... just doesn't work with the vpn.

Is this something that's possible or no?
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-10-24 20:48
Hi James

Yes the setup does work with VPN's but it seems different VPN's have slightly different settings. I have used it with OpenVPN without any changes.

What it may be is ExpressVPN is using a bridge or a custom network device to redirect traffic to the vpn other than eth0. The access point is directing the internet to eth0. If you run the command: ip a
it will list the devices, you should have , lo, wlan0, eth0
if you have a 4th device that is only available when the vpn is active then you need to change some settings from eth0 to the new device.
I don't know if you have installed the static hotspot or a autohotspot but I will presume the static one.

In file /etc/iptables-hs
change any reference to eth0 to the new device and then reboot. Then try the VPN again.

If this dosn't help can you let me know what setup you have installed and what the output to "ip a" and "route" are both with and without the vpn active.
Reply | Reply with quote | Quote | Report to administrator
# James 2020-10-28 19:53
Ok, did

sudo nano iptables-hs

Then I changed all of the eth0 to tun0

tun0 was the fourth device that showed up when connected to ExpressVPN

Still has the same behavior though... once I connect to the VPN I don't have internet.

The fourth device under ip a is "tun0"

The data under the route command is

Destination 0.0.0.0
Gateway 10.40.0.85
Genmask 128.0.0.0
Flags UG
Metric 0
Ref 0
Use 0
Iface tun0
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-10-29 20:57
Hi James

That all look fine as far as I can see should work correctly. The other thing you could check is that ip forwarding is still enabled.

in /etc/sysctl.conf

look for the section below and check there is no # in front of the command as shown here.

# Uncomment the next line to enable packet forwarding for IPv4
#
net.ipv4.ip_forward=1


Let me know if that doesn't help and I will see if I can find a solution.
Reply | Reply with quote | Quote | Report to administrator
# Andrei 2020-10-21 15:49
Will this work on other sbc, like OrangePi ?
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-10-21 20:10
Hi Andrei

This installer is set to only work on Raspberry PI OS (Raspbian) specifically. As Linux uses different network managers I can't guarantee it will work on other setup as it required dhcpcd.


I see Orange Pi has Debian as a listed OS. If that version is using dhcpcd as the network manger instead of dhcp or other network manager then the script will most likely work. The file /etc/network/interfaces must not be used with this as it will conflict. Lots of older guides online will use this file for network config.

you can check with sudo systemctl status dhcpcd

if it returns with Active: active (running) then it probably work if you follow the manual guides.
I would be interested to know if you do try it.

I will look at other OS at a future point and see what needs be modified.
Reply | Reply with quote | Quote | Report to administrator
# DragProt 2020-09-16 18:01
Switching between wifi and hotspot works but does not give internet for connected devices. Connected to 5GHz Wifi before change to option 1 but there is no Internet available after hotspot is activated. Also, when doing a "switch" between 2.4GHz to 5GHz, Pi requires a reboot.
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-09-16 20:41
Hi DragProt

When the hotspot is active are you able to use ssh or VNC to access the Pi? Just to confirm that side is working ok.

Do you have a VPN setup that is using a device such as tun0 to route traffic through then LAN connection? if so your default route may be incorrect.
When the hotspot is active enter route into a terminal
There should be a destination "Default" for "Iface" eth0
This has been tested with openvpn and it works without any changes but not all VPN's are the same.

Can you give me more detail on your setup please, what Pi it is, if you are using a USB wifi adapter, which OS are you using?

The hotspot is only setup for 2.4Ghz connections so I presume you are having issues switching between 5GHZ & 2.4GHZ to your router? When the Pi connects to the router is using standard the wifi setup as your default Wifi settings. As long as your Wifi country is set in Raspi-config or the desktop preferences/Raspbery Pi Config it should be not different than without the autohotspot setup.

Could you give me more details on how you are switching between the two wifi speeds please, and I will look into it further.
Reply | Reply with quote | Quote | Report to administrator
# DragProt 2020-09-17 16:10
After a bit more fussing, I decided to go back to a Base PI load I started from:
2020-05-27-raspios-buster-full-armhf.zip
The first thing I noticed was I could switch between 2.4GHz and 5GHz wireless with no issues.
To answer questions in order.
1. Hotspot active - VNC or ssh work
No. Client does not get compatible IP but even when hard coded, unable to VNC or ssh to PI
2. No VPN installed
3. route command returns no default device
4. PI setup:
PI 4 8GB booted from TDBT case w/ 512GB NVMe Gen3x4 SSD
raspi-config set to US/English
WLan - US
Interfacing Options - Camera, SSH, VNC
5. Attempted different methods to switch between wifi speeds
Console click select
Script run sudo to replace wpa_supplicant.conf with either 5GHz or 2.4GHz settings
Also changed priority so started on 2.4GHz as default based on your suggestions.

Overall Project Plan is a bit grandiose at this point to go into here, but testing multiple platforms to see where pieces can work together. One key piece here is requirement to maintain network connection and failover to hotspot or other network connection capability if network/internet unavailable. The lack of high speed wireless connection may kill this as

Finding the wired/wireless connections interesting as it appears both are 'active' on the base when Ethernet is plugged in.
ifconfig show both eth0 and wlan0 connected with 2 different addresses on base configuration - which would be good. Obviously 2 different network chips/services.

All input would be appreciated....
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-09-17 20:22
Hi DragProt

Thanks for the update.
If VNC and SSH are not working then either Hostapd is not working or the autohotspot script has not run.
The IP is set in the autohotspotN script so if that isn't available then it also suggest the above.

It does seem odd that you are having the same issue with multiple installs.

The installer checks various things are installed ok but can you do some manual checks.

run the autohotspot script manually sudo /usr/bin/autohotspotN
this should tell you its connected to a network.
then change rename your routers ssid in /etc/wpa_supplicant/wpa_supplicant.conf to an unknown ssid so your router is not found.
and run the autohotspotN script again.

You will get feedback as it does the switch.
If no errors then check hostapd is running

sudo systemctl status hostapd, it should say
Active: active (running) in the response.

Let me know what response you get.

for route you should get a default when you are connected to your router and the hotspot but we will deal with the above first.

There will be a separate ip for wifi and eth0 in both setups so you will be able to ssh through eth0 while wifi plays up.

Nothing else in your setup looks to like it would be an issue.

you are welcome to email admin at this site.
An no you are not spamming me I generally answer in the evenings :)
Reply | Reply with quote | Quote | Report to administrator
# DragProt 2020-09-18 15:27
OK. All working on Base PI running 64bit OS. Now back to test on previous setup.
Thanks!
Getting a better understanding of why. So, unless I have a wired connection, there will be no internet even with 2 Wireless adapters. I'll need to work on that as can only use wireless for my project.
Client connection did get assigned correct IP so was able to connect through wireless and get to internet with Ethernet plugged in.
One caveat to this - the second USB WiFi adapter was no longer available on the menu bar, but does show in ifconfig. Can switch default Pi WiFi to any WiFi network now, but unable to associate USB WiFi to a network at all. wlan1 shows in menu pop-up as "Not Associated", but will no longer allow me to associate in menu as I was able to before loading Autohotspot. Further digging obviously required here....
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-09-18 19:06
Hi DragProt

I'm glad you have it all working now.
The setup is designed to get internet through an Ethernet cable for the devices connected to the wifi. So the script can detect if you are connected to a router, wifi is only available for 1 wifi device. This can be changed to wlan1 by changing some of the config but only 1 wifi device will be available.

The permanent hotspot can be reconfigured to run through two wifi devices but currently not the Autohotspot scripts.

I believe it is possible to rewrite some of the script and setup to use wlan0 and wlan1 rather than wlan0 and eth0 which is on my list of future updates but currently I have not looked at that.

If you want to know how to use wlan1 instead of wlan0 let me know but it sounds like it's not quite what you need unfortunately.
Reply | Reply with quote | Quote | Report to administrator
# DragProt 2020-09-18 22:16
Just as another little side note. After the installation of this, you can not change the network options in raspi-config to add an additional network device or attach an additional network device to the network. While wlan1 is seen by the system, attempted changes result in "Could not communicate with wpa_supplicant".
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-09-18 22:59
HI Dragprot

While the hotspot is active wpa_supplicant is disabled otherwise it would conflict with the hotspot and override it.
You can add a new network, ssid, with option 5. Otherwise you have to switch back to network wifi, presuming your router is in range with option 6, and wpa_supplicant will be available again.

When network is available wlan1 and other devices will be available again and disabled during the hotspot.
Reply | Reply with quote | Quote | Report to administrator
# DragProt 2020-09-18 21:39
Thanks... getting me a bit further. Appreciate all the help.
Reply | Reply with quote | Quote | Report to administrator
# DragProt 2020-09-16 21:42
No VPN setup (yet).
route returns:
Kernel IP routing table
Destination Gateway Genmask Flags Metric ect all with nothing in columns.
No USB wifi adapter - using internal network wifi chip
Current configuration:
Raspberry PI 4 8GB USB Boot from 512GB 3D NVMeM.2 2280 SSD in TDBT Case
OS is:
-------------------
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
------------------
Tried with 2.4GHz wifi only. Still does same:
No VNC connection works - no sh either
Wifi RPiHotspot is available and can connect
VPC connection does not connect
Windows machine does not get IP Address from PI, but even hard coding to 192.168.50.10 does not connect with DNS and Gateway set to 192.168.50.5

When on normal Wifi on PI, auto connects to 5GHz and 2.4GHz with no issues.
If changing between 5G and 2.4G, requires a reboot - which I don't like.
Wifi country is set to US and works fine.

I attempted the installation first with complete manual steps and everything worked the same. Have tried this on 2 different boot cards with same results. Both from scratch, made headless, then loaded only the Hotspot - 1 manually, 1 with scripts. Get same results. My initial concerns were:
1. can't switch between 2.4 and 5 without a reboot
2. client connection to hotspot gets no address
3. client hard coded IP still no connection through VNC Viewer
4. network throughput on wireless is at 10% of wired 36 vs. 360 regardless of 2.4 or 5 connection.

Bad PI? Weird Network issues?
About run the gambit on what I can think of....
Reply | Reply with quote | Quote | Report to administrator
# coldnpale 2020-08-14 15:29
Lots of thanks for sharing your script. I tried it this morning and it works great! Something I noticed, however, and wanted to ask if it’s normal or if I did something wrong is thE boot time. Boot Time on my zero w is now considerably longer. The script alone adds about 25 seconds. Does this happen to you too?
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-08-14 17:54
Hi coldnpale, The boot time can be slower on some setups. The autohotspot service starts once they system is fully up. Normally wifi would be available once the network devices are ready. So if you have another app that is slow to load but allows you to use the Pi you may notice it but then the script loads after.

What you can do is change the service so it starts once the network is available which is earlier in the boot sequence. This may not be suitable for everybody but could be fine for you.

I don't know which script you are using, but I presume the direct version.

in /etc/systemd/system/autohotspot.service

change multi-user.target to network.target

[Unit]
Description=Automatically generates an internet Hotspot when a valid ssid is not in range
After=multi-user.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/autohotspot
[Install]
WantedBy=multi-user.target

to

[Unit]
Description=Automatically generates an internet Hotspot when a valid ssid is not in range
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/autohotspot
[Install]
WantedBy=network.target

Then after you reboot it should come up a bit quicker.

This is down to the OS on the SD card as I have a setup that is slower than others run on the same Pi

Let me know if you have any issues.
Reply | Reply with quote | Quote | Report to administrator
# Dale 2020-07-31 19:33
Hi - The script worked great. I chose option 2.

I changed the IP to be 10.0.0.254, modified the dhcp range, SSID and password. I need to add a second IP static IP address to the wifi of 10.0.0.1. How can this be done?

Thank you
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-07-31 20:39
Hi Dale,

You can set a static IP for when it is connected to your router by adding the ip address to /etc/dhcpcd.conf

interface wlan0
static ip_address=10.0.0.1/24

For the access point, wlan0 in dhcpcd.conf is disabled, so those settings will then be ignored. wlan0 control is moved to /etc/dnsmasq.conf and the autohotspot script. I don't believe you can set a second IP address for the access point. If this is what you are after can you give me more detail of what you are trying to set up please.
Reply | Reply with quote | Quote | Report to administrator
# Dale 2020-08-01 00:13
Thanks for the quick reply.

I want to add a secondary IP to the interface. Similar to how you can add multiple IPs to eth0 like:
ip address add 192.168.86.200/24 dev eth0

These are for IoT devices. When activated for the first time they look for instructions from IP 10.0.0.1 port xxxx.
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-08-01 10:24
Hi Dale

That's not something I have looked at before but can be done. In the /usr/bin/autohotspot script where you changed the ip address, add the new IP to the line underneath.

createAdHocNetwork()
{
echo "Creating Hotspot"
ip link set dev "$wifidev" down
ip a add 10.0.0.254/24 brd + dev "$wifidev"
ip a add 10.0.0.1/24 dev "$wifidev"
ip link set dev "$wifidev" up
dhcpcd -k "$wifidev" >/dev/null 2>&1
systemctl start dnsmasq
systemctl start hostapd
}

This will make both IP's available for the access point.

You will not be able to use option 6 on the installer to force the hotspot as that option gets the ip from the first ip line of the autohotspot script.

It will work fine when the pi is booted out of the range of your router.
alternately when your in range of your router, change the ssid in /etc/wpa_supplicant/wpa_supplicant.conf from network={
ssid="mySSID1"

to network={
ssid="mySSID1-off"

and reboot or run sudo /usr/bin/autohotspot
Reply | Reply with quote | Quote | Report to administrator
# Dan 2020-07-21 21:09
Thanks for this. I used option 2 to create the access point on my Raspberry Pi model B+ with the Pi Hut wifi dongle. I can now drive my Lego mounted zoom lens while streaming Raspivid to my laptop with zero lag compared to nearly 20 seconds lag via my home router.
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-07-21 21:37
Hi Dan,
You're welcome, Thanks for the feedback. I'm glad you have found it useful.
Reply | Reply with quote | Quote | Report to administrator
# set hotspot when find valid et 2020-07-18 02:26
hi, i add this at begin of your script to have ever hotspot while eth0 connected on local lan

myipeth="192.168.2.52"
myiphot="192.168.52.1/24"
wifidev="wlan1"
ethdev="eth0"

myeth0=$(ifconfig eth0 | grep inet | tr -s " " | cut -d " " -f 3)

if [ "$myeth0" = $myipeth ]; then
echo "eth0 connected: set hotspot"
ip link set dev "$wifidev" down
ip a add "$myiphot" brd + dev "$wifidev"
ip link set dev "$wifidev" up
dhcpcd -k "$wifidev" >/dev/null 2>&1
systemctl start dnsmasq
systemctl start hostapd

exit
else
echo "eth0 not found: coninue to autohotspot"
fi

ps: thank you for your script, it working very good
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-07-22 08:36
Hi

Thank you for sharing your modification.
Reply | Reply with quote | Quote | Report to administrator
# Jeff A 2020-06-28 15:39
Thank you for this, Worked perfectly on my PizeroW robot on the 1st try. Been looking for an easy way to do this for awhile.
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-06-29 21:52
Hi Jeff

You're welcome, Thanks for the feedback, i'm glad it's useful to you.
Reply | Reply with quote | Quote | Report to administrator
# Fred D 2020-06-24 17:45
For me, the ideal would have 4 options, 1. Change Network settings. 2. Change hotspot settings 3. Use Network 4. Use Hotspot. After an initial setup, you don't ever need 1 or 2 again unless you change something. The automatic feature might be nice where if on power up, it sees no listed network, it goes into hotspot mode from the saved hotspot settings. But when at home, you could override the network wifi mode, test something as a hotspot, and then go back to the network and have it login again to your home wifi. Would it be hard to get the script to do that? I've been trying to learn the scripting language and all network services and settings, but it has been difficult. It is 700 lines of code in a new language. The bottom line for me is to try to prevent a user from having to do anything other than select a simple option. So it needs to be able to create a network or scan for one to enter as the default network, it can't have them open a text file manually and try to enter settings for a previously known network. I'll keep playing in the code. Thanks again!
Reply | Reply with quote | Quote | Report to administrator
# Roboberry 2020-06-24 19:41
Hi Fred

The intention of the script is to install and setup the access point and autohotspot scripts guides found on this site. An alternative option to working through the guide with a few extra features for testing and changing basic settings. It is not intended as a script you would use regularly.

I wrote the script for my own use as I don't want a permanent access point but would like one when im out just to access the Pi.

Using a cron timer it is able to switch between network and access point as it moves in out of range of a router.

Option 6 to force the switch back and forth between access point and Network. The script can't do it automatically as it will always check if the router is range, so never go to a hotspot. So this is the only way to force the access point at home.

You say:
"So it needs to be able to create a network or scan for one to enter as the default network, it can't have them open a text file manually and try to enter settings for a previously known network."

I'm not clear on what you mean here.

If it finds no know wifi network it will create an access point. If you are in a location where there is a wifi network you want to use, you can use option 5, select the wifi ssid in the list and add the password. Then use option 6 to connect to the new network.

The future option that will be added is when it is in Access Point mode it will serve a webpage that these settings can be changed in.

If you email me more details of what the issue is I can tell you if it is possible and what needs changing.
Reply | Reply with quote | Quote | Report to administrator
# Fred D 2020-06-24 15:40
Sorry, I re-read and looked at the script. I see it can switch back and forth. So my only real question is how not to obliterate the existing AP setting. Or do I just write down the ID, PW and IP and put that in the script?
Reply | Reply with quote | Quote | Report to administrator
# Fred D 2020-06-24 15:35
Nathan, I did have another question. I have an image that has all sorts of things setup on it, VNC, SSH, etc. It also comes setup with a working hotspot (AP). It has no networking setup yet. Can the script keep the existing settings for the AP and then add networking to find my home network when at home? And lastly, if I am home, but want to connect to the AP instead and then switch back, can I do it?
Reply | Reply with quote | Quote | Report to administrator
# Roboberry 2020-06-24 19:24
Hi Fred

The Autohotspots for option 1 & 2 wouldn't work with an existing Access Point as the some of the access point setting are needed in the script. If you need a specific ip address setup then the dhcpc-range in dnsmasq needs to be changed along with the IP address in the autohotspot/N script.

You also can't set access point settings in dhcpcd.conf as they won't be used only network settings can be set there.

It really depends on what you are trying to achieve.
Reply | Reply with quote | Quote | Report to administrator
# Omar 2020-06-04 23:00
why if i install openvpn, the connection is not accessible?
Reply | Reply with quote | Quote | Report to administrator
# roboberry 2020-06-05 15:36
Hi Omar

It depends on what you have setup and which mode it is in. If you have the Autohotspot setup and connected to your router via WiFi then it should work fine. If the autohotspot is in Hotspot mode with an ethernet connection or you are using the static hotspot then as far as I know VPN needs additional routing for Devices connected to the hotspot. The Pi should itself be using the VPN just not connected devices.

It is possible, if this is your issue, but I don't have VPN access to see what is required.
Reply | Reply with quote | Quote | Report to administrator
# 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