# Howto re-try wireless [almost solved]

## chris...

How do i setup the wireless network so that that it keeps retrying to connect

At the moment it tries to connect once then stops

I'd like it to alternate between managed and ad-hoc

```
modules=("iwconfig")

essid_wlan0="chris"

adhoc_essid_wlan0="stuff"

config_chris=("192.168.1.113/24")

routes_chris=("default via 192.168.1.254")

dns_servers_chris=( "192.168.1.254" )

config_stuff=("192.168.1.10/24")

```

```

Network controller: Intel Corporation PRO/Wireless 4965 AG or AGN [Kedron] Network Connection

```

Last edited by chris... on Sun Nov 22, 2009 4:50 am; edited 1 time in total

----------

## erik258

wpa-supplicant can manage AP  connections like this pretty well (perhaps 5-20 seconds of time to reconnect to new AP) and apparently supports adhoc mode too.  It allows configuring priorities to specify preferred wireless networks.  I think it would work well for you.  It doesn't necessarily require wpa, by the way, but supports unsecured, and probably poorly secured (WEP) networks too.

----------

## chris...

wpa-supplicant will continuously try connecting between ad-hoc and managed?

----------

## d2_racing

I'm not an expert on that, but WICD can do a lot of stuff, so instead of using the manual way, maybe you should try WICD to test if it's working with that little program.

----------

## erik258

I'm pretty sure wicd uses wpa_supplicant.  

 *Quote:*   

>  instead of using the manual way

 

it's fully automated, just doesn't provide more than a crappy interface to wpa_supplicant.conf (wpa_cli exists but is a pain to use).  but wpa_supplicant.conf is easy enough to create.  here's an example with a low-priority block for connection to open networks and a block with WPA enabled.  

```

network={

        key_mgmt=NONE

        priority=-9999999

}

network={

        ssid="your-essid"

        scan_ssid=1

        key_mgmt=WPA-PSK

        psk="your-passkey"

        priority=10

}

```

You'll have to figure out how to add an ad-hoc network yourself.  It seems to be supported according to google, but I've never done it.  

 *Quote:*   

> wpa-supplicant will continuously try connecting between ad-hoc and managed?

 

It will continually poll the surrounding air, checking to see what wireless networks are available, and connect to a higher priority network when it is available.  it will then stay on that network until it is either unavailable or an even higher priority network is available.

----------

## chris...

ok i've got wpa_supplicant working but not with an ad-hoc network

in the doco it says to add "mode=1" to the network block, but that doesnt seem to work

i can manually get an ad-hoc network working

ok ad-hoc seems to work when i set

```
ap_scan=2
```

will have to wait till i get back home to see if it works as expected with a managed ap

----------

## chris...

OK, it mostly works apart from connecting to a managed network

It'll connect to an ad-hoc network

It'll connect as ad-hoc but doesnt realise its the only computer and wont try a managed network, but that may be becuase it wont connect to a managed network in the first place

It'll swap between trying to connect to 2 different access points but not connect to either

wpa-supplicant wont seem work with ad-hoc and managed

if i want to use managed i need to set ap_scan=1

if i want to use ad-hoc i need to set ap_scan=2

----------

## erik258

interesting.  I can see that being the case.  Did you set the managed network priority higher than the ad-hoc network?  care to post your wpa_supplicant.conf?

----------

## chris...

one is 11n 

two is 11g

I'm using iwlagn and iwl3945 wireless modules

all work manually in ad-hoc and managed mode

```
ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=wheel

ap_scan=1

country=AU

network={

  ssid="one"

  key_mgmt=NONE

  priority=2

}

network={

  ssid="two"

  key_mgmt=NONE

  priority=1

}

network={

  ssid="adhoc"

  key_mgmt=NONE

  mode=1

}
```

iwl3945 has "two" as a higher priority so it prefers the 11g router

----------

## erik258

Shouldn't the advocate net have a priority too?

----------

## chris...

no, its the default 0

however, setting it makes no difference

----------

