config file for on-boot wifi


 

Steve_M

TVWBB Guru
Throwing this out there as it seems like it would be relatively simple to implement and could save some config headaches, especially for those with wifi devices that don't enter AP mode properly.

Have a wifi.txt file in the /boot folder that contains config info. This can be created right after the SD card is imaged. When the raspberry pi boots, a process looks for the presence of the wifi.txt file and configures the wifi device with that info.

Something like:

ssid="My_Wireless_SSID"
pass="My_Wireess_Password"
mode="(client or ap)" < Optional: Default to client mode if not present
 
I actually brought this exact same idea up a year or more ago and it didn't get much traction. The only problem I saw with it was that there are two ways it would work:
1) Overrides the wifi configuration on every boot
2) Overrides the wifi configuration only on first boot

#1 Sucks because you can't change the wifi configuration, ever, without pulling the SD card out
#2 Sucks because many firstboots aren't with fully operational hardware. You plug in the Pi, it looks like it is booting OK so you plug in the rest of the stuff and now it's no longer firstboot and you can't figure out why it isn't joining your AP.

I was just going to put it into config.txt though because it seemed simpler than having the extra step of "create a text file, no not a rich text file, no not wifi.txt.txt, no not in a folder what are you doing!". I had written all the code to do it and there wasn't much so it can easily be added. I think #2 is the least terrible of the options because it is sort of like how it gets set to AP mode currently but I am open to other ideas.
 
My thought process was that #2 would be the most desirable, or as you put it, least terrible :)

Perhaps it could:

1) check for a wireless device before running the config
2) check for the presence of /boot/wifi.configured ( for example )
2a) if /boot/wifi.configured doesn't exist, attempt to config wireless and create the empty /boot/wifi.configured file
2b) if /boot/wifi.configured exists, don't attempt to re-config

This also lets you put the SD card back into the computer, change the wifi options in config.txt, delete wifi.configured and have things re-configured on next boot.
 
Last edited:
Can you program for Option 1 using a unique text file like wificonfig.txt and then have the HM delete that text file after boot? That way for initial wifi config or wifi reset you could just throw a wificonfig.txt file on the SD Card...
 
It's easy enough to remove those lines from config.txt after the fact. The nice thing about config.txt, as Bryan mentioned, is that it already exists, so editing it should be a relatively straightforward task. If you want to re-config wireless, add the lines back to config.txt

You can always keep a local copy of config.txt in a folder on your computer to copy over the existing one.
 
It's easy enough to remove those lines from config.txt after the fact. The nice thing about config.txt, as Bryan mentioned, is that it already exists, so editing it should be a relatively straightforward task. If you want to re-config wireless, add the lines back to config.txt

You can always keep a local copy of config.txt in a folder on your computer to copy over the existing one.

Or just # (comment) it out.

Can you have it set up for multiple SSIDs/PWs? Go down a list of 'preferred' SSIDs, the AP mode if none are found.
/etc/network/interfaces worked like that on the beaglebone in Angstrom, but I haven't been able to put multiple networks in Debian (haven't tried real hard)
being able to set it up from config.txt would be nice.
 
Am I the only one that my wifi connects automatically? Perhaps I'm missing something here, but when my EDIMAX wifi adapter is working, all I have to do is plug my heatermeter into power and it grabs the wifi and an IP address without me mucking with it. If I want a static IP address I just configure my DHCP to always hand out the same IP to that mac address.
 
Chris,

This is to address initial wireless setup on a new heatermeter. By being able to put your wifi into into a config file, the system can boot and automatically join your wifi network without the need for performing the initial wifi config through the web gui.
 
This is now available in the latest snapshot. Just edit the config.txt file in the DOS/FAT partition (the one you see when you insert the SD card into a windows PC).
Code:
##
## wifi configuration
##
# SSID (network name)
#wifi_ssid=heatermeter
# Password for encryption
#wifi_password=password
# Encryption mode psk2 (WPA2-PSK default), psk, wep, none
#wifi_encryption=psk2
# Mode ap (Access Point) or sta (Client mode, default). Must be lowercase!
#wifi_mode=ap
# wifi channel, only used in AP mode
#wifi_channel=6

To set it in client mode you just need to uncomment out the wifi_ssid and wifi_password. The configuration takes place at the end of boot, after the network has already been initialized, so you'll see it pop up in the original mode first, then switch to the desired mode. This is because it needs to take place after the configuration restore has occurred (if it is going to). Once the wifi settings are loaded, it will automatically comment out all the wifi values in config.txt so it won't reset them again.

I've tested it to switch from ap to client mode, as well as to switch to client mode on a fresh install after the first boot, and a fresh install before the first boot. Please test and if it doesn't work then provide a detailed explanation as to why.
 

 

Back
Top