I want to figure out the easiest way to setup wifi networking on a headless Pi that has no user-accessible I/O apart from wifi. By "easy" I mean easy to explain to someone who hasn't used a Pi before.
The only thing I can think of so far is for the Pi to start out as a wifi hotspot itself, and serve a web page that the user would access via phone/tablet/etc. to enter the name and password for their wifi router. Maybe they could select from a list of wifi networks from a scan the Pi had previously done at bootup.
Is there a better way? With all the buzz about "Internet of Things" and embedded systems / internet appliances, I suppose this must be a common problem. I recall seeing some wifi routers with an easy setup button that must allow some kind of handshake to allow a new device on the network, but I don't think I can assume everyone has one of those.
- DougieLawson
- Posts: 40835
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: headless wifi setup: easiest approach?
If you know the access point SSID and password you can write an /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant file that will automatically connect when the network starts and the dongle is available.
So it now becomes a problem of how to get those things on the ext4 filesystem on the SDCard.
We can read and write /boot on a windows machine.
We can get a process running by setting it as init=/directory/filename in /boot/cmdline.txt
So here's a plan
1. create /boot/interfaces.txt (Unix flavour no ^M chars)
2. create /boot/supplicant.txt (also no ^M chars)
3. create /boot/WiFiSetUp (everything on /boot has -rwxr-xr-x permission bits by default)
4. create /boot/cmdline.normal.txt as a copy of current /boot/cmdline.txt
5. update /boot/cmdline.txt so that it has init=/boot/WiFiSetUP
Your /boot/WiFiSetUp program does the following
1. Mounts all filesystems
2. copies /boot/interfaces.txt to /etc/network/interfaces
3. copies /boot/supplicant.txt to /etc/wpa_supplicant/wpa_supplicant.conf
4. renames /boot/cmdline.txt to /boot/cmdline.WiFiSetup.txt
5. renames /boot/cmdline.normal.txt to /boot/cmdline.txt
6. Unmounts all filesystems
7. reboots
I think it will need to be a statically linked ELF executable because that init program starts before everything else is ready.
That should work.
So it now becomes a problem of how to get those things on the ext4 filesystem on the SDCard.
We can read and write /boot on a windows machine.
We can get a process running by setting it as init=/directory/filename in /boot/cmdline.txt
So here's a plan
1. create /boot/interfaces.txt (Unix flavour no ^M chars)
2. create /boot/supplicant.txt (also no ^M chars)
3. create /boot/WiFiSetUp (everything on /boot has -rwxr-xr-x permission bits by default)
4. create /boot/cmdline.normal.txt as a copy of current /boot/cmdline.txt
5. update /boot/cmdline.txt so that it has init=/boot/WiFiSetUP
Your /boot/WiFiSetUp program does the following
1. Mounts all filesystems
2. copies /boot/interfaces.txt to /etc/network/interfaces
3. copies /boot/supplicant.txt to /etc/wpa_supplicant/wpa_supplicant.conf
4. renames /boot/cmdline.txt to /boot/cmdline.WiFiSetup.txt
5. renames /boot/cmdline.normal.txt to /boot/cmdline.txt
6. Unmounts all filesystems
7. reboots
I think it will need to be a statically linked ELF executable because that init program starts before everything else is ready.
That should work.
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
-
- Posts: 142
- Joined: Thu Dec 12, 2013 10:39 pm
- Location: Suffolk, UK
- Contact: Website
Re: headless wifi setup: easiest approach?
I've recently created a video tutorial showing how to setup a Raspberry Pi model A (no ethernet) using a £6-7 console cable and another computer, I used a Mac, but you can also use Windows or Linux. It goes through three tasks, flashing the SD card with Raspbian, connecting through the Console cable and setting up wifi, finally connecting through wifi and SSH.jbeale wrote:I want to figure out the easiest way to setup wifi networking on a headless Pi that has no user-accessible I/O apart from wifi. By "easy" I mean easy to explain to someone who hasn't used a Pi before.
The only thing I can think of so far is for the Pi to start out as a wifi hotspot itself, and serve a web page that the user would access via phone/tablet/etc. to enter the name and password for their wifi router. Maybe they could select from a list of wifi networks from a scan the Pi had previously done at bootup.
Is there a better way? With all the buzz about "Internet of Things" and embedded systems / internet appliances, I suppose this must be a common problem. I recall seeing some wifi routers with an easy setup button that must allow some kind of handshake to allow a new device on the network, but I don't think I can assume everyone has one of those.
Take a look, hopefully you might find it useful.
http://bit.ly/headless_install
Re: headless wifi setup: easiest approach?
I'm also interested in solving this problem using the Wifi hotspot strategy instead of using a cable. I'll post any progress.
- iinnovations
- Posts: 621
- Joined: Thu Jun 06, 2013 5:17 pm
Re: headless wifi setup: easiest approach?
I totally understand this concern. I have a networked control unit, and it's pretty dumb to ask the user to plug in a mouse, keyboard, and monitor just to set wireless parameters. I ship units configured as an access point, so the user plugs it in and just logs into 'cupidwifi'. Navigating to 192.168.0.1, they can then configure it. As it is, the still must ssh in to reconfigure the SSID and WiFi password via wpa_supplicant, but it's still a good first step. They can then select station mode from the web GUI, reboot, and it will be on the SSID specified. The boot procedure is as below:
[*] Line in rc.local calls boot.sh
[*] In boot.sh (amongst other things), networkrestart.py is called
[*] Networkrestart.py:
[*][*] Reads database with table netconfig
[*][*] Sets up and starts/stops dhcp server, hostapd, copies one of several preconfigured /etc/interfaces files to /etc/interfaces
[*][*] Brings wlan down and up
At some point I'll build in SSID and password from the web GUI, but I'm not excited about plaintext password stores or going out of my way to stash it somewhere. I'm certainly open to suggestions on a good way to do this. For now, it's a one-time setup.
Ideally, it will eventually be set up with a connection timeout to the SSID specified so that it will revert to AP mode. This way if the user sets a bunk SSID and/or password, they'll see it pop up again as a wireless network. Otherwise, if it's screwed up once, get out the keyboard, mouse, and monitor ....
Colin
[*] Line in rc.local calls boot.sh
[*] In boot.sh (amongst other things), networkrestart.py is called
[*] Networkrestart.py:
[*][*] Reads database with table netconfig
[*][*] Sets up and starts/stops dhcp server, hostapd, copies one of several preconfigured /etc/interfaces files to /etc/interfaces
[*][*] Brings wlan down and up
At some point I'll build in SSID and password from the web GUI, but I'm not excited about plaintext password stores or going out of my way to stash it somewhere. I'm certainly open to suggestions on a good way to do this. For now, it's a one-time setup.
Ideally, it will eventually be set up with a connection timeout to the SSID specified so that it will revert to AP mode. This way if the user sets a bunk SSID and/or password, they'll see it pop up again as a wireless network. Otherwise, if it's screwed up once, get out the keyboard, mouse, and monitor ....
Colin
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
- iinnovations
- Posts: 621
- Joined: Thu Jun 06, 2013 5:17 pm
Re: headless wifi setup: easiest approach?
Looking back over my code here, it looks like I actually wrote functions for parsing and writing wpa_supplicant from scratch, along with determining network WAN and LAN status.
Considering that SSID and password are already stored in plain text, I suppose there is no harm in storing them in an auxiliary file or database as long as it's outside the web root.
Considering that SSID and password are already stored in plain text, I suppose there is no harm in storing them in an auxiliary file or database as long as it's outside the web root.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
Re: headless wifi setup: easiest approach?
what i made:


