pawcio
Posts: 1
Joined: Sun Dec 23, 2012 7:56 am

wifi - switch between hotspot and infrastructure

Mon Mar 25, 2013 11:58 am

Hello,

My first post here, although I have been reading for a while.

I wonder if someone could point me in the right direction. I want to use RPi in the car, and I want to set up a wifi dongle in such way, that when the car is parked on a driveway it connects to my home network (so that RPi can for example sync files library with my home computer, or to allow me to log in and download some data from RPi) but when I drive away, the wifi should switch to the access point mode (to act as a hotspot for wifi enabled devices in my car).

What would be the best way to switch wifi mode between AP and infrastructure? I am not asking about detecting it's location (at home or away) as I will try to figure it out myself later on, just trying to switch modes back and forth - because I don't think one dongle could be set up to work in two modes at the same time?

Thanks,
Pawel.

petrace
Posts: 12
Joined: Thu Dec 13, 2012 10:29 pm

Re: wifi - switch between hotspot and infrastructure

Mon Mar 25, 2013 8:15 pm

Unless your car has an Ethernet cable to bridge etc., I don't believe that your raspi can act as an access point.

You might be looking to use an ad-hoc network, which would link your wifi-enabled devices together but not to the Internet.

To do this, you can use

Code: Select all

sudo ifconfig wlan0 down; sudo iwconfig wlan0 mode ad-hoc essid yourEssid
sudo ifconfig wlan0 169.169.169.1 netmask 255.255.255.0
sudo ifconfig wlan0 up
Replacing yourEssid with what you want. You can use a different IP and netmask also, just make sure to string the first two commands with a semicolon.

iwconfig can also be used to change it back, replacing ad-hoc with managed and deleting the essid part.

Hope this helps

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: wifi - switch between hotspot and infrastructure

Mon Mar 25, 2013 9:54 pm

I got it working with two dongles, one as AP, the other as client: http://www.raspberrypi.org/phpBB3/viewt ... 75#p286220

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: wifi - switch between hotspot and infrastructure

Tue Mar 26, 2013 8:48 am

Make sure you have a RT5370 Wifi dongle for painless ( hopefully ) hostapd functionality.

To do the automatic switching, I have written up a script that will do exactly that.
If you setup the Pi to automatically connect to your WiFi network, then this script should do the job.

Can be found on the adafruit site @ http://www.adafruit.com/blog/2013/01/25 ... pberry_pi/

Set the script to run every minute and it will check every minute, and if it thinks that your wifi connection is down, it will automatically bring up hostapd to act as a hotspot.
My blog is down due to me hitting my bandwidth limit lol...
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

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: wifi - switch between hotspot and infrastructure

Tue Mar 26, 2013 8:56 am

Hey thanks SirLagz, that looks really good! But I don't think it changes back to client mode when you come back home and the network is available again? For the dongle I have can't see networks when in AP mode.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: wifi - switch between hotspot and infrastructure

Tue Mar 26, 2013 9:07 am

Unfortunately that is one downside to the script, in that I don't think it can do a scan while in AP mode.
Version 2 of the script will have that capability. Which I'm still working on, hopefully be able to bring it out soon...once my blog is back online :D

[Edit]
Just thought of what I could do for the script, though this will only work if there is always a certain device that is connected to the Pi while it's acting as an AP
ping the certain device every minute, and if it doesn't get a reply then turn the ap off, scan for networks and attempt to connect.
If it doesn't connect, then it will bring the access point back.

Opinion ? ideas ?

[Edit2]
Or do a timeout where if there's no devices connected to the AP, then it will automatically try and connect to a wifi network ?
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

Return to “Beginners”