Saturday, 28 May 2016 11:47

Raspberry PI 3 Auto WiFi Hotspot if no Internet

Written by 
  • Author Type: Individual
  • Operating System: Raspbian
  • Country: UK

I'm using a Raspberry Pi 3 which i want to connect to via SSH from my Android tablet or phone when i am not in range of my home router.

My requirements are for when the pi is at home it connects to my home router or other known routers so it is available on the local network. If no router is found when it is started up then it will create a wifi hotspot, which is not rooted to the Internet, so i can SSH to the RPi from another device and control the camera and run other custom scripts.

Previously i could do this by creating an adhoc hotspot on my Android Nexus tablet and set the Raspberry Pi to connect to the Tablet if the home network was not in range. In google's infinite wisdom they dropped this feature for my Nexus tablet in the Android Marshmallow update, meaning i could no longer connect to my pi when i was out and about.

The other solution is for the RPi to create a wifi hotspot and connect my tablet to that. Most tutorials for hotspot setup on the pi are for creating an access point to the internet via the Raspberry pi which is not what I require.
I use my pi for photography amongst other things when im out and about, so i don't need internet access just a direct connection to control the Raspberry Pi via SSH from my tablet.

UPDATE:

This article has been updated as some commands became depreciated, it also uses the more recent systemd start-up process rather than rc.local.

The original script is available here for reference purposes.

If you are using the rc.local script and wish to use this article then just restore the original rc.local file, shown in the original article, and then follow on from "Start-up Script"

 

 This tutorial is the solution I used based on parts of other tutorials i have found online.

Aim:

Raspberry Pi searches for known router's (SSID)

If the router is not found then it creates a hotspot so tablets, phones and computers can connect to the Raspberry Pi's WiFi hotspot, which is not routed to the internet but allows a connection via SSH, VNC etc.

(Internet will not be available via Ethernet either while the hotspot is active but will be restored after a reboot and a known router is in range.)

Requirements:

Raspberry Pi 3, Raspberry Pi ZeroW or other Raspberry Pi with WiFi dongle*

Internet Connection

WiFi connection already set-up to your local router or any routers you are using with this script

*some WiFi dongles don't work in adhoc mode or don't work with with the nl80211 driver used in this guide, so you may want to check this first before starting.

 

Step1:

To start with hostapd hotspot client and dnsmasq lightweight dns server need to be installed.

Open a Terminal session.

Update Raspbian with the latest updates by entering the commands:

sudo apt-get update

sudo apt-get upgrade

 To install hostapd enter the command:

sudo apt-get install hostapd

enter Y when prompted.

To install dnsmasq enter the command:

sudo apt-get install dnsmasq

enter Y when prompted

The installers will have set up the programme so they run when the pi is started. For this setup they only need to be started if the home router is not found. So automatic startup needs to be disabled. This is done with the following commands:

sudo systemctl disable hostapd

sudo systemctl disable dnsmasq

Now the hostspot configuration file can be setup. This contains the name of the WiFi signal you will need to connect to (SSID) and the security password.

To edit the configuration files I will be using the nano text editor but if you prefer an editor with an point and click interface then replace nano with leafpad in the following instructions.

Hostapd Configuration

Using a text editor edit the hostapd configuration file. This file won't exist at this stage so will be blank.

sudo nano /etc/hostapd/hostapd.conf

enter or paste the settings:

interface=wlan0
driver=nl80211
ssid=RPI3hot
hw_mode=g
channel=6
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=TKIP
rsn_pairwise=CCMP

  • The interface will be wlan0
  • The driver nl80211 works with the Raspberry Pi 3 onboard WiFi but you will need to check that your wifi dongle is compatable and can use Access Point mode.

For more information on wifi dongles see elinux.org/RPi_USB_Wi-Fi_Adapters

  • The SSID is the name of the WiFi signal broadcast from the RPi, which you will connect to with your Tablet or phones WiFi settings.
  • Channel can be set between 1 and 13. If you are having trouble connection because of to many wifi signals in your area are using channel 6 then try another channel.
  • Wpa_passphrase is the password you will need to enter when you first connect a device to your Raspberry Pi's hotspot. This should be at least 8 characters and a bit more difficult to guess than my example.

To save the config file press ctrl & o and to exit nano press Ctrl & x

Now the defaults file needs to be updated to point to where the config file is stored.
In terminal enter the command
sudo nano /etc/default/hostapd

Change:
#DAEMON_CONF=""
to
DAEMON_CONF="/etc/hostapd/hostapd.conf"

And save.


dnsmasq configuration

Next dnsmasq need to be configured to allow the PI to act as a router and issue IP addresses.

sudo nano /etc/dnsmasq.conf

Go to the bottom of the file and add the following lines

#Pi3Hotspot Config
#stop DNSmasq from using resolv.conf
no-resolv
#Interface to use
interface=wlan0
bind-interfaces
dhcp-range=10.0.0.3,10.0.0.20,12h

And then save (ctrl & o) and exit (ctrl & x)

Step2:

Now that hostapd and dnsmasq are configured we now need to make some changes to the interfaces file and then add a script that will detect if you are at home or not.

Next we need to edit the interfaces file. There will be several entries already in the file. Look for references to Wlan0 and alter them as below.
Any reference to wpa_conf for wlan0 should be disabled by putting a # at the start of the line.

Open the interfaces file with the command

sudo nano /etc/network/interfaces

edit the following lines as below

auto lo wlan0
iface lo inet loopback

allow-hotplug wlan0
iface wlan0 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

now save (ctrl & o) and exit (ctrl & x)

 

Required only if:

if your home routers SSID and password was listed in this file then the hotspot will probably not get generated.

 

You will need to put a # infront of each line

#iface wlan0 inet dhcp
#       wpa-ssid "mySSID"
#       wpa-psk "Router Pasword"

These details need to be in the wpa_supplicant.conf file to work with this setup.