ive made it headless, just a webpage like a normal router you can access by domain name
my own (portable) router with extra functions
also ive stumbled a really annoying thing in bash, by passing arguments if your access point contains any spaces
your screwed
so i store logon arguments in a variable in a bash script then i call it via source


ive made it headless, just a webpage like a normal router you can access by domain name
my own (portable) router with extra functions
also ive stumbled a really annoying thing in bash, by passing arguments if your access point contains any spaces
your screwed
so i store logon arguments in a variable in a bash script then i call it via source
- iinnovations
- Posts: 621
- Joined: Thu Jun 06, 2013 5:17 pm
Re: headless wifi setup: easiest approach?
Ok, I wrapped this up.
On boot:
[*] rc.local runs boot.sh, which includes a call to netconfig.py
[*] netconfig.py:
[*][*] If enabled, reads netconfig preferences from table netconfig in systemdatabase, updates /etc/network/interfaces with address and gateway
[*][*] If enabled, update wpa_supplicant, using netconfig SSID, retrieving psk from database table in /var/wwwsafe (matches SSID from table of SSID/PSK pairs)
[*][*] If enabled, brings wlan0 down and back up again
[*][*] Updates status of network in database, including LAN/WAN access, latency, etc.
Periodically, systemstatus is run by master cron script:
[*] Reads and updates wpa client, dhcpd, latency, LAN/WAN access status in database
[*] If aprevert mode set to 'temprevert' or 'aprevert':
[*][*] If wpa status is not connected for longer than database value aprevert time, set mode to ap, bring wlan down and back up in ap mode
[*][*] If aprevert mode is 'aprevert', set netconfig to ap mode. This puts the wireless in ap mode until manually changed. Otherwise, when netconfig is run again, it will revert to station mode.
There are all sorts of parsing and utilities in here, so grab what you want...
https://github.com/iinnovations/iicontr ... tconfig.py
https://github.com/iinnovations/iicontr ... mstatus.py
Colin
On boot:
[*] rc.local runs boot.sh, which includes a call to netconfig.py
[*] netconfig.py:
[*][*] If enabled, reads netconfig preferences from table netconfig in systemdatabase, updates /etc/network/interfaces with address and gateway
[*][*] If enabled, update wpa_supplicant, using netconfig SSID, retrieving psk from database table in /var/wwwsafe (matches SSID from table of SSID/PSK pairs)
[*][*] If enabled, brings wlan0 down and back up again
[*][*] Updates status of network in database, including LAN/WAN access, latency, etc.
Periodically, systemstatus is run by master cron script:
[*] Reads and updates wpa client, dhcpd, latency, LAN/WAN access status in database
[*] If aprevert mode set to 'temprevert' or 'aprevert':
[*][*] If wpa status is not connected for longer than database value aprevert time, set mode to ap, bring wlan down and back up in ap mode
[*][*] If aprevert mode is 'aprevert', set netconfig to ap mode. This puts the wireless in ap mode until manually changed. Otherwise, when netconfig is run again, it will revert to station mode.
There are all sorts of parsing and utilities in here, so grab what you want...
https://github.com/iinnovations/iicontr ... tconfig.py
https://github.com/iinnovations/iicontr ... mstatus.py
Colin
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
- Richard-TX
- Posts: 1549
- Joined: Tue May 28, 2013 3:24 pm
- Location: North Texas
Re: headless wifi setup: easiest approach?
I have several Rpis that I run headless. All I do when starting with a new Rpi is to boot with the ethernet connected, login via ssh, drop in my interfaces file and reboot. Poof - it is up and running. No config for supplicant needed.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip
- iinnovations
- Posts: 621
- Joined: Thu Jun 06, 2013 5:17 pm
Re: headless wifi setup: easiest approach?
That definitely works, but I want users to not have to use an ethernet cable or ssh. What seems like a long workaround above is to avoid ever having to plug in any IO devices at all, including ethernet cable, and to interact solely by a web interface.Richard-TX wrote:I have several Rpis that I run headless. All I do when starting with a new Rpi is to boot with the ethernet connected, login via ssh, drop in my interfaces file and reboot. Poof - it is up and running. No config for supplicant needed.
I personally have a stock image that I boot up and log in wirelessly and change the IP. I've got half a dozen running around here that are essentially identical.
It may seem like a big commitment to wireless, but I build systems around zero wired network access, LAN or otherwise.
Colin
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
-
- Posts: 142
- Joined: Thu Dec 12, 2013 10:39 pm
- Location: Suffolk, UK
- Contact: Website
Re: headless wifi setup: easiest approach?
But what do you do if you have a model A without Ethernet port. That's why I find the console cable so handy.Richard-TX wrote:I have several Rpis that I run headless. All I do when starting with a new Rpi is to boot with the ethernet connected, login via ssh, drop in my interfaces file and reboot. Poof - it is up and running. No config for supplicant needed.
Tutorial here:
http://bit.ly/headless-install-playlist
- iinnovations
- Posts: 621
- Joined: Thu Jun 06, 2013 5:17 pm
Re: headless wifi setup: easiest approach?
Buy a model B.keithellis wrote:
But what do you do if you have a model A without Ethernet port.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
-
- Posts: 142
- Joined: Thu Dec 12, 2013 10:39 pm
- Location: Suffolk, UK
- Contact: Website
Re: headless wifi setup: easiest approach?
That is an answer, but the model A is much better when running off batteries for robot or remote projects. It is also cheaper.
- jackokring
- Posts: 818
- Joined: Tue Jul 31, 2012 8:27 am
- Location: London, UK
- Contact: ICQ
Re: headless wifi setup: easiest approach?
put the required files on the SD card using another system before booting the pi. Not exactly what you asked, but I'd assume you use another system to burn the SD images.
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028
- iinnovations
- Posts: 621
- Joined: Thu Jun 06, 2013 5:17 pm
Re: headless wifi setup: easiest approach?
I was kidding. Sortof.keithellis wrote:That is an answer, but the model A is much better when running off batteries for robot or remote projects. It is also cheaper.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com
Re: headless wifi setup: easiest approach?
All.
I was working on a (probably now abortive) project which used an initrd. This was configured to install some packages (held in the initrd as the Pi is offline), run a setup bash script that made the Pi a wireless AP and then enabled wifi passwords (etc) to be entered via a web interface (the script could do anything else too). The web interface also exposed a shell via the web configuration page (it used shellinabox but was not very good - very browser dependent).
From the user's perpective, all that was required was to:
(a) burn a standard image
(b) drop the initrd into the /boot partition (i.e. via the FAT partition in windows);
(c) add two lines to config.txt; and
(d) boot the Pi with a wifi dongle attached, wait a minute for the configuration of the AP and webserver (I used webpy) and then connect to the Pi and configure as they liked (expanding the root partition and anything else was possible) Once it finished running (over a reboot or two), the script restored config.txt, removed the initrd file and restored the Pi to pretty much standard but otherwise configured(OK python2, hostapd and dhcp (server) were still installed but were inactive).
I thought it was quite neat.
What I wrote could easily be adopted here and I am happy to share if anyone is interested (at least someone will be able to gain something from my abortive project). I should say, however, that I use Arch and Raspbian will differ in the implementation details.
BBUK
I was working on a (probably now abortive) project which used an initrd. This was configured to install some packages (held in the initrd as the Pi is offline), run a setup bash script that made the Pi a wireless AP and then enabled wifi passwords (etc) to be entered via a web interface (the script could do anything else too). The web interface also exposed a shell via the web configuration page (it used shellinabox but was not very good - very browser dependent).
From the user's perpective, all that was required was to:
(a) burn a standard image
(b) drop the initrd into the /boot partition (i.e. via the FAT partition in windows);
(c) add two lines to config.txt; and
(d) boot the Pi with a wifi dongle attached, wait a minute for the configuration of the AP and webserver (I used webpy) and then connect to the Pi and configure as they liked (expanding the root partition and anything else was possible) Once it finished running (over a reboot or two), the script restored config.txt, removed the initrd file and restored the Pi to pretty much standard but otherwise configured(OK python2, hostapd and dhcp (server) were still installed but were inactive).
I thought it was quite neat.
What I wrote could easily be adopted here and I am happy to share if anyone is interested (at least someone will be able to gain something from my abortive project). I should say, however, that I use Arch and Raspbian will differ in the implementation details.
BBUK
Re: headless wifi setup: easiest approach?
See here for a way to configure a model A headlessly.
http://www.raspberrypi.org/forums/viewt ... 29&t=75762
Sorry about the X-post
BBUK
http://www.raspberrypi.org/forums/viewt ... 29&t=75762
Sorry about the X-post
BBUK
Re: headless wifi setup: easiest approach?
@j3rryken could u share some code ?
i`m looking for smth similar to your work whole week !!!
regards
i`m looking for smth similar to your work whole week !!!
regards
-
- Posts: 1
- Joined: Thu Feb 16, 2017 10:59 am
Re: headless wifi setup: easiest approach?
HI,
This is pushpa i am also trying the same thing. i made raspberry hotspot and getting the wifi list but when i am trying to authenticate wifi its giving error in command line .please can u share the code for me regording of html display
Thanks,
pushpa teja.c
This is pushpa i am also trying the same thing. i made raspberry hotspot and getting the wifi list but when i am trying to authenticate wifi its giving error in command line .please can u share the code for me regording of html display
Thanks,
pushpa teja.c
-
- Posts: 38
- Joined: Wed Jan 02, 2013 1:38 pm
Re: headless wifi setup: easiest approach?
Does anyone have a solution that works with recent Raspbians as above solution does not work anymore?
-
- Posts: 142
- Joined: Thu Dec 12, 2013 10:39 pm
- Location: Suffolk, UK
- Contact: Website
Re: headless wifi setup: easiest approach?
Yes it’s easy now, once you have burnt your new Raspbian image, mount the boot directory on you desktop/laptop and create a wpa_suplicant.conf file with your wifi settings.gulliverrr wrote:Does anyone have a solution that works with recent Raspbians as above solution does not work anymore?
If you want ash enabled create a blank file called ssh
Save both of these files in /boot
Then put your SD card in your Pi and switch on. On first boot the wpa_suplicant.conf file will be copied over to /etc/wpa_supplicant and ssh will be enabled.
Easy.
Re: headless wifi setup: easiest approach?
NB: probably better to tell people to put it on the FAT partition of the card. If you're on Windows it's the only partition you can access.keithellis wrote:Save both of these files in /boot
The file goes in the root directory of that partition, *not* in a subdirectory 'boot'
Re: headless wifi setup: easiest approach?
Sorry to dig out such an old thread, but I hope this might be useful to people stopping by here looking for a solution:
There's a project called BerryLan (https://berrylan.org) now which is meant to provide easy headles wifi setup. Basically it provisions WiFi credentials over Bluetooth.
Any raspbian out there can be enabled for this by adding the nymea repo:
Alternatively there are images with nymea-networkmanager preinstalled available on the website.
After installing that it can be configured using a smartphone app.
All of this is open source code available on github too.
Hope this helps,
Michael
There's a project called BerryLan (https://berrylan.org) now which is meant to provide easy headles wifi setup. Basically it provisions WiFi credentials over Bluetooth.
Any raspbian out there can be enabled for this by adding the nymea repo:
Code: Select all
sudo apt-add-repository deb http://repository.nymea.io stretch main
sudo apt-get update
sudo apt-get install nymea-networkmanager
sudo systemctl enable nymea-networkmanager
Alternatively there are images with nymea-networkmanager preinstalled available on the website.
After installing that it can be configured using a smartphone app.
All of this is open source code available on github too.
Hope this helps,
Michael
Re: headless wifi setup: easiest approach?
TBH: I can't see the advantage if I have to install a load of 3rd party software before I can use it. I would have to connect and log in to make the changes first.mzanetti wrote: ↑Mon Oct 15, 2018 3:39 pmThere's a project called BerryLan (https://berrylan.org) now which is meant to provide easy headles wifi setup.
And no, I would not install a Raspian image from a random website. Never done that and I can't see a reason why I would change that.
Re: headless wifi setup: easiest approach?
Concurring with @DirkS
Things have changed a lot since the issue was first raised nearly 5 years ago.
The method documented by the Raspberry Pi Foundation and exhaustively expanded and explained by forum user @HawaianPi works reliably and is straightforward.
But different folks have different needs and if this third-party solution helps someone that can't be bad.
Things have changed a lot since the issue was first raised nearly 5 years ago.
The method documented by the Raspberry Pi Foundation and exhaustively expanded and explained by forum user @HawaianPi works reliably and is straightforward.
But different folks have different needs and if this third-party solution helps someone that can't be bad.