acTennis
Posts: 14
Joined: Mon Mar 16, 2015 6:47 pm

Automatically connect to open WiFi network

Sun Apr 19, 2015 2:18 pm

Hi all,

I would like my rPi can automatically connect to any open wifi network at boot. I know that editing the wpa_supplicant.def file I can choose which wifi network use but the problem is that I don't know the SSID of the open network to connect. My goal is that the rPi can connect to any open wifi network founded (sure only one network at a time).

So a standard configuration like:

# Open WiFi Network.
network={
ssid="<name_here>"
key_mgmt=NONE
priority=3
}

can't be used.

Can anyone help me ?

Best Regards.

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Automatically connect to open WiFi network

Sun Apr 19, 2015 2:36 pm

Start with https://github.com/jsh2134/iw_parse/ you should be able to hack that to update /etc/wpa_supplicant/wpa_supplicant.conf with any open networks you find.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

acTennis
Posts: 14
Joined: Mon Mar 16, 2015 6:47 pm

Re: Automatically connect to open WiFi network

Mon Apr 20, 2015 6:39 am

Hi,

thanks for reply it's very usefull.

Do you know if is there an equivalent script in other languages? (python is not my best)

Best Regards.

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Automatically connect to open WiFi network

Mon Apr 20, 2015 9:37 am

There's nothing else that I've seen.

Python isn't that awful once you've got over the lack of code block delimiters {} and the insane use of left hand white space as a syntax requirement.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Automatically connect to open WiFi network

Mon Apr 20, 2015 10:13 am

Dooes the following entry in wpa_supplicant.conf not work ??

Code: Select all

# This one is for connecting to any unsecured network your machine comes into contect with, just comment out if you don't like this: 

network={
        key_mgmt=NONE
}
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

acTennis
Posts: 14
Joined: Mon Mar 16, 2015 6:47 pm

Re: Automatically connect to open WiFi network

Mon Apr 20, 2015 2:02 pm

Hi,

the SSID fields seems to be mandatory.

mikerr
Posts: 2827
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Automatically connect to open WiFi network

Mon Apr 20, 2015 2:47 pm

I've used the below at the end of wpa_supplicant.conf for years:

Code: Select all

network={
        key_mgmt=NONE
        priority=-999
}
The low priority is to stop it connecting to an open network when there's one of my known SSIDs in range.

For reference my /etc/netowrk/interfaces is :

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Android app - Raspi Card Imager - download and image SD cards - No PC required !

acTennis
Posts: 14
Joined: Mon Mar 16, 2015 6:47 pm

Re: Automatically connect to open WiFi network

Tue Apr 21, 2015 6:26 am

Hi,

I will try your configuration and I will report my results here.

Thanks for the moment.

acTennis
Posts: 14
Joined: Mon Mar 16, 2015 6:47 pm

Re: Automatically connect to open WiFi network

Thu Apr 23, 2015 5:49 am

Hi all again,

the solution posted by mikerr seems to work but there is an open issue in my configuration.

The board boot with a WiFi adapter and DHCP configuration set in /etc/network/interfaces config file.
If a WiFi connection listed in /etc/wpa_supplicant/wpa_supplicant.conf is present at boot the rPi attach to it but if
the network is not present the rPi remain offline even if the WiFi network become available later.

In other words, only at boot che rPi join the WiFi networks, not during it's time life.

The /etc/network/interfaces file (only wifi part) is:

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

iface default inet dhcp

I miss some configuration parameters ?

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Automatically connect to open WiFi network

Thu Apr 23, 2015 12:26 pm

You MUST have a loopback interface defined or very bad things happen.

Code: Select all

auto lo
iface lo inet loopback
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

MrEngman
Posts: 4036
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Automatically connect to open WiFi network

Thu Apr 23, 2015 1:31 pm

acTennis wrote:Hi all again,

The /etc/network/interfaces file (only wifi part) is:

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

iface default inet dhcp

I miss some configuration parameters ?
First "wlan0 auto" is wrong and should be "auto wlan0". Second, you do not need both "auto wlan0" and "allow-hotplug wlan0".
Only one is needed - "allow-hotplug wlan0" is sufficient.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

acTennis
Posts: 14
Joined: Mon Mar 16, 2015 6:47 pm

Re: Automatically connect to open WiFi network

Thu Apr 23, 2015 7:23 pm

Hi all,

I post my current interfaces file:

Code: Select all

## Loopback interface.
auto lo
iface lo inet loopback

## Wired ethernet interface (DHCP).
iface eth0 inet dhcp

## Wireless interface.
allow-hotplug wlan0
# wpa-roam can only be used with the manual.
iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

## Development interface.
iface develop inet dhcp

## Customer interface.
iface wifi inet dhcp

## Default interface.
iface default inet dhcp
I have this processes running (only networks):

Code: Select all

/usr/sbin/ifplugd -i wlan0 -q -f -u0 -d10 -w -I
/sbin/wpa_supplicant -s -B -P /var/run/wpa_supplicant.wlan0.pid -i wlan0 -W -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf -C /var/run/wpa_supplicant
/sbin/wpa_cli -B -P /var/run/wpa_action.wlan0.pid -i wlan0 -p /var/run/wpa_supplicant -a /sbin/wpa_action
dhclient -v -pf /run/dhclient.wlan0.pid -lf /var/lib/dhcp/dhclient.wlan0.leases wlan0

acTennis
Posts: 14
Joined: Mon Mar 16, 2015 6:47 pm

Re: Automatically connect to open WiFi network

Sat Apr 25, 2015 3:54 pm

Hi all,

now the WiFi network attaches a network also after boot sequence (so it is solved).

For the WiFi open network , in my case set:

Code: Select all

network={
        key_mgmt=NONE
        priority=-999
}
doesn't work.

DineshSam
Posts: 2
Joined: Sun Nov 12, 2017 6:17 pm

Re: Automatically connect to open WiFi network

Sun Nov 12, 2017 6:25 pm

Hi, I’m new to Raspberry pi & linux. I don’t know much about coding but i can understand by reading.
I also want my pi to auto connect to open wifi network. Can you help me to do that? Please post here a step by step coding. I connect to my pi via SSH from my computer.
PLEASE.

Return to “Troubleshooting”