Add your router details to the wpa_supplicant.conf file with 

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

and add the following commands to the bottom of the file.

network={
        ssid="mySSID"
        psk="Router Password"
        key_mgmt=WPA-PSK
}

If in the future you change your router connection details with the WiFi icon by the clock then check that the changes have been made to the wpa_supplicant.conf file and not the /etc/network/interfaces file.

Note: Change "mySSID" to the ssid of your router and "Router Password" to the password of your router.

Start-up Script

The final stage is to setup the startup-scripts using the systemd process.

if you have been updating Raspbian Jessie and not used a recent image you may not have some wifi tools installed.

just chek you have iw installed with

dpkg -s iw

If it is not found then install it with

sudo apt-get install iw

 

This script will check what routers are available when the RPi is started in the order of mySSID1 mySSID2 etc. The first router found in the list will be connected to using existing configured WiFi settings. If none of the listed SSIDs are in range then a WiFi hotspot is created.

Create the start-up script in a new file in /usr/bin/

sudo nano /usr/bin/autohotspot

 

Enter this script.


#!/bin/bash
#
#Wifi config - if no prefered Wifi generate a hotspot
#enter required ssids: ssids=('ssid1' 'ssid2')
ssids=('mySSID1' 'mySSID2')#Main script
createAdHocNetwork()
{
    ip link set dev wlan0 down
    ip a add 10.0.0.5/24 dev wlan0
    ip link set dev wlan0 up
    systemctl start dnsmasq
    systemctl start hostapd
}
connected=false
for ssid in "${ssids[@]}"
do
    if iw dev wlan0 scan ap-force | grep "$ssid" > /dev/null
    then
        wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1
        if dhclient -1 wlan0
        then
            connected=true
            break
        else
            wpa_cli terminate
            break
        fi
    else
        echo "Not in range, WiFi with SSID:" $ssid
    fi
done
if ! $connected; then
    createAdHocNetwork
fi

in the line ssids=('mySSID1' 'mySSID2')
replace 'mySSID1' with the SSID of your router.

in the UK common SSIDs are in the format of SKY12345, BTHub-1234, TalkTalk12345, VM123456, plusnet1234 etc

If you access other routers then enter them, with single quotes and a space between each entry. The script will try each one and make a connection to the first one that is available.

Then save (ctrl & o) and exit (ctrl & x)

This file is also available to download here

 

make the autohotspot script executable with the command

sudo chmod +x /usr/bin/autohotspot

Next add a service file to systemd.
Create a file in /etc/systemd/system and add the service file

sudo nano /etc/systemd/system/autohotspot.service

 

Enter the script

[Unit]
Description=Generates a non-internet Hotspot for ssh when a listed ssid is not in range.
After=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/autohotspot
[Install]
WantedBy=multi-user.target

 

Then save (ctrl & o) and exit (ctrl & x)

This service file can be downloaded here

now enable the Hotspot service with the command

sudo systemctl enable autohotspot.service

 If you use a Hidden SSID...

If your router does not broadcast the ssid the /usr/bin/autohotspot script will not find your router and always go to a hotspot. By scanning for your MAC address instead of your SSID the script will work.

Your mac address will be printed on your router somewhere in the format XX:XX:XX:XX:XX:XX using letters and numbers.

It can alternately by found using the command

sudo iw wlan0 scan | egrep "BSS|SSID"

Which will return all the routers in range, the top one should be your router.

