User avatar
jbeale
Posts: 3494
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

headless wifi setup: easiest approach?

Fri Jan 31, 2014 5:07 pm

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.

User avatar
DougieLawson
Posts: 36182
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: headless wifi setup: easiest approach?

Fri Jan 31, 2014 5:36 pm

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.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

keithellis
Posts: 142
Joined: Thu Dec 12, 2013 10:39 pm
Location: Suffolk, UK
Contact: Website

Re: headless wifi setup: easiest approach?

Mon Feb 03, 2014 8:42 am

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.
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.

Take a look, hopefully you might find it useful.
http://bit.ly/headless_install

djbutler
Posts: 3
Joined: Fri Apr 04, 2014 7:41 pm

Re: headless wifi setup: easiest approach?

Fri Apr 04, 2014 7:45 pm

I'm also interested in solving this problem using the Wifi hotspot strategy instead of using a cable. I'll post any progress.

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: headless wifi setup: easiest approach?

Fri Apr 04, 2014 9:17 pm

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
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: headless wifi setup: easiest approach?

Fri Apr 04, 2014 9:38 pm

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.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

j3rryken
Posts: 7
Joined: Wed Mar 26, 2014 8:28 pm

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 12:34 am

what i made:
Image
Image

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

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 3:03 am

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
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 3:47 am

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

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 4:50 am

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.
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.

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

keithellis
Posts: 142
Joined: Thu Dec 12, 2013 10:39 pm
Location: Suffolk, UK
Contact: Website

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 8:39 am

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.
But what do you do if you have a model A without Ethernet port. That's why I find the console cable so handy.

Tutorial here:
http://bit.ly/headless-install-playlist

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 9:24 am

keithellis wrote:
But what do you do if you have a model A without Ethernet port.
Buy a model B.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

keithellis
Posts: 142
Joined: Thu Dec 12, 2013 10:39 pm
Location: Suffolk, UK
Contact: Website

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 9:30 am

That is an answer, but the model A is much better when running off batteries for robot or remote projects. It is also cheaper.

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 11:03 am

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

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: headless wifi setup: easiest approach?

Sun Apr 06, 2014 4:35 pm

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.
I was kidding. Sortof.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

BBUK
Posts: 141
Joined: Tue Dec 18, 2012 10:34 am

Re: headless wifi setup: easiest approach?

Mon Apr 14, 2014 1:07 pm

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

BBUK
Posts: 141
Joined: Tue Dec 18, 2012 10:34 am

Re: headless wifi setup: easiest approach?

Sun Apr 27, 2014 3:17 pm

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

binar123
Posts: 1
Joined: Tue Sep 02, 2014 12:27 pm

Re: headless wifi setup: easiest approach?

Tue Sep 02, 2014 12:32 pm

@j3rryken could u share some code ?
i`m looking for smth similar to your work whole week !!!
regards

pushpapavan
Posts: 1
Joined: Thu Feb 16, 2017 10:59 am

Re: headless wifi setup: easiest approach?

Thu Feb 16, 2017 11:06 am

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

gulliverrr
Posts: 38
Joined: Wed Jan 02, 2013 1:38 pm

Re: headless wifi setup: easiest approach?

Fri Jul 14, 2017 9:13 pm

Does anyone have a solution that works with recent Raspbians as above solution does not work anymore?

keithellis
Posts: 142
Joined: Thu Dec 12, 2013 10:39 pm
Location: Suffolk, UK
Contact: Website

Re: headless wifi setup: easiest approach?

Fri Jul 14, 2017 9:24 pm

gulliverrr wrote:Does anyone have a solution that works with recent Raspbians as above solution does not work anymore?
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.

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.

DirkS
Posts: 9947
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: headless wifi setup: easiest approach?

Fri Jul 14, 2017 9:36 pm

keithellis wrote:Save both of these files in /boot
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.
The file goes in the root directory of that partition, *not* in a subdirectory 'boot'

mzanetti
Posts: 4
Joined: Tue Sep 25, 2018 1:25 pm

Re: headless wifi setup: easiest approach?

Mon Oct 15, 2018 3:39 pm

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:

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

DirkS
Posts: 9947
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: headless wifi setup: easiest approach?

Mon Oct 15, 2018 4:12 pm

mzanetti wrote:
Mon Oct 15, 2018 3:39 pm
There's a project called BerryLan (https://berrylan.org) now which is meant to provide easy headles wifi setup.
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.
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.

User avatar
B.Goode
Posts: 8617
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: headless wifi setup: easiest approach?

Mon Oct 15, 2018 4:22 pm

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.

Return to “Networking and servers”