As promised I'm going to write down the steps to configure an run a "wifi config server" on the raspi.
The idea is to allow the user to not ssh on the system to just config the wifi.
1) Install webserver:
I use the mongoose tcz package. It is a tiny server. So
Run the tce package manager. Search for mongoose and install it.
2) Create the pages
We need to create the server pages that mongose need to server. They need to be on the same folder structure. You can put it anywhere you want, mongoose is not strict. I just use /home/tc/www
2.1) The index.html. This is just a basic html form with the SSID, encryptyon and password fields so the user could just fill them.
The contents of my index.html (it is based on the pifi proyect)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />
<meta charset="UTF-8" />
<title>Wifi Config</title>
<style type="text/css">
/*<![CDATA[*/
a:link {color:black; text-decoration:none;} /* unvisited link */
a:visited {color:black; text-decoration:none;} /* visited link */
a:hover {color:#900000; text-decoration:underline;} /* mouse over link */
a:active {color:#900000; text-decoration:underline;} /* selected link */
@font-face
{
font-family: "asenine";
src: url('/fonts/asenine.ttf');
}
h1 {
text-shadow:2px 2px 5px rgba(10,10,10,0.6);
font-family: 'asenine', Fallback, sans-serif;
font-size:300%;
}
h2 {
text-shadow:2px 2px 5px rgba(10,10,10,0.6);
font-family: 'asenine', Fallback, sans-serif;
font-size:200%;
margin-top: 0.5em;
margin-bottom: 0.1em;
}
p {
font-size: 150%;
text-shadow:2px 2px 5px rgba(10,10,10,0.6);
font-family: 'asenine', Fallback, sans-serif;
margin-top: 0.5em;
margin-bottom: 0.1em;
}
/* html *
{
text-shadow:2px 2px 5px rgba(10,10,10,0.6);
font-family: 'asenine', Fallback, sans-serif;
font-size: 120%;
}*/
html, body { min-height: 100%; }
body
{
background-image: url('/images/bg_top.png'), url('/images/bg_bottom.png'), url('/images/pifi_mini_logo.png');
background-position: top left, bottom left, top center;
background-repeat: repeat-x, repeat-x, no-repeat;
background-size: 3%, 2%, 45%;
}
/*]]>*/
</style>
</head>
<body>
<center>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<h1><a href="index.php">Main Menu</a></h1>
<form name="user_wpa_info" method="get" action="wpa_helper.cgi" onsubmit=
"return confirm('Are you sure? This will reboot the unit!')">
<h2>SSID:</h2><input name="ui_ssid" type="text" size="22" /><br />
<h2>Encryption Type:</h2><select name="ui_encryption">
<option value="open">
Open (No Encyrption)
</option>
<option value="wep">
WEP
</option>
<option value="wpa">
WPA or WPA2
</option>
</select><br />
<h2>Password:</h2><input name="ui_pass" type="password" size="22" /><br />
<br />
<input type="submit" style=
"-mox-box-shadow: 0 1px 3px #111; -webkit-box-shadow: 0 1px 3px #111; box-shadow: 0 1px 3px #111 ;border-radius:8px; -moz-border-radius:8px; -webkit-border-radius: 8px;font-face:'asenine'; font-size:110%;"
value=" Submit and Reboot " />
</form><br />
</center>
</body>
</html>
You can of course make it more pretty or better. This just works.
2.2) CGI script.
The idea is use a sh script to retrieve the parameters from the form and just create a WIFI.db that substitutes the created by the wifi.sh script. This way the same init code for the wifi that is used on the wifi script could be used here.
Also it needs to persist the changes, and reboot the raspi.
Any programming language could be used here. However I wanted to maintain an small footprint, so I didn't want to install python / perl whatever for just this.
My wpa_helper.cgi:
#!/bin/sh
#first we retrieve the parameters from the query_string
IFS='&'
set -- $QUERY_STRING
ui_ssid=${1#*=}
ui_encr=${2#*=}
ui_pass=${3#*=}
#save the parameters to the wifi.db
echo ${ui_ssid}$'\t'${ui_pass}$'\t'${ui_encr}> /home/tc/wifi.db
# The HTML output starts here
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Storing WIFI Data connection. Please wait</title>"
echo "</head><body><h1>Storing WIFI Data Connection... Please wait</h1><pre>"
#Persist the info
filetool.sh -b
#reboot the raspi
reboot
Edited 11-17-2013As point out by mcdudeabides. It is need to give execution permits to the cgi script:
sudo chmod 755 /home/tc/www/wpa_helper.cgi
Thats all. Easy enough
3) Run the server at boottime.
We need to run mongoose, so add the following to the /opt/bootlocal.sh
mongoose -document_root /home/tc/www &
4) Persist all before rebooting:
Ensure that you have the home folder on your filelist, and just
filetool.sh -b
That's all folks the next time you reboot your raspi and point your webbrowser to the port 8080 on the raspi the wifi config will appear.
Some notes:
If you combine this approach with the data of the post:
http://forum.tinycorelinux.net/index.php/topic,16181.msg95878.html#msg95878You can create a boot process like this:
The raspi tries to connect to the wifi network that is defined on the wifi.db.
If it connects then
resume normal boot
if not (maybe the wifi.db doesn't exist or the network is unreachable)
the raspi creates an AP with DHCP
The wifi config server (the one of this post) is started
Then after that, the user could just connect to the wifi that the raspi is generating, go to the wifi server page, config the wifi data, and reboot, next time the raspi will be connected to the wifi.
This mechanism allows to use the raspi without ethernet connection as a wifi-connected device. The user only needs a wifi capable device (as an smartphone) to config the device without the need of ssh to it.
Some drawbacks or improvements that could be done:
- At this moment the SSID introduced by the user is not checked. A mechanism to retrieve all reachable wifi's and fill a combobox of ssid could be great.
To do it, the index.html must be trasnformed on an index.cgi and us sh to call iwilist and parse the info.
- The password of the wifi is stored as plain text on the wifi.db, however this is the same way as the wifi.sh script does, I'm not very comfy with that, but I don't have the time / knowledge to use another mechanism.
- The password is passed on the url when the user clicks on the form button. Again I don't think this would be a major concern as this is use just one moment after the reboot. Also if it is configured using the PA mechanism the network on which the server is running is almost "one-time" use and created ad-hoc for the configuration.
I hope this could help anyone. If anyone have any doubts I will try to explain.
Gabriel