(My routers ssid is not hidden so you won't see the ssid but my results were as follows)

BSS XX:XX:XX:XX:XX:XX(on wlan0) -- associated
    SSID: XXXXXXXX
    BSS Load:

where X is the address results.

Once your know your MAC address the following changes can be made to the /usr/bin/autohotspot script.

Change:

#enter required ssids: ssids=('ssid1' 'ssid2')
ssids=('mySSID1' 'mySSID2')

for

#enter required MAC Addr: macAdresses=('XX:XX:XX:XX:XX:XX' 'YY:YY:YY:YY:YY:YY')
macAdresses=('MyRouterMACAdress')

 

change:

for ssid in "${ssids[@]}"
do
    if iw dev wlan0 scan ap-force | grep "$ssid" > /dev/null

for

for macAdress in "${macAdresses[@]}"
do
if iw dev wlan0 scan ap-force | grep "$macAdress" > /dev/null

and change

echo "Not in range, WiFi with SSID:" $ssid

for

echo "Not in range, WiFi with MAC:" $macAdress

 

The Router detection should now work for you.

Thanks to Willem Me for supplying these modifications.

 

Testing the Hostspot


To test if the hotspot is being created edit the /usr/bin/autohotspot file again and change your SSID to something else such as mySSID1off

ssids=( 'mySSID1' 'mySSID2' ) to ssids=( 'mySSID1off' 'mySSID2off' )

Save the /usr/bin/autohotspot file and then reboot.

When the desktop loads the WiFi network icon in the top right corner will be two screens instead of the usual WiFi icon.

RPIwifihotspot-wifi

When the mouse is placed over the icon is should show a popup displaying the RPI3hot access point.

RPIwifihotspot-AP

 

Check the WiFi signals in range with the wifi settings on a Laptop, tablet or Phone and you should see that one of them is RPI3hot

wifisignal-android

 

Select RPI3hot as the WiFi signal to connect to. The security password will be the one you set in the hostapd.conf file.

From my example that would be 1234567890.

Now you are connected to the Raspberry Pi's hotspot and you can now open a SSH connection as usual using the IP address 10.0.0.5

Once your happy it is all working, reset the SSID entry back to your routers SSID and your ready to go.

 

This setup has been tested on a Raspberry Pi 2 and PiZero with a WiFi dongle and with a Raspberry Pi 3 and PiZero W all running Raspbian Jessie. 

Wifi and Hotspot Auto Switch Script

I have an alternative script that can switch between wifi and a hotspot without rebooting using a timer or manually.

Details are in this article Raspberry Pi - Auto WiFi Hotspot Switch

Removal

If you no longer require this script then it can easily be disabled without affecting your set-up.

Restore your wifi startup by editing the /etc/network/interfaces file and removing the # from the line # wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Then disable the startup script with the command

sudo systemctl disable autohotspot

After a reboot your RPI will connect to your router.

 Reference:

Tutorials used as reference for the original rc.local article, since adapted for this systemd article:

lcdev.dk/2012/11/18/raspberry-pi-tutorial-connect-to-wifi-or-create-an-encrypted-dhcp-enabled-ad-hoc-network-as-fallback/

nims11.wordpress.com/2013/05/22/using-hostapd-with-dnsmasq-to-create-virtual-wifi-access-point-in-linux/

frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/

 

 

Find the latest and greatest embedded system development kits and boards at Arrow.com!

Last modified on Wednesday, 19 April 2017 21:59
Google
roboberry

RapberryConnect.com SuperUser.  Contactable via the site admin e-mail in the Contact Us link.

Website: www.raspberryconnect.com

Leave a comment

Comments for Guest and account owners. Account owners will need to login to use registered e-mail address.

77 comments

  • Comment Link Graeme Friday, 21 April 2017 21:44 posted by Graeme

    Hi Keith, I know there are issues with hostapd and the realteck chips that don't use the nl80211 driver, but I don't know what issues it causes. There is a version of hostapd that has been modified for the rtl8118 chips, see https://jenssegers.com/43/realtek-rtl8188-based-access-point-on-raspberry-pi may be worth giving that a go. Could try dropping the driver line altogether in the hostapd.conf file which some online comments suggest.

    Try putting it in hotspot mode on a screen and seeing if 'sudo systemctl status -l hostapd' and see if there are any clues. Other issues people have had is the laptop had the wrong encryption mode, not wpa. Your phone should have been fine though.

    If the wifi icon near the clock is show "associated with RPI3Hot" (with the mouse on it) and you can connect to the RPI3Hot wifi signal with your laptop/phone but fails at the password prompt then the password is wrong (unlikely) or hostapd has failed. Any hostapd issues I have had while putting the script together just caused the hotspot not to get generated.
    Other than trying it with a different dongle, if possible, just to check its a compatibility problem. Hope you get it sorted, sound like a fun project.

    Report
  • Comment Link Keith Friday, 21 April 2017 17:49 posted by Keith

    Hi totally out of depth with 'CODE'but have managed to write a script on raspi for a turning pistol target. Want to run it from ssh via laptop in a barn with no wifi or network. Can see the Hotspot on pc&phone etc but after entering passcode returns not able to connect. Have checked and rechecked your writeup but no joy. Going guiddy circles trying to figure whats wrong! No doubt something simple....any ideas where to check? (Raspi 2b with tontec wifi rtll818cus dongle updated driver & hostapd to suit)

    Report
  • Comment Link Graeme Wednesday, 12 April 2017 22:42 posted by Graeme

    Hi Willem Me, Thanks for letting me know about the hidden ssids issue. I will be adding your changes to the guide, very helpful. Thank you.

    Report
  • Comment Link Willem Me Wednesday, 12 April 2017 15:03 posted by Willem Me

    I have asked to fast, I fixed it myself by changing inside script the loop to loop through macAdresses instead of SSID and also changed variables to work with macAdress. Maybe add this finding as note to the script part for others with hidden ssids, but still thank you. (my edited code: ...
    macAdresses=('MyRouterMACAdress')
    ...
    for macAdress in "${macAdresses[@]}"
    do
    if iw dev wlan0 scan ap-force | grep "$macAdress" > /dev/null
    ...
    echo "Not in range, WiFi with MAC:" $macAdress
    ...)

    Report
  • Comment Link Willem Me Wednesday, 12 April 2017 14:20 posted by Willem Me

    Awesome that you made this easy guide! I only have a "small" problem my home ssid is hidden, and it seems the script can't find it. Do you have any suggentions to get this working? Thanks in advance.

    Report
  • Comment Link Graeme Monday, 10 April 2017 12:06 posted by Graeme

    Hi Falko, the driver is nl80211 already, did you mean something different? The set-up has been tested on a PiZero W and worked fine as they are the same as Pi3 :)

    Report
  • Comment Link Graeme Monday, 10 April 2017 12:01 posted by Graeme

    Hi Tony, thanks for highlighting that. I really should stop making changes so late at night. :)

    Report
  • Comment Link falko Sunday, 09 April 2017 22:28 posted by falko

    Hi roboberry

    Had some problem configuring it for pizero w. Found out that in hostapd.conf you need change driver to nl80211 for it to work.

    Report
  • Comment Link Tony Sunday, 09 April 2017 19:34 posted by Tony

    The hostapd defaults configuration still has a typo in it. The A is missing in DAEMON_CONF

    It should say:
    Change:
    #DAEMON_CONF=""
    to
    DAEMON_CONF="/etc/hostapd/hostapd.conf"

    I couldn't see my access point after following these instructions, and that was the problem for me. Once I fixed the typo it all worked.

    Thanks for putting this together. Very handy.

    Report
  • Comment Link Graeme Sunday, 09 April 2017 10:09 posted by Graeme

    Hi Chris, thanks for highlighting the space issue. The article has been updated with your change. Thank you.

    Report
  • Comment Link Chris Friday, 07 April 2017 03:28 posted by Chris

    Great article. Just one issue - my SSID has spaces in, which causes your grep to break. $ssid needs quotes around it to solve this. ie:
    if iw dev wlan0 scan ap-force | grep "$ssid" > /dev/null

    Report
  • Comment Link Graeme Wednesday, 05 April 2017 20:10 posted by Graeme

    Hi Neil, thanks for the info, I use Juice on a Nexus 7 which is Wifi only, so I don't come across issues like that.

    Report
  • Comment Link Neil Wednesday, 05 April 2017 18:02 posted by Neil

    I think I see the same as Ignoto92 on my Nexus 5X. I cna't use Juice SSH to connect to 10.0.0.5.

    However I can connect using my laptop - wonder if android is trying to be too clever as it knows there is no internet...

    I disabled data on my mobile connection and then SSH worked.

    Report
  • Comment Link Graeme Monday, 03 April 2017 20:12 posted by Graeme

    Hi Ignoto92, I have tried a few things but not reproducing your issue exactly. Check dnsmasq is started ok, in AP mode enter sudo systemctl -l status dnsmasq and see if that give an error. Do the same for hostapd just to be sure thats ok.
    If i change the /usr/bin/autohotspot file so dnsmasq doesn’t start I can see RPI3hot and attempt to connect but the ip is never given. So just double check the files. Errors I make at times are using a comma instead of a full stop and general typos.
    If no luck your welcome to send me your config files and I will try it out on my pi's, or if you have further questions. admin@{thiswebsite}

    Report
  • Comment Link Ignoto92 Monday, 03 April 2017 12:11 posted by Ignoto92

    Hey, I've just did it but I can't connect to my Pi in AP mode, it don't give me ip addresses and devices give me an error 'ip configuration erro'; I think this is dnsmasq, how can I resolve?

    Report
  • Comment Link Graeme Sunday, 02 April 2017 19:29 posted by Graeme

    Hi Justin, thanks for that, it should be capitals in older versions as well. :)

    Report
  • Comment Link Justin Sunday, 02 April 2017 04:49 posted by Justin

    Thank you for this.

    There is a typo at the end of the Hostapd Configuration section. The instruction is to change the "demon_conf" line, but that should be "DAEMON_CONF". At least that's how it is in the current version of Raspbian (version March 02 2017).

    Report
  • Comment Link Graeme Tuesday, 28 March 2017 21:46 posted by Graeme

    Hi Manu, in terminal just check what ssid is being found, your need it on a display for this if using ssh, enter : sudo iw dev wlan0 scan ap-force | grep "ATTUverse01" it should return "SSID : ATTUverse01. if it doesn’t then it doesn’t think that ssid is being broadcast. If it does find it stop hostapd and dnsmasq with sudo systemctl stop hostapd, sudo systemctl stop dnsmasq. Then start wifi with: sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf your wifi should come back. If it doesn’t then check your /etc/wpa_supplicant/wpa_supplicant.conf file has the correct details. Because if the: sudo dhclient -1 wlan0 line doesn’t return "RTNETLINK answers: file exists" then the wifi connection has failed so a hotspot get generated.
    Your welcome to email me if you need this looking into further, happy to get you up and running.

    Report
  • Comment Link Manu Monday, 27 March 2017 23:53 posted by Manu

    Hi, got this to work partially on a pi zero with a dongle. The access point is setup fine and I can connect to it. Problem is, even when I put the valid SSID name in the /usr/bin/autohotspot , reboot always results in the hotspot mode - it never connects to my router like it used to.
    I've already reduced the SSID list to just one router and the syntax is ..
    ssids=('ATTUverse01')


    Any suggestions?

    Thanks.

    Report
  • Comment Link Graeme Monday, 20 March 2017 21:33 posted by Graeme

    Hi John, glad the script is useful to you. If you have an external script updating the wpa_supplicant.conf file it should still work as the file is not changed. Does wpa_supplicant points to a different config file? if so change the path in the autohotspot "wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf" to that location.
    or (a very unsecure option) if your /boot/octopi-wpa-supplicant.txt is your config file change the path to that. Can you give more details on how this part is working.
    The autohotspot file can be run from the boot folder so you can just add the SSIDs as you please. Though make sure if you are using windows the file is not saved in dos text format, use unix format.
    You then need to change the path in the /etc/systemd/system/autohotspot.service file to ExecStart=/boot/autohotspot

    It should be possible to take a list of ssids from a file and use them in the ssid variable. If you need that I can have a look.

    let me know if this helps or you can email me further details.

    Report
  • Comment Link Graeme Monday, 20 March 2017 21:12 posted by Graeme

    Hi Jose, so what is happening is your SSID is being detected but your wifi is failing to start, possible because the details in wpa_supplicant.conf are wrong. If the dhclient dosn't detect the wifi has connected it will goto "else". Check your wpa_supplicant.conf file.
    Open terminal and enter: sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf and see what message you get.
    Also just check the wpa_supplicant line in the autohotspot script ends in "> /dev/null 2>&1" i have managed to chop the end of that of a couple of times copying it in. Let me know if you have further issues.

    Report
  • Comment Link John McNerney Monday, 20 March 2017 17:43 posted by John McNerney

    Is there any way to make the list of known WiFi networks get copied automatically from a file in the boot directory into the list in /usr/bin/autohotspot ?

    That, coupled with the method of populating wpa_supplicant.conf with networks from a file in the boot directory (as mentioned in my previous comment or as the ) would make it very simple to add known networks by editing an SD card on a computer. There would be no need to remember what files were where or how to get to them (since the boot directory is easily accessible when an SD card is read in a computer).

    Report
  • Comment Link Jose Moffa Monday, 20 March 2017 15:12 posted by Jose Moffa

    Hello, nice work with this script, it helped me a lot. But i am having a issue, when the script reaches here:

    'if dhclient -1 wlan0'

    That command returns nothing a then fall on else statement. I tried this script on a RPI with a fresh installation.

    Report
  • Comment Link John McNerney Monday, 20 March 2017 03:38 posted by John McNerney

    Thank you SO much for making this available. I'm volunteering with a local elementary school which is using R-Pi's in various projects. Your set up will greatly simplify things for us.

    I do have a question for you, however. Prior to setting up the "Auto WiFi hotspot..." the system we had set up to use a pi to provide wireless access to a 3D printer used to look at the file /boot/octopi-wpa-supplicant.txt for the WiFi configurations. Since the boot directory is the only one that shows up (easily) when plugging the SD card into a computer, it was simple to edit when the SD card via computer when necessary. The information in that file then "magically" appeared in /etc/wpa_supplicant/wpa_supplicant.conf when the Pi was booted up.

    That no longer happens since I set up the auto wifi hotspot. Is there a way to restore that behavior? It was very convenient to be able to access a file easily from a computer to manually enter a wifi set-up - and, since th efile needed to do so was in the boot directory, I didn't need to remember where the various files were.

    Report
  • Comment Link Graeme Sunday, 19 March 2017 20:19 posted by Graeme

    Hi Keith, I’m glad you have found it useful. Will post a version soon that can be swapped between both set-ups without rebooting.

    Report
  • Comment Link Keith Sunday, 19 March 2017 18:31 posted by Keith

    This worked perfect and was just what I needed. Thank you. I have added some more commands to your script to run stuff when I am away from home and not when I return.

    Report
  • Comment Link Graeme Friday, 17 March 2017 19:40 posted by Graeme

    COMMENT DELETED BY MISTAKE: Someone asked about an issue, script works but keeps going to hotspot. Sorry i deleted it not published your comment. Please post again.
    As for issue, check ssid entered correctly for your router in autohotspot example ('myssid')

    Report
  • Comment Link Graeme Monday, 13 March 2017 21:42 posted by Graeme

    Hi Osprey, unfortunately not. Some background files used for wifi have to be cleaned up before the hotspot can be started. I will have another go at it soon. I think it would be useful to save rebooting.
    Update: have it working, script emailed to you

    Report
  • Comment Link Osprey Monday, 13 March 2017 15:38 posted by Osprey

    Thanks Graeme. If I were to somehow run the startup script every, say, 2 minutes, would I achieve what I am after? The reason I am asking (as opposed to just try it) is that I still have to find out how to make a script run at regular intervals.

    Report
  • Comment Link Aden McCusker Saturday, 11 March 2017 06:58 posted by Aden McCusker

    Outstanding! Thank you very much.

    Report
  • Comment Link Graeme Wednesday, 08 March 2017 19:24 posted by Graeme

    Hi Osprey, Maybe possible without a reboot, I will have to look into it further. I have just tried a couple of quick changes to the current setup, but the network wifi takes over the hotspot when the router is back in range and messes about with the connection. If I come up with something I will let you know.

    Report
  • Comment Link Osprey Wednesday, 08 March 2017 16:04 posted by Osprey

    Thanks for the thoroughly explained tutorial. Works as advertised. I was wondering if there was a way to periodically do the process of deciding whether to work as a hotspot or as a client. I have a situation where my car is started in my garage where it connects to the home wifi. However, I need it to switch to hotspot mode as soon as the car leaves the vicinity of my home and then switch back to client mode (and connect to my home wifi) when I get back home.

    Report
  • Comment Link Fi7i Tuesday, 07 March 2017 11:02 posted by Fi7i

    Nice ! Thanks !

    Report
  • Comment Link Graeme Wednesday, 01 March 2017 08:28 posted by Graeme

    Hi burksfamily, I take it the pi still connects to the router when ssid is found, just hotspot not working when ssid not found? Is RPI3Hot being broadcast to wifi devices?
    Set a fake ssid and boot to the desktop. check hostapd is running ok with sudo systemctl -l status hostapd, should get a success message. do the same with autohotspot to see if my script went ok. They should give you a clue if something has gone wrong starting the hotspot. Though strange it not working with a restored os.
    also make sure the autohotspot is executable sudo chmod +x /usr/bin/autohotspot as it won't run if that step is not done.
    If still no luck send me an email with details of your setup and whats happening, can send the config files as well, happy to get you up and running. Hopefully you won't need a late night tonight :)
    Graeme

    Solved: issue due to laptop encryption settings

    Report
  • Comment Link burksfamly Tuesday, 28 February 2017 16:53 posted by burksfamly

    Great instructions.
    Using on a project that is two months in the making.
    1) Performed SD image of my entire OS.
    2) Performed your instructions and checked.
    3) Worked great at 10.0.0.5 with Filezilla and VNC Viewer over Windows laptop.
    4) Performed test to see if switching between ssid (changed to bogus name), ad-hoc, and ethernet cable directly to home network.
    5) That test work with one iteration.
    6) Now I cannot get ad-hoc back and I have tried various ways...different channel...different address range...still no joy.
    7) RESTORED my image card to original.
    8) Performed same instructions...could not get ad-hoc to work.
    9) RESTORED my image card to orignal and repeated...still could not get it to work.
    10) This took 8 hours (until 2 am last night.
    11) I liked what I saw and it is exactly what I need for my project, but I for the life of me cannot figure out why I cannot get it to work again. I realize this doesn't make sense, but I have nothing else to offer.

    Any ideas...will be trying again tonight and looking for other solutions.

    Report
  • Comment Link Matt Monday, 27 February 2017 11:22 posted by Matt

    Awesome!
    Many thanks for your easy to follow instructions!

    Report
  • Comment Link Graeme Wednesday, 22 February 2017 20:33 posted by Graeme

    Hi mafkaan, thanks again for your previous heads up, a few other bits needed updating as well. Adding internet/network access is not something I need, but I have had interest in it being able to get eth0 access in hotspot mode. So i have actually got that on my list of projects. Got some other projects on the go at the moment but I will look into that afterwards and update the article if it goes well.

    Report
  • Comment Link Graeme Wednesday, 22 February 2017 20:18 posted by Graeme

    Hi Stuart, i haven't been able to reproduce your issue, I have changed some bits on hostapd but generally get disassociated. use the command sudo system status -l hostapd this should give you a clue if hostapd is ok. If you have no luck e-mail me the details of your pi and setup and I will see if i can find the issue. admin@ this site

    Report
  • Comment Link mafkaan Wednesday, 22 February 2017 10:03 posted by mafkaan

    Hi again.
    The update looks great. very neat
    I was wondering. could you add a paragraph on how to make this forward the internet to the clients when pi is connected to internet by ethernet. It could become a range extender or hotspot when at a hotel or something.

    Report
  • Comment Link Stuart Wednesday, 22 February 2017 00:00 posted by Stuart

    Hey, so I followed the instructions here. However, when I go to test the hotspot I get the icon with two screens, but the information given is wlan0: Associated with and then blank, no name given. No signals visible on any wifi devices. I think I'm creating the hotspot but not broadcasting a discoverable name? I've checked in the hostapd.conf file and there's definitely a ssid name there. Any help would be appreciated.

    Report
  • Comment Link Graeme Tuesday, 21 February 2017 19:24 posted by Graeme

    Note: All comments below are for the original rc.local version of this hotspot article not the latest version using systemd

    Report
  • Comment Link Graeme Monday, 13 February 2017 10:49 posted by Graeme

    Hi Mateusz, as long as you are using a PI3 or AP capable wifi dongle and there is no typo errors it should work fine.
    If you would like to e-mail me details of your set up, OS and the issue I can help you with the setup. But to reverse the changes you need to restore your rc.local file so it is the same as the first section under "Start-up Script" in the article.
    Then in the /etc/network/interfaces file, reverse the changes there. No need to change anything else. On reboot it will connect to the default WiFi settings.

    Report
  • Comment Link Mateusz Sunday, 12 February 2017 17:57 posted by Mateusz

    hi, can someone tell me how go back with all settings, because its not working and also i cant connect to my home wifi

    Report
  • Comment Link Graeme Friday, 10 February 2017 19:58 posted by Graeme

    hi rober2ce
    the hotspot will be generating because the ssid entered is not available. make sure there is single quote either side 'ssid1'
    for two ssids try a space in-between rather than a comma
    ssids=('ssid1' 'ssid2')
    It seems some things have changed since the script was written. Let me know if you still have problems.

    Report
  • Comment Link rober2ce Wednesday, 08 February 2017 05:37 posted by rober2ce

    You guide was quite helpful. I had everything working well but when I tried to add a second ssid it no longer worked. I tried to go back to one ssid but now that no longer works either. Not sure what is going on but the wifi will no longer connect and the hotspot is always on.

    Report
  • Comment Link Graeme Monday, 06 February 2017 19:49 posted by Graeme

    Hi John, if you want two wifi connections you will need a wifi dongle attchaed to a pi3 or 2 wifi dongles connected the Pi 1 & 2. You will then set the second wifi up on wlan1 with this hotspot on wlan0. You will need to activate the IP tables for wlan1 as well to route to the internet.
    I havenen't tried a set up like that so don't know exactly what you need to get it working but this script will not go online once activated as a hotspot via ethernet either.
    Also if you have a new raspian image you may have issues as pointed out by mafkaan below.

    Report
  • Comment Link john  hewitt Monday, 06 February 2017 14:56 posted by john hewitt

    this is great, will try it. I have been running my Pi as an access point and realVNC server which works great. Will be great to be able todynamically start up the access point from a script.

    My question is normally I plug in my access point to home router to get internet, but there has to be a way to get internet access wirelessly too right? in other words a hotspot for my hotspot. how would one proceed?
    if anyone with ideas could email me too that would be great, john@hewitt123.com

    Report
  • Comment Link Graeme Saturday, 21 January 2017 20:40 posted by Graeme

    Hi Alec, if you have been updating an existing Raspian distro with get-apt you should be fine, my ones are all running Pixel and up to date. From Mafkann's comments there looks to be an issue if you use one of the latest Raspbian images. Try: Edit the SSID so it's not your routers and reboot, then run sudo /etc/rc.local from terminal. You can see any messages that is too fast during bootup. Also run hostapd in debug mode and see if that reports and issue as that is most likely the cause.
    sudo hostapd -d /etc/hostapd/hostapd.conf
    I presume you are using a PI3 or suitable Wifi dongle with AP mode.
    Let me know if this doesn’t help and I will look into it further.

    Report
  • Comment Link Alec G Friday, 20 January 2017 04:09 posted by Alec G

    Hi there, I followed the tutorial to the letter, and I cannot seem to get the last part. The Pi can connect to my router when it is active, but when I disconnect it to test the creation of the hotspot, the wifi symbol changes to two lines with an X on either side with wlan0 saying that it is not associated. I cannot tell if there is an error I made somewhere, or if it is an error due to me being on the latest update as of now. Any help would be appreciated. Thanks

    Report
  • Comment Link Graeme Friday, 13 January 2017 21:01 posted by Graeme

    Hi Mafkann, thanks for the update on iwlist. still working for me on my up to date Pi's, presumable it affects new installs and not rolling updates as my Pi's are. I plan to make a few updates to this process soon so will look into the depreciations. thanks

    Report
  • Comment Link mafkaan Thursday, 12 January 2017 08:09 posted by mafkaan

    thanks. made it work
    I had not seen this was an older post so...

    few things I needed to work out. in /etc/rc.local
    ssids=( 'mySSID1','mySSID2' ) had to be space delimeted like this
    ssids=( 'mySSID1' 'mySSID2' )
    I had found out, it was treated as one long string so use spaces around
    The other was 'iwlist' seems to be deprecated. I found with google search. the command had to be 'iw dev wlan scan ap-force' run as superuser
    the lines changed : became
    ssids=( 'mySSID1' 'mySSID2' )
    if iw dev wlan0 scan ap-force | grep $ssid > /dev/null

    Using Jessie ( lite ) from november 2016
    - iw was already setup so no need to go install it

    Hope someone will benefit from this in the future

    Report
  • Comment Link Graeme Thursday, 29 December 2016 21:13 posted by Graeme

    Hi Oj, I think your routers password in /etc/wpa_supplicant/wpa_supplicant.conf is not correct. Check the entry for psk="" has the correct password. Also if your routers ssid and password are in /etc/network/interfaces then put a # infront of each line.
    #iface wlan0 inet dhcp
    # wpa-ssid "mySSID"
    # wpa-psk "Router Pasword"

    Hope this helps, let me know if this doesn’t work and I will look into it further. :)

    Report
  • Comment Link 0j Wednesday, 28 December 2016 21:51 posted by 0j

    Thank you for such usefull script.
    However I have problem

    However I got a problem to connect back to my home wifi.
    when running rc.local I got respond on "Obtaining IP from DHCP"

    Report
  • Comment Link Robert H Friday, 23 December 2016 22:46 posted by Robert H

    If anyone if having trouble with the rc.local script not resolving your AP name, change the following line in rc.local

    FROM
    ssids=( 'mySSID1','mySSID2' )
    TO
    declare -a ssids=( "mySSID1" "mySSID2" )

    Report
  • Comment Link Graeme Tuesday, 29 November 2016 19:18 posted by Graeme

    Hi Vishal, glad you have it working, not sure what's going on with that. It worked when it was originally tested. I will have to look into that further.

    Report
  • Comment Link Vishal Verma Tuesday, 29 November 2016 02:32 posted by Vishal Verma

    Thanks Graeme for the feedback and resolution. I removed the multiple values from ssids=( 'mySSID1','mySSID2' ); and changed to have only one entry of my wifi router ssid, and it worked perfectly. Appreciate your help. Thanks again. Regards, Vishal

    Report
  • Comment Link Graeme Friday, 25 November 2016 22:52 posted by Graeme

    Hi Vishal, the rc.local script is not detecting your SSID as it is written, if it does detected the ssid but network config was wrong it would not go to a hotspot. Do you have more than 1 ssid entered, if so just try 1.
    You can run rc.local on its own with the command sudo /etc/rc.local
    you will see what decision it makes.
    Email me if no luck so I can help further. admin@ this website

    Report
  • Comment Link Vishal Verma Friday, 25 November 2016 09:47 posted by Vishal Verma

    Hi, Firstly thanks for the great step by step instructions. I am able to have my pi as an access point and SSH from my laptop to the pi with RPI3Wifi hotspot. But now the pi never connects to the home wifi router. Have changed the setting in rc.local. There is only one entry in wpa_supplicant.conf for the home wifi router. But it never gets that (even after reboot). Request help here. Regards, Vishal

    Report
  • Comment Link Graeme Thursday, 24 November 2016 19:09 posted by Graeme

    Hi Dimitar, sorry to hear it didn't work for you, if you want to try again you can e-mail me for support. As for removing it it sounds like you have done what is needed. the IP of 10.0.0.5 is only set in rc.local so if that has been removed then I would check your WiFi settings with the Icon next to the clock. There should be no entry for the RPI3wifi or 10.0.0.5. Or check wpa_Supplicant.conf and make sure only your routers SSID is listed. If it is in your WifI settings then that probably will be why it didn't work. let me know if you need further information.

    Report
  • Comment Link Dimitar Sunday, 20 November 2016 23:38 posted by Dimitar

    Hello,
    I tried to follow the instructions, but it did not work for me.
    Now I try to go back before I started but when RPI boots it always comes with the IP address of 10.0.0.5 - can't connect to internet
    If I run sudo dhclient wlan0 - then I get a new ip address and i can connect to internet
    but if I reboot again - it comes back with IP 10.0.0.5 again
    How can I fix that?

    I am using Raspberry Pi 3.
    I removed the script from rc.local
    in/etc/network/interfaces I uncommented
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    I checked that both services are disabled - dnsmasq and hostapd
    I did not revert the changes in/etc/dnsmasq.conf and/etc/default/hostapd

    Report
  • Comment Link Dan Saturday, 05 November 2016 18:14 posted by Dan

    Hello,
    I have an issue, that is although my Raspberry Pi 3 has successfully be an auto wifi hotspot thanks to your tutorial, but when i pluged in the ethernet cable, my PI cannot connect to Internet (but still connect to LAN, i still can SSH it over IP 192.168.1.7). Other devices connect to my home network (cellphone, Laptop,etc...) still can connect to the internet, exept my PI
    So please tell me how to fix it?

    Response: In Hotspot mode no internet can be used even with a LAN cable connected. Once the SSID is recognised the internet is available.

    Report
  • Comment Link Graeme Monday, 31 October 2016 20:17 posted by Graeme

    Hi JI, i have tried various settings, i think your hotspot is being triggered because your router is not being detected which would be why dnsmasq is always active. The messages "No Wireless interface" is shown when the hotspot is active. can you e-mail me at admin@ this website, with a bit more detail of what is happening, also are you using a Pi3 or using a wifi adapter?
    SOLVED: hostapd password only 4 digits, minimum 8

    Report
  • Comment Link Graeme Monday, 31 October 2016 20:06 posted by Graeme

    Hi Ralf, check to make sure the SSID has also changed in the wpa_supplicant.conf file. This is usually where the details will be when they have been changed by the wifi icon by the clock. I have recently added details about the main wifi ssid and password in Step2 just above Start-up Script. let me know if this helps.

    Report
  • Comment Link Ralf Monday, 31 October 2016 12:46 posted by Ralf

    Thank you for this tutorial, the hotspot is working fine, but my router isn't recogniced any more. I changed the SSID of my router in the rc.local file and I tried even an other SSID but it's not working or better it's not finding my router. What can I do?

    Report
  • Comment Link JI Saturday, 29 October 2016 21:33 posted by JI

    First of all thank you for your quickly answer.
    I tried the "wpa_supplicant -B" line and WiFi still not working. I tried the other two options but enemas status continues being "active (running) since..."
    Another thing is that when I click on the double vertical line it says "No wireless interfaces found"
    Any new suggestions?

    Report
  • Comment Link Graeme Friday, 28 October 2016 20:01 posted by Graeme

    Hi Paul, it is possible there is another dns server running such as udhcpd or isc-dhcp-server.
    if you run the command "ip addr" you should get two inet entries under WLAN0. one should be 10.0.05 and the other the same as the wifi icon shows. my one is 169.254.71.151. If 10.0.0.5 is not showing then I believe something else is issuing an ip address.
    use sudo systemctl status udhcpd or isc-dhcp-server to see if they are running.

    Report
  • Comment Link Paul Atredies Friday, 28 October 2016 02:41 posted by Paul Atredies

    The tutorial works for setting up the hotspot to logon only to the pi, however it is issuing itself a strange Ipaddress that is not the 10.0.0.5 address, nor can I use the hostname to SSH into the pi. Any suggestions as to why?

    Report
  • Comment Link Graeme Thursday, 27 October 2016 22:00 posted by Graeme

    Hi JI, I also have this running on a Pi3 with Pixel. I have managed to replicate your issue. If you copy the long line from rc.local starting with wpa_supplicant -B and paste it into terminal (preceded by sudo) does your wifi come back? it will only be for this session though.
    If systemctl disable is not working then try "sudo update-rc.d dnsmasq disable" and the same for hostapd. If no luck then check the /etc/default/dnsmasq file and change ENABLED=1 to ENABLED=0.

    The issue is dnsmasq is still running at boot so your wifi won't connect to your network.
    let me know if this works or if you still have an issue.

    Report
  • Comment Link JI Thursday, 27 October 2016 11:13 posted by JI

    I did all the steps but is not working. It not create a wifi
    I have the new pixel interface and the icon is a double vertical line with two red X on it. When i put the mouse on it I get:

    eth0: link is down
    wlan0: not associated

    I check the hostapd and dnsmasq status and they are active. I redo "sudo systemctl disable dnsmasq" and "sudo systemctl disable hostapd" and they still active (with and without a reboot).

    What can I do to fix it?

    Report
  • Comment Link Striker Monday, 17 October 2016 19:32 posted by Striker

    Hello. I did this and now my wifi icon dissapeared. I did everything as in the tutorial so i dont know what could be wrong. Any ideas of what could be or how to undo everything? Thanks

    Hi, if you are getting two screens instead of a Wifi icon, as shown at the bottom of the article, then it is generating a hotspot and not connecting to your router. Make sure the SSID is the same as your router in rc.local, also hostapd maybe running at boot. check this with
    "sudo systemctl status hostapd" and "sudo systemctl status dnsmasq" if there is a green text saying Active (i think) then they are running at boot. redo "sudo systemctl disable dnsmasq" and "sudo systemctl disable hostapd" and try again.
    Are you using a Pi3? to reverse; remove the added script from /etc/rc.local and in the /etc/network/interfaces remove the # from "# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf"
    e-mail me if you have further issues, happy to help get it up and running for you.

    Report
  • Comment Link Vijayenthiran Tuesday, 20 September 2016 12:07 posted by Vijayenthiran

    In the sudo nano /etc/hostapd/hostapd.conf

    commenting out driver=nl80211 works for raspberry pi 3.

    Report
  • Comment Link Graeme Thursday, 01 September 2016 19:07 posted by Graeme

    Hi Rob, i no expert at networking but i think you need to add a wifi dongle to use Wlan1. Instead of using a static IP are you able to connect via a Host name for your network set up. Then the interfaces setup can be set to manual. I connect to my PI's at home via there host name and the Hotspot IP when out.
    I'm happy to try some static/manual setting on my set up to see what works if need be.

    Report
  • Comment Link Rob Thursday, 01 September 2016 00:18 posted by Rob

    This looks really useful, I just seem to be hitting a snag (it's late and it's probably me).
    I've got my Pi set on a static IP address for my home network using the network interfaces file on wlan0. Will changing wlan0 from static to manual mess that up?
    Could I have wlan0 set to static and wlan1 set to manual to get round this?
    Sorry if this is an obvious question.

    Report
  • Comment Link Graeme Wednesday, 03 August 2016 20:35 posted by Graeme

    Hi Emanon, the Wifi password is stored in the the WPA_supplicant.conf file, but the wifi connection can be setup normally via the WiFi icon in the top right corner of the desktop. To have it as a preferred connection then add it to the ssids=(...) list in the rc.local file. The pi will broadcast 2 IP's one similar to the one stated and 10.0.0.5 set in the script. Use 10.0.0.5. I don't think the host name is reliable for this but it works fine with the IP.
    For the connection issue; are you using a RPi3 or other model with a WiFi dongle? if using dongle it may not be compatible with AP mode.
    I have just checked out a Pi2 with wifi dongle which did create a hotspot but kept dropping the connection. This was probably because of power issues on the battery as it was fine plugged into the mains.
    If you have no luck then e-mail me to try and sort it out (link in contact us)

    Report
  • Comment Link emanon Tuesday, 02 August 2016 01:06 posted by emanon

    thanks for this tutorial! However, by default the machine doesn't connect to the default router (where do I set the password for it, by the way? Is it still the wpa_supplicant file?) and creates a hotspot. I suceed in connecting to it, but I can't ssh the pi (neither by its host name nor by the ip. The IP the hotspot gives me seems to be in a completely different network (169.254.78.193). Any ideas?

    Report
  • Comment Link Graeme Saturday, 11 June 2016 12:37 posted by Graeme

    hi, it uses an infrastructure Access Point, not a AdHoc connection. The pi doubles as a router so all devices connect to the pi's router (RPI3hot) so they are on the same network and communicate via the router and not directly connected to each other. For a ssh connection with a Tablet both the pi and the tablet are communication via the pi's router, even though there is physically only two devices from a network point of view there are 3.

    Report
  • Comment Link Alejandro Saturday, 11 June 2016 05:49 posted by Alejandro

    Hi, one question... This is a kind of Ad-Hoc conection?? I'm looking for that hours and hours and I can't find anything!

    Report

Additional information