Raspberry Pi Tutorial – Connect to WiFi or Create An Encrypted DHCP Enabled Ad-hoc Network as Fallback
In this post I describe how I have configured my Raspberry Pi (RPi) to first attempt to connect to WiFi and if that fails, create and use an ad-hoc network as fallback (in this way I can always reach the RPi via SSH). The blog post is based on the following “How To” from the Raspberry Pi forum: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=19517&p=190855 – however, I have introduced a level of more detail and a couple of modifications in order to get faster boot time and support for multiple wireless networks (see my previous RPi blogt post suvery for details on which parts of that “How To” I think are good as well as which I think can be improved).
Hardware
- The WiFi adapter I have used for this tutorial is the Edimax EW-7811Un (more details here) which seems to be one of the more popular WiFi adapters for the RPi (at least based on the amount of forum posts where it appears).
Software
This tutorial has been tested with success on:
- 2012-09-18-wheezy-raspbian
- 2012-10-28-wheezy-raspbian
What We Are Going To Do
To reach our goal, I will walk through the following 7 steps:
- Getting Wireless Interface Name and Hardware Address
- Connect to WiFi
- Install and Configure DHCP Server
- Update
interfacesConfig File - RPi Network Conf Bootstrapper
- Prevent DHCP From Starting At Boot
- Reboot and Test
So basically, the main idea is that we use wpa_supplicant for maintaining a connection to WiFi, and we use an ad-hoc network as fallback if we cannot connect to WiFi on boot. Further, to make it easier to connect and communicate with the RPi via the ad-hoc network, we setup a DHCP server for that network as well.
ifconfig
… or:
iwconfig
The name of my wireless interface is: wlan0
… and the pattern of its hardware address is: 00:aa:11:bb:22:cc
Step 2 – Connect to WiFi
First of all, use wpa_cli or the “WiFi Config” GUI in lxde to setup any WiFi connections on the RPi.
The GUI is self-explanatory, but the command line approach can be a bit tricky if you don’t know where to start. Based on:
- http://sirlagz.net/2012/08/27/how-to-use-wpa_cli-to-connect-to-a-wireless-network/
- http://superuser.com/a/341440/127795
… the steps are:
Open the command line interface (cli) for wpa_supplicant:
wpa_cli
Make it scan for networks:
> scan
List the results:
> scan_results
From the list of networks, you should be able to see the SSID of the network you are going to connect to. If that is the case, we are now going to add that network to wpa_supplicant. Make sure to note the number returned by the add_network command as that identifies the new network (if you forget, you can use list_networks to view the list of networks known to wpa_supplicant):
> add_network 0
Then we need to tell about the SSID and the WPA/WPA2 key of the network:
> set_network 0 ssid "mySSID" > set_network 0 psk "myKey"
I have seen some guides saying that at this point, wpa_supplicant should automatically start connecting to the specified network, however, that is not what I have experienced. So, if wpa_supplicant does not automatically start to connect after pressing the commands above, use the following command to “force” it to connect:
> enable_network 0
Then, in order to persist the settings, we type:
> save_config
And finally, we quit the wpa_cli:
> quit
At this point, you should be connected to the desired WiFi.
If not, you might need to request an IP-address from the DHCP server on the WiFi network using:
sudo dhclient -1 wlan0
Step 3 – Install and Configure DHCP Server
Next, we are going to install the isc-dhcp-server DHCP server using apt:
sudo apt-get update sudo apt-get install isc-dhcp-server
/var/log/syslog btw.sudo nano /etc/default/isc-dhcp-server
INTERFACES setting, like:# On what interfaces should the DHCP server (dhcpd) serve DHCP requests? # Separate multiple interfaces with spaces, e.g. "eth0 eth1". INTERFACES="wlan0"
wlan0sudo nano /etc/dhcp/dhcpd.conf
DHCPDARGS=wlan0; #args for the dhcpd daemon -> limit DHCP to the wlan0 interface
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.0.255;
option domain-name "RPi-network";
option routers 10.0.0.1; #default gateway
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.2 10.0.0.20; #IP range to offer
}
#static IP-assignment
host myLaptop {
hardware ethernet 11:aa:22:bb:33:cc;
fixed-address 10.0.0.100;
}
interfaces Config FileIn this step we are going to configure the network interface configuration information:
sudo nano /etc/network/interfaces
My interfaces file looks like this (see the added comments for details):
# start interfaces upon start of the system auto lo wlan0 # register loopback interface iface lo inet loopback # use dhcp and allow interface to be started when kernel detects a hotplug event allow-hotplug eth0 iface eth0 inet dhcp # use manual ip configuration for wlan0 interface and allow hotplug as well allow-hotplug wlan0 iface wlan0 inet manual
Step 5 – RPi Network Conf Bootstrapper
In this step we are going to do a bit of bash scripting in order to the tell RPi to create an ad-hoc network if it cannot connect and obtain an IP-address from one of our already known WiFi networks.
We want this code to be executed when the RPi has booted and “is ready for use”, so we use rc.local as the container of our script:
sudo nano /etc/rc.local
The script I provide below requires that you use bash as the interpreter for the rc.local file – to do this, you need to change the very first line (the shebang) to:
#!/bin/bash
The script I provide here (RPi Network Conf Bootstrapper) should be put at the end of the rc.local file – the script goes as follows:
# RPi Network Conf Bootstrapper
createAdHocNetwork(){
echo "Creating ad-hoc network"
ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc
iwconfig wlan0 key aaaaa11111 #WEP key
iwconfig wlan0 essid RPi #SSID
ifconfig wlan0 10.0.0.200 netmask 255.255.255.0 up
/usr/sbin/dhcpd wlan0
echo "Ad-hoc network created"
}
echo "================================="
echo "RPi Network Conf Bootstrapper 0.1"
echo "================================="
echo "Scanning for known WiFi networks"
ssids=( 'MyWlan' 'MyOtherWlan' )
connected=false
for ssid in "${ssids[@]}"
do
if iwlist wlan0 scan | grep $ssid > /dev/null
then
echo "First WiFi in range has SSID:" $ssid
echo "Starting supplicant for WPA/WPA2"
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1
echo "Obtaining IP from DHCP"
if dhclient -1 wlan0
then
echo "Connected to WiFi"
connected=true
break
else
echo "DHCP server did not respond with an IP lease (DHCPOFFER)"
wpa_cli terminate
break
fi
else
echo "Not in range, WiFi with SSID:" $ssid
fi
done
if ! $connected; then
createAdHocNetwork
fi
exit 0
Step 6 – Prevent DHCP From Starting At Boot
As we only want it to start if an ad-hoc network has been created, we need to tell the DHCP server not to start on boot:
sudo update-rc.d -f isc-dhcp-server remove
Step 7 – Reboot and Test
Now, everything should be setup and ready to work – so reboot the RPi and pay attention while it boots to make sure everything looks right.
sudo reboot
Finally, try to connect to the same network as the RPi and see if it responds to ping requests. Also, try to connect to its ad-hoc network and verify that the DHCP server is leasing you an IP.
Dones
If everything looked okay, and your RPi is either connected to your WiFi or emits and ad-hoc network, everything should be working as expected
Otherwise, if you are experiencing problems, walk through the tutorial again and make sure that all your config files matches what is written in the tutorial – if that do not solve your problem, feel free to send me an e-mail or ask further question at the Raspberry Pi forum.

