Auto-connect to wireless nets?
Hey all.
So, I have a wireless dongle and can attach fine to my home wireless network, having set up /etc/network/interfaces to connect to that one ESSID using WPA. Of course, that relies on a very precise configuration.
However, I'll be depending often on mobile use with the RPi, which means no handy monitor and keyboard, so I want to simply power on the RPi and have it automatically join whichever open wireless network it can reach. Since I have the RPi registering itself via Bonjour/Avahi, I can then SSH to it using raspberrypi.local.
And so, how would I configure Debian to auto-connect to any open wireless AP?
So, I have a wireless dongle and can attach fine to my home wireless network, having set up /etc/network/interfaces to connect to that one ESSID using WPA. Of course, that relies on a very precise configuration.
However, I'll be depending often on mobile use with the RPi, which means no handy monitor and keyboard, so I want to simply power on the RPi and have it automatically join whichever open wireless network it can reach. Since I have the RPi registering itself via Bonjour/Avahi, I can then SSH to it using raspberrypi.local.
And so, how would I configure Debian to auto-connect to any open wireless AP?
Re: Auto-connect to wireless nets?
Crazy idea off the top of my head
Have a script that is run every minute that will -
Check to see if wlan0 is connected with the command
if it is then do nothing
if it is not connected
do a wifi scan with
to
get the name of an open network
and then
to connect
Have a script that is run every minute that will -
Check to see if wlan0 is connected with the
Code: Select all
iwconfig
if it is then do nothing
if it is not connected
do a wifi scan with
Code: Select all
iwlist wlan0 scan
get the name of an open network
and then
Code: Select all
iwconfig wlan0 essid NETWORK_ID
dhclient wlan0
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044
Re: Auto-connect to wireless nets?
wpa-roam does this exactly.
Have a quick google, otherwise I'll dig out an example config when I can.
Have a quick google, otherwise I'll dig out an example config when I can.
Re: Auto-connect to wireless nets?
This config has been working for me on my Raspbian wheezy install.
/etc/network/interfaces
/etc/wpa_supplicant/wpa_supplicant.conf
/etc/network/interfaces
Code: Select all
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface home inet dhcp
iface work inet dhcp
iface default inet dhcp
Code: Select all
network={
ssid="Acme Corp"
scan_ssid=1
psk=abc123
id_str="work"
priority=5
network={
ssid="Linksys"
scan_ssid=1
psk=abc123
id_str="home"
priority=5
network={
key_mgmt=NONE
}
-
- Posts: 19
- Joined: Mon May 28, 2012 7:44 pm
Re: Auto-connect to wireless nets?
Although its probably inefficient and takes uses more CPU, I use Wicd. Just install with "apt-get install wicd-gtk" It provides a nice GUI for configuring wireless networks, and there is an option to automatically connect to certain networks
Re: Auto-connect to wireless nets?
I'm using wicd-curses...takes 1-2 minutes but works great.
Greets,
Michael
Greets,
Michael
Re: Auto-connect to wireless nets?
Automatically selecting a wireless router with a specific priority is exactly what I need. So I tried your example (modified for my SSID, Password, etc.) and I am getting the following errors. A Google search indicates that something is possibly wrong with the format of the file:r1cht3r wrote:This config has been working for me on my Raspbian wheezy install.
wpa_supplicant: /sbin/wpa_supplicant daemon failed to start
run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
Failed to connect to wpa_supplicant - wpa_ctrl_open: No such file or directory
wpa_supplicant: /sbin/wpa_cli daemon failed to start
run-parts: /etc/network/if-up.d/wpasupplicant exited with return code 1
I can connect wirelessly with a simple setup (without using wpa_supplicant), so I know that everything is in working condition.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
Well, solved that problem. The network sections of the wpa_supplicant.conf file are missing the closing curly brackets. However, I still cannot connect to my routers.pjc123 wrote:Automatically selecting a wireless router with a specific priority is exactly what I need. So I tried your example (modified for my SSID, Password, etc.) and I am getting the following errors. A Google search indicates that something is possibly wrong with the format of the file:r1cht3r wrote:This config has been working for me on my Raspbian wheezy install.
wpa_supplicant: /sbin/wpa_supplicant daemon failed to start
run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
Failed to connect to wpa_supplicant - wpa_ctrl_open: No such file or directory
wpa_supplicant: /sbin/wpa_cli daemon failed to start
run-parts: /etc/network/if-up.d/wpasupplicant exited with return code 1
I can connect wirelessly with a simple setup (without using wpa_supplicant), so I know that everything is in working condition.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
Between reading all the /usr/share/doc/wpa_supplicant documentation and some experimenting with the various parameters, I finally have everything working. Now:
1) During bootup, wpa_supplicant searches through each router I have listed in wpa_supplicant.conf (more importantly in the proper order), then chooses the first active router it finds, and finally assigns a DHCP ip address to wlan0. If there is no wifi dongle connected, it uses the wired connection eth0. This operation was critical for my headless pi configuration.
2) I can now connect to my routers that have a hidden SSID (SSID not broadcasted), which was not possible with just the /etc/network file by itself without using wpa_supplicant.conf. I disable broadcasts for security reasons.
3) As an added bonus, the wpa_supplicant file does not think that the character "\" is an escape character in the password field, unlike the /etc/network file by itself without using wpa_supplicant.conf, which required that it be escaped with another escape character "\\".
1) During bootup, wpa_supplicant searches through each router I have listed in wpa_supplicant.conf (more importantly in the proper order), then chooses the first active router it finds, and finally assigns a DHCP ip address to wlan0. If there is no wifi dongle connected, it uses the wired connection eth0. This operation was critical for my headless pi configuration.
2) I can now connect to my routers that have a hidden SSID (SSID not broadcasted), which was not possible with just the /etc/network file by itself without using wpa_supplicant.conf. I disable broadcasts for security reasons.
3) As an added bonus, the wpa_supplicant file does not think that the character "\" is an escape character in the password field, unlike the /etc/network file by itself without using wpa_supplicant.conf, which required that it be escaped with another escape character "\\".
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
pjc123 can you share your script ? autoconnect
Re: Auto-connect to wireless nets?
I haven't used the pi in a couple of months, so let me see if it still works. The cat plays with the wiring, so no guarantee. What have you tried so far? Have you read any of the documentation that I pointed to?lizdainis wrote:pjc123 can you share your script ? autoconnect
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
First of all, don't expect to just copy my scripts and expect them to magically work for your application. You might find it a lot easier to use one of the gui applications like wicd, although I don't know their capabilities. For me, I like to know what is going on, so I usually work with simple files whenever I configure something. Because I have these files set up for my specific routers, and to perform certain specific tasks, there are probably items you do not need and/or you need to modify for your case. OK, now that the disclaimer is behind us......Oh, wait a minute, one more......The following was set up and tested with Wheezy Debian dated 06-18-2012. OK, some items you might need to change:lizdainis wrote:pjc123 can you share your script ? autoconnect
1) The config files scan for multiple routers, in the order given in the wpa_supplicant file. I am not sure if that is what you mean by “autoconnect”. If so, the sections labeled win7 and duane in both files are what are used in both files to differentiate each router (Change the names to what you feel is appropriate, as long as they match in both files). If what you mean by “autoconnect” is to connect to public routers that may be available, then you need to un-comment the last four lines of the wpa_supplicant file (Remove the pound symbols). Note that I have not tested that feature. I have seen it used with and without the ssid=”” parameter.
2) Scan for routers with a hidden SSID (Not broadcasted). There are several lines in the files that are specifically set up for this including setting ap_scan=2 and scan_ssid=1. Note that the priority field is ignored when setting ap_scan=2, and the routers are searched for in the order that they appear in the config file. Also, the following four security parameters must be set explicity for each router, meaning not having multiple values on each line, and the values must be exactly correct: key_mgmt, pairwise, group and proto.
3) I have two different wifi dongles that I use (An Edimax and a TP-Link). If you only have one wireless dongle for your pi, then you do not need the wlan1 section in the /etc/network/interfaces file.
4) I am using DHCP. If you are using a static address you will have to modify these files.
5) I am using WPA2. If you are using different authentication (WPA, WEP, etc) you will have to modify these files.
6) You need to enter your SSID (and PSK if using one of the WPA protocols). Do not type in all CAPS like I did, use whatever case you used in your router.
7) Just a side note that I set several other parameters explicitly, rather than relying on multiple or default settings.
On your pi, the files in the directory /usr/share/doc/wpa_supplicant explain what all these parameters mean, and there are various example files for different configurations. In particular, the file associated with the wpa_supplicant.conf file is located at /usr/share/doc/wpa_supplicant/examples/wpa_supplicant.conf.gz.
Here are my config files:
A) /etc/network/interfaces:
Code: Select all
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-driver wext
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-driver wext
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface win7 inet dhcp
iface duane inet dhcp
iface default inet dhcp
B) /etc/wpa_supplicant/wpa_supplicant.conf:
Code: Select all
update_config=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
eapol_version=1
network={
ssid="ENTER SSID HERE"
scan_ssid=1
mode=0
proto=WPA2
auth_alg=OPEN
pairwise=CCMP
group=CCMP
key_mgmt=WPA-PSK
psk="ENTER PASSKEY HERE"
id_str="win7"
priority=1
}
network={
ssid="ENTER SSID HERE"
scan_ssid=1
mode=0
proto=WPA2
auth_alg=OPEN
pairwise=CCMP
group=CCMP
key_mgmt=WPA-PSK
psk="ENTER PASSKEY HERE"
id_str="duane"
priority=0
}
# network={
# ssid=""
# key_mgmt=NONE
#}
Last edited by pjc123 on Wed Jul 17, 2013 11:30 am, edited 2 times in total.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
After setting up my raspberry pi to wirelessly connect to the router wireless with WiFi manager tool I tried again on a new computer, with a fresh Debian installed on the raspberrypi. It is helpful to know what is going on on the LAN to troubleshoot.
One, I used my router webpage by connecting to the default IP address.
Second, I SSH'ed through the router to the pi.
Third, Simply edited the /etc/wpa_supplicant/wpa_supplicant.conf: file with what you wrote
Fourth, Rebooted and was able wireless SSH by the IP adress the my routers DHCP server gave.
One, I used my router webpage by connecting to the default IP address.
Second, I SSH'ed through the router to the pi.
Third, Simply edited the /etc/wpa_supplicant/wpa_supplicant.conf: file with what you wrote
Fourth, Rebooted and was able wireless SSH by the IP adress the my routers DHCP server gave.
Re: Auto-connect to wireless nets?
If your confused on the purpose of the properties and values.. here is a usefull cheat sheet http://www.nowiressecurity.com/articles ... _linux.htm
-
- Posts: 6
- Joined: Mon Dec 10, 2012 10:27 pm
Re: Auto-connect to wireless nets?
SirLagz wrote:Crazy idea off the top of my head
Have a script that is run every minute that will -
Check to see if wlan0 is connected with thecommandCode: Select all
iwconfig
if it is then do nothing
if it is not connected
do a wifi scan withtoCode: Select all
iwlist wlan0 scan
get the name of an open network
and thento connectCode: Select all
iwconfig wlan0 essid NETWORK_ID dhclient wlan0
Hey man, can you share that script with me?
I am new to bash scripting and want a script that runs:
ifup wlan0
if my pi disconnects, which it does very often
how could i check if my pi is connected?
Re: Auto-connect to wireless nets?
There is a thread here on that topic:
http://www.raspberrypi.org/phpBB3/viewt ... 26&t=16054
See the script by Dweeber at the very end. Although I have not tried it yet, if it works I plan on adding it once I finish building my hardware. My pi is headless and will be moving in and out of the range of a wifi signal occasionally, so I also need a way to reconnect without reinserting the dongle.
http://www.raspberrypi.org/phpBB3/viewt ... 26&t=16054
See the script by Dweeber at the very end. Although I have not tried it yet, if it works I plan on adding it once I finish building my hardware. My pi is headless and will be moving in and out of the range of a wifi signal occasionally, so I also need a way to reconnect without reinserting the dongle.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
got an answer. add these lines. /etc/network interfaces
/etc/wpa_supplicant/wpa_supplicant.conf
Code: Select all
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
Code: Select all
network{
key_mgmt=NONE
}
Re: Auto-connect to wireless nets?
Hello pjc123,
Could you please tell me how did you install 2 wireless card to Raspberry Pi? As soon as I add 2 cards, it hang up.
Could you please tell me how did you install 2 wireless card to Raspberry Pi? As soon as I add 2 cards, it hang up.
Re: Auto-connect to wireless nets?
Unfortunately I never tried two wifi dongles at the same time, only one at a time using the settings above, which works fine. The first thing that comes to mind if you are trying to do that and either the OS or the wifi startup is hanging up, is that you might be exceeding the power requirements of the pi, unless of course you are using a powered hub. I know I would not even attempt to connect two of my high gain dongles at the same time, as they would never start up properly; this is even more the case on a stock Model B Rev 1 board, as it will not even run one of my wifi dongles without removing the USB fuses.sbhunia wrote:Hello pjc123,
Could you please tell me how did you install 2 wireless card to Raspberry Pi? As soon as I add 2 cards, it hang up.
EDIT: OK, just tried two dongles with the above setting with a powered hub, I can confirm that it will only let me run one dongle at a time. As soon as I enable the second dongle and it gets an ip address, the first one loses its ip address, and vice-versa; I never needed to run two dongles at the same time, so I never tried it before. I don't know offhand how to change it to work for your case.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
I've run 2 dongles at once, 2 RT5370s and they both connected and got IP addresses.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044
Re: Auto-connect to wireless nets?
Some useful information on how you did it would be nice (network files setup), and were you able to get it working with roaming?SirLagz wrote:I've run 2 dongles at once, 2 RT5370s and they both connected and got IP addresses.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
Re: Auto-connect to wireless nets?
I had it setup in /etc/network/interfaces, one with a static IP address and one with a dynamic IP Address, both interfaces were configured to use ssid/psk from /etc/network/interfaces
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044
Re: Auto-connect to wireless nets?
Unfortunately, no good for my application.SirLagz wrote:I had it setup in /etc/network/interfaces, one with a static IP address and one with a dynamic IP Address, both interfaces were configured to use ssid/psk from /etc/network/interfaces
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/
https://www.flaminghellmet.com/launch/
-
- Posts: 4
- Joined: Thu Nov 28, 2013 7:54 am
Re: Auto-connect to wireless nets?
my question is : i want operate WiFi dongle with raspberry pi so i need to write python script for automatically scan WiFi networks and need to be connected automatically .
with known ssid and known password .
that means i need to provide password for WiFi network in script only
remain thing is need to scan and connect automatically .
so please help me to write python script. for this .
with known ssid and known password .
that means i need to provide password for WiFi network in script only
remain thing is need to scan and connect automatically .
so please help me to write python script. for this .