I’m getting a syntax error on ssids=( ‘MyWlan’ ‘MyOtherWlan’ ) Any clue what that could be about?
Have you remembered to change the script interpreter to bash? (That is, changing the very first line of the rc.local script to: “# /bin/bash”)
Just double checked, and I had a 2nd SD card laying around so I ran through the instructions again on a vanilla Wheezy image. Set for bash and still the same error on boot.
Right after the echo for Scanning for known Wifi networks.
/etc/rc.local: 32: /etc/rc.local: Syntax error: “C” unexpected
Correction: /etc/rc.local: 32: /etc/rc.local: Syntax error: “(” unexpected
Oh, my bad – I’ve just realized that I have included the wrong syntax of how to specify the interpreter. Instead of “# /bin/bash” try this: “#!/bin/bash” – I was missing the exclamation mark (this has been updated in the blog post as well). Try it, and let me know if that made any difference
I missed that twice >.< Works perfectly now.
Great! Thanks for stopping by and letting me know
I am getting an error on boot up and down saying that there is something wrong with /etc/network/interfaces.
I deleted everything in that file and pasted in your code. Is that what I was supposed to do?
Here is the error I get. Any help is appreciated.
[....] Configuring network interfaces…/etc/network/interfaces:3: misplaced option ifup: couldn’t read interfaces file “/etc/network/interfaces”
failed.
Hi Lucas, thanks for your comment.
I will double check the correctness of my interfaces file when I get my RPi booted later today.
However, I briefly searched for this issue, and it appears to me that the typical main root cause of this, is a syntax error in the interfaces file. So, first of all, are you absolutely, 100% sure, that the file you are using are identical to the one I show in this post?
If so, you could try again with an empty interfaces file and instead of copy pasting, try writing the exact content in the file – I have sometimes seen that doing a copy paste from one platform to the other induces some unwanted side-effects.
Hi Lucas, I have now compared the provided interfaces file in this blog post with the one currently running on my RPi – and they are identical. I also replaced my interfaces file on the RPi with a copy paste of the one from my blog post, and the interfaces settings loads without any issue on boot. So ye, currently, my only suggestion is that you start verifying that the interfaces file in this post is 100% equal to the one you use on your RPi
Let me know how it turns out
Thanks.
I am so happy that this works.
First thing i did with my pi was make it an airplay receiver.
Second thing was this!
I now have a standalone device that i can plug into my Aux in my car or work and play music!!
Thanks for the tutorial! Needed this for a project where the pi is in my car and needs to pull the latest code on boot if possible. Thanks a million
First of all thank you for these detailed instructions. I am having an issue where ad-hoc wifi network is no longer available when the device connected to the ad-hoc network disconnects. This seems like perhaps there is another setting I need to make to tell the ad-hoc network to persist when a device disconnects?
When this happens, I have to reboot the Raspberry Pi which allows me to re-establish the ad-hoc connection. Note if I have the Raspberry Pi connected to an access point, the connection to the Raspberry Pi can always be re-established.
So it is as if the networking stack has crashed when in ad-hoc mode and a device disconnects.
Any advice here to help resolve this would be greatly appreciated.
Thanks for a great tutorial. Very useful. It’s worked fine for me up until the part when i try to connect other devices to my ad-hoc network. They just time out when try to lease an ip address. If I allow my android phone (for instance) to use it’s own ip settings, it finds an address (albeit outside the range supposed to be leased by the dchp), but i can’t connect to the default gateway.
Any suggestions!? Many thanks!
Hi Matt and Michael, thanks for your comments – I will take a look at both during the weekend
Thanks for the effort put into making this tutorial. I’ve done a little bit more and added a router script with iptables rules in case it makes a hotspot.
Hi Adrian, that sounds great! Just out of interest, could you please share a link to a blog post describing your script (if a such exist)?
Hi Matt and Michael, I have unfortunately been fully occupied the entire weekend, but if I get some more spare time in the next week, both of your “issues” are on my list and I will look into it.
I followed the tutorial but and I was observing erratic behavior when the rc.local script creates the ad-hoc network and executes the ‘iwconfig wlan0 mode ad-hoc’ command. I was getting:
Error for wireless request “Set Mode” (8B06):
SET failed on device wlan0 ; Device or resource busy.
The strange thing was that this would occur only once every 2 or 3 times upon full (power-unplugged) reboot. I was using a Tenda Wi-Fi dongle plugged into a powered usb hub, but found that using a BT-Micro3H2X (combination Bluetooth WiFi) dongle plugged directly into the RPi, the problem has not reappeared.
Excellent tutorial; many thanks!
@Michael – I just tried connecting to my RPi, then disconnect and re-connect again – thus, I cannot reproduce the exact same problem. Which type of WiFi device are you using?
@Matt – have you tried connecting using a PC? As far as I know, Android devices are still not able to connect to Ad Hoc networks out of the box.
Hi Lasse, thanks for your reply. Yes, I have tried it from a PC also, but I get a similar problem. The PC says that it is connected, but it is not leased an IP address, and does not receive any packets from the RPi. I’ve followed your tutorial exactly….very odd!
Hi Matt, thanks for your reply
I have a couple of questions that might help narrow the issue down – have you checked that the DHCP server is actually running? Is the DHCP server complaining about an invalid config file when started? Which WiFi device are you using? Have you tried starting the “RPi Network Conf Bootstrapper” from the terminal and checked that everything went well (that no errors were returned?)
Hi Lasse, first i want to say is THANK YOU
. I have RPi (rasbian wheezy, but 256MB version) and same wifi usb adaptor Edimax EW-7811Un. I would like create adhoc “server” on windows 7 ( in this post – http://raspberrypi.org/phpBB3/viewtopic.php?f=63&t=34895 ) but i was unsuccessful. So i found your really great tutorial and do this way ( “server” on raspberry ) and this works. But when i start (boot) RPi, it stay while on “Obtaining IP from DHCP” then write on screen ” DHCP server did not respond with an IP lease (DHCPOFFER) ” and then “Failed to connect to wpa_supplicant – wpa_ctrl_open: No such file or directory ” and finaly Creating ad-hoc network. This problem is now OK for me, because i need only Ad-Hoc network ( for internet (for update) i use cable). Is there any way to choose what i want. I think in script will be something like this – echo “Choose: For wifi write “w” and for AdHoc write “a” ” then user write W or A for option that he want. But that is just detail. More main thing i would like to change is transfer speed, edimax can work in 802.11 N mode, but when i wrote ” iwconfig wlan0 ” it show me only 54mb/s (so it is 802.11 G mode?). Is there any way to change transfer speed, because i stream video from USB camera with MJPG-STREAMER (by BobTech) and there is 3 seconds delay between reality and video, so i think that higher transfer speed is better.
THANK YOU AGAIN for this tutorial
Hans
Hi Hans, thanks for your response – I’m glad the post have helped several RPi users out there
Regarding your questions – I think a simple way of solving the “Failed to connect to wpa_supplicant – wpa_ctrl_open: No such file or directory” error is to simply call “createAdHocNetwork” directly in the bootstrapper and skip the bootstrapper’s attempt to connect to an existing wireless network (which I understand is okay, since your are using cable for Internet access). In regards to the transfer rate of the network connection, I have seen a couple of blog posts mentioning that WEP is not supported on the N standard, meaning that if WEP is enabled, the device will automatically fall back to the g standard. So, you could try editing the script such that it do not set a WEP key, then connect and see what speeds are reported? Further, I have seen that it should be possible to “force” the device to use a certain standard by using the “rate” option for iwconfig – so that would also be an option to look further into
Thank you for fast response. I change rc.local, so i “commented” (write ” # ” behind every text from echo bootstraper to end and i ” call ” function createAdHocNetwork, where i comment line about password. Re-boot and network is created but “iwconfig wlan0 ” show me same Bit Rate: 54 Mb/s and show in first line IEEE 802.11 bg. I look at this in Thursday, but if you have some information about this ” switch to N mode ” i will be glad.
Wifi connection was good, before i re-write interfaces and wpa_supplicat. In interfaces for wlan0 interfaces was before line “wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf ” but this is maybe for this tutorial.
As i wrote this is not realy important. More important is N mode.
In previous question (about WiFi connection or Ad-Hoc) i thought it is possible in script something like this. Before creating any connection, that script “Ask User What He Want” – like “echo “Are you want create AdHoc (A) or Wifi (W) network”" .. Script after this wait for what user type – A or W – and next scrit do function createAdHocNetwork if user type A or connect to existing wifi network if user write W. But this is only detail, which i would like to solve in future. I ask you if script (in rc.local) can “Read what user write with keyboard to command line”.
Realy thank you for your time and answers.
Hi Hans, I have been away for a couple of days, so maybe you could give me an update on how you progress – are things starting to work?
Regarding the N mode – I do not have that much time for trying to solve it since I’m doing my Master thesis these days, but hopefully, some day, I will have more time and be able to look into it
Hi after a long time. I was away for few days too. I was and still i am ill, so i am not progressed as i would like. As i wrote i have working WiFi network, after boot RPi start “AP” i can connect via SSH and start script for streaming video from USB webcam.
I write to Edimax tech support, but their answer did not help me.
Their answer:
” Dear Sir, You will need to check in EW-7811Un driver properties if there’s possibility to change its band.
Best Regards,”
But i have RPi very short time, so i dont know where i find driver for editing. Did you know where is placed?
I read that Ad-Hoc network is not standardized (IEEE standard) in N mode. If NIC can create this network, it is guaranteed only B/G mode.
N mode is only additional option that manufacturer can (not must) add to device settings.
Although there is 3s lag, WiFi connection and video streaming works. So I will probably solve another problem, which is sending text information over wifi. If you have some experiencies with text stream i will glad for some information about this
Thank you so much for these instructions! I was trying to figure out a way to set up an ad-hoc connection with static ip’s and it just was not working. I was worried about opening the whole dhcp can of worms since I’m still learning linux. Your method is great because it only enables dhcp if it’s unable to connect to a wireless network, brilliant!
I’m making a little wifi boombox and I was stumped on how to make the setup process easier, if possible I wanted to have it configurable via smartphone instead of using buttons and the lcd. This gets me one step further!
I still need to work out a way to make the wpa_supplicant part easier for people, I was thinking I could maybe write a little program that a user can run after ssh’ing into it that just asks “Enter SSID, Enter Encryption type 0=Open 1=WEP 2=WPA, then if applicable Enter Passkey”. If you’re interested in helping me with that feel free to email me. Once my project is done I’d like to post an all in one tutorial from getting MPD setup to stuff like this.
Thanks again!
After initial success I hit a few snags when trying to customize this a little. I didn’t realize at first that you need to specify your existing wifi networks in the rc.local file.
I wonder if there is a different way to approach this so that ssid’s don’t have to be hard coded in? Issue some query to determine if the Pi is connected to an SSID, if not sleep 5 check again, do x number of times then if still not connected start ad-hoc mode? I realize this is out of the scope of your instructions, I’m just trying to figure out a way to limit users having to edit files as much as possible avoid hardcoding if possible.
Lastly, in your script you have a bunch of feedback being echoed to show the status of the script, however I see none of it. I’m connected via serial so I see all of the boot process. The output of the boot seems to hang for awhile after “bcm2835 ALSA chip created!” which is where your script is running I assume, then I get the login prompt, no echoes from the script. Does something need to point at 2>&1 maybe? I assume you put the debug info in for a reason, just curious how you were viewing it?
Again I’m very greatful for this tutorial, I’m just trying to adapt it a little to my needs and maybe in the process it can help improve yours as well.
Thanks
Just FYI, here is my modified version without the hardcoded ssid’s
#!/bin/bash
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0″ on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf “My IP address is %s\n” “$_IP”
fi
# RPi Network Conf Bootstrapper
createAdHocNetwork(){
echo “Creating ad-hoc network”
ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc
iwconfig wlan0 key aaaaa11111 #WEP key you can change this but keep it 10 digits
iwconfig wlan0 essid Boombox_Ad-Hoc #SSID set this to whatever you want
ifconfig wlan0 10.0.0.200 netmask 255.255.255.0 up
/usr/sbin/dhcpd wlan0
echo “Ad-hoc network created”
echo “The server ip is 10.0.0.200″
}
echo “=======================================================”
echo “RPi Network Conf Bootstrapper 0.2 – JPH Photography mod”
echo “=======================================================”
echo “Scanning for known WiFi networks”
connected=false
for i in 1 # Initially was for i in 1 2 3 but found it took too long to failover to adhoc
do
if connected=false
then
echo “Starting supplicant for WPA/WPA2″
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1
echo “Obtaining IP from DHCP”
if dhclient -1 wlan0
then
echo “Connected to WiFi”
connected=true
iwconfig 2> /dev/null | grep ESSID > /etc/wpa_supplicant/my_current_ssid.txt
cat /etc/wpa_supplicant/my_current_ssid.txt
echo “My IP address is:”
hostname -I
break
else
echo “DHCP server did not respond with an IP lease (DHCPOFFER)”
wpa_cli terminate
break
fi
else
echo “No ssid’s listed in your wpa_supplicant.conf file were in range”
fi
done
if ! $connected; then
createAdHocNetwork
fi
exit 0
Thanks fot amazing tutorial! I’m stuck on DHCP server – connecting to adhoc wifi is OK, but never got IP address
Iˇve followed your guide on my xbian and then on vanilla Raspbian “wheezy” installation with the same result: Devices can connect to ad-hoc RPi network, but any never receives IP address. Devices are able to see each other, but not Raspberry PI.
Hi Lasse,
thanks for the great tutorial!!
For me everything works except the DHCP server. I can connect to the ad-hoc WiFi, but do not get an IP address.
(I did not use your bootstrapped, but did the same steps manually.)
I hope you can help…!
Hi Nakej and Elmar,
Thanks for your comments – I’m glad you found the tutorial useful.
In regards to your issues with the DHCP server not leasing an IP adress I have some follow up questions:
- Do you get any error messages?
- Have you tried running the logic in the “createAdHocNetwork()” function in a shell and checked that it succeeds without any error messages?
- Have you tried using static IP assignments on any of the connecting devices (in “/etc/dhcp/dhcpd.conf”)?
Hi Aikku,
Thanks for your comments – I’m glad you could use the blog post to get started
I’m currently in the process of writing my master thesis, so I don’t have that much time for other activities – but when I have finished my thesis I am planning to get back on this, and, based on the provided comments, write an update to the post above.
I’m glad you solved it out and everything is working.
Hi,
At the end of the day from trial and error, I found that I am still having problems despite my earlier posts. In order to prevent giving misleading info to others (by me), could you please REMOVE my last two posts above?
Sorry for the inconvenience – and good luck with your thesis.
-wbw
A.
Hi Aikku,
Thanks for you comment – I’m glad you informed me about that
I have now removed both of your comments.
As I mentioned in an earlier comment, I am planning to revisit this topic at some point in time after I have finished my thesis. So hopefully, we will manage to get your setup working properly
I am using my raspi as an access point with AirPlay in my car. How do I stop my iPhone from thinking the ap has Internet? I.e. iPhone connected to ap but still access 3/4G?
Thanks for the tutorial! Very smooth process.
I’m just having a few issues with the bootstrapper. On boot and load it gives me a syntax error:
syntax error near unexpected token ‘done’
‘done’
[FAIL] startpar: service(s) returned failure: rc.local … failed!
And I also noticed this:
Configuring network interfaces…ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ifup: interface eth0 already configured
done.
I’ll go back and check again to see if I missed anything.
Thanks again.
After going back and checking the code, I found out that copying and pasting the bootstrapper wasn’t a very good idea. If anyone has any issues with syntax errors after following this tutorial you either copy/pasted the code or you wrote it wrong. In the end, I also was able to solve my othe issues with the network interface conf file. I went back and deleted everything and wrote it again from scratch exactly how you had it written in the tutorial. I guess, I’m just stubborn and wanted to start picking at the code and only adding the things I want (or at least thought I needed)
Thank you very much for the tutorial! I finally got the adhoc network to be created and broadcast. I just need to test the connection to make sure it’s working properly.
Hmm, my raspberry pi isn’t working and it doesn’t look like rc.local is running at boot. I don’t see any of rc.local’s echo statements in the terminal, syslog, or user.log. Is there somewhere else I should be looking? And the raspberry pi is not connecting to my home network or creating an ad-hoc network.
Any advice?
Hi Lasse,
Thanks for the great tutorial, got the Pi finally working in WPA-mode. Now I have a challenge: On our campinggrouns internet-access is provided by means of a username and password you have to fill-in in your browser, a sort of public AP. No encryption is used (shame) but I was wondering if it could be possible to add the login to a file somewhere so the Pi connects automatically.
Please share you’re thougts with me…
Regards, Bert
Hi Bert, hmm, maybe you could try creating a simple bash script which uses wget to post the login credentials?
First, you need to figure out the pattern/syntax of the url that is requested from the server when you press login through your browser. There are different ways to do that, e.g., using Chrome’s developer console (ctrl + shift +j, then select “Network”) or using a tool like Fiddler. I think the easier way will be using Chrome’s developer console
Anyway, lets assume you use Chrome for this – then while at the login page, go to the “Network” tab in the developer console, then fill in the login form and submit it as you normally do – then, after you have pressed submit you should be able to see that Chrome has logged the network traffic / you request, and the url/path should now be visible in the developer console (along with the needed form data).
With the url in hand, I suggest you create a bash script that uses wget to post the form after you have connected to the camping grounds network. You can use advise on how to configure wget for that purpose, here: http://stackoverflow.com/a/1432161/700926
And when the script is working, you could call it from line 30 of the rc.local script I have provided in the blog post. At that line, we know we got an IP from the DHCP server, so from that point, the wget trick should be able to work.
Give it a try and let me know how it goes