Sometimes I have to take my headless system to places that I don't know the WiFi SSID/Password before hand. SSH does not reliably work via usb, which is a pain anyways with my enclosure.

Is there a wireless way to change SSID/Password settings on the fly. I'm a mechanical Engineer, I don't know complex linux concepts, maybe this is trivial.

Some consumer IoT devices broadcast there own network for initial config of home SSID/Password. Is that possible? Necessary equipment/software/code?

I have Debian 3.8 on Pi 2, and use /etc/network/interfaces for setting SSID/Password "manually"

  • SSH does not reliably work via usb - I'd be interested to know, reliability aside, how this is achieved at all ... I do have a kernel of a solution in mind, but nee to get to my raspberry pi to test it before I even propose a solution :p are you able to plug in a thumb drive with your enclosure? Jul 6, 2016 at 5:16
  • This is a prototype, while I could do I USB drive in development,( i see where you're going) I'd like to avoid potential end user infecting own equipment with bad usb drive. Jul 6, 2016 at 6:25
  • Does your wifi device allow AP mode? Jul 6, 2016 at 6:34
  • As for infecting with bad USB drive, I don't think linux is vulnerable to that if you do it right (I'm not 100% sure on that though) Jul 6, 2016 at 6:35
  • What about a basic serial cable to the system console? Jul 6, 2016 at 13:58

3 Answers 3


guess you are looking for a configuration mode on the Pi. With a SPDT switch connected to GPIO pins you can trigger some scripts to change the PI's config and start in AP mode.

for both modes i would use different network interface config in /etc/network: interface.ap and interface.normal. the switching script just will set a symlink to the specific interface file

in normal mode the pi will connect its wlan0 to one of the WIFIs configured in the wpa_supplicant.conf. IP will be obtained automatically by DHCP.

The /etc/network/interfaces.ap to:

iface wlan0 inet dhcp
    allow-hotplug wlan0
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

in AP mode, the wlan0 needs to be configured with a static IP, bring up hostapd and dhcp.

you will need a installation of hostapd and dhcp server (the following is from eLinux: install software:

sudo apt-get install hostapd udhcpd

configure udhcpd: /etc/udhcpd.conf

start # This is the range of IPs that the hostspot will give to client devices.
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns # The DNS servers client devices will use.
opt subnet
opt router # The Pi's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds

infact all the dns settings will be irrelevant because the Pi has no internet connection during AP mode. Then configure the /etc/network/interfaces.ap to:

iface wlan0 inet static

and the last step for AP mode is the configuration of hostapd at /etc/hostapd/hostapd.conf

#wpa_pairwise=TKIP  # You better do not use this weak encryption (only used by old client devices)

wiring the switch here i can't bring up all details because i cant test the wiring at the moment. in general the configuration should be like this tutorial. the switch will be connected on two GPIO pins.

scripting a phyton script will check the position of the switch and fire the changes if the mode changes. the status of the mode can be checked with a variable that will be set on status changes or just read where the symlink is pointing to... it would be basically like this GPIO.input(21) is for AP mode and GPIO.input(17) is for normal mode:

while True:
  if (GPIO.input(17) and my_state=='AP'):
    my_state = 'normal'
    os.system("rm /etc/network/interfaces")
    os.system("ln -s /etc/network/interfaces.normal /etc/network/interfaces")
    os.system("ifdown wlan0 && ifup wlan0")
    os.system("systemctl stop hostapd")
    os.system("systemctl stop udhcpd")
    os.system("systemctl disbale hostapd")
    os.system("systemctl disbale udhcpd")

  if (GPIO.input(21) and my_state==normal):
    my_state = 'ap'
    os.system("rm /etc/network/interfaces")
    os.system("ln -s /etc/network/interfaces.ap /etc/network/interfaces")
    os.system("ifdown wlan0 && ifup wlan0")
    os.system("systemctl enbale hostapd")
    os.system("systemctl enbale udhcpd")
    os.system("systemctl start hostapd")
    os.system("systemctl start udhcpd")

okay this script snipplet is a quick example and very dirty. (I am not an expert in python and could not test it.) Maybe some others can help to improve it.

  • Would it be more efficient to put the groups of os.system calls into two bash scripts, so os.system only gets called once? I have strep, so can't test this for a few days. -OP Jul 8, 2016 at 15:40
  • @NasaWelder, yes of course the sytsem calls can be handled in bash scripts that will be triggered by one syscall. if it is more efficient than in phyton I dont know. I am not python expert) Jul 8, 2016 at 16:55
  • @JoePlatano I would like to use something like your concept, but my question is in AP Mode, is the Pi has to connect to ethernet cable? If not, How can I give wifi ssid and password to Pi?
    – ton1
    Oct 30, 2016 at 13:03
  • @JoePlatano so If the Pi has not ethernet cable, I can't use your way, right?
    – ton1
    Oct 30, 2016 at 13:07
  • 1
    @Juntae, the Pi is running completely without Ethernet cable connected. In the use case of the NasaWelder, it is not possible to connect the Pi to Ethernet to configure it. Therefore the AP mode. If you can connect the Pi to Ethernet and are able to SSH to the Pi, AP Mode is not necessary. The SSID is provided by Hostapd (see the config in my awnser ssid=My_AP so the password for the AP) the IP Addresses in AP mode are provided by udhcpd. Oct 30, 2016 at 15:50

Some consumer IoT devices broadcast there own network for initial config of home SSID/Password. Is that possible?


Necessary equipment

You need a wifi adapter that supports AP (access point) mode. I think most but not all of them do. You could check with

sudo iw list | grep -A 12 -i "supported interface modes"

This may not be definitive in that it gives you a blind 12 lines of context after the search term, so if the list is longer than that you won't see all of them, in which case you could just scroll through the entire output of iw list (if iw isn't installed, apt install iw). However if the list is that long it probably includes AP.


hostapd and probably dhcpd. The latter is a server that hands out IP addresses to clients that want to connect. Unfortunately my approach to networking is unorthodox so I can't tell you the canonical approach to this,1 however, you will find many guides to configuring this software for use as a wifi hotspot online (including some specifically dedicated to the Pi/Raspbian; the quality of that stuff varies greatly and tends toward the low side IMO, but when it is correct and complete it is the most straightforward to follow).

Once the hotspot is running you'll have to connect to it, configure the ESSID, password, etc. You may be able to do this without losing your own connection to it for reasons implied in the footnote; if not you'll have to have a script you can trust to complete the task after you are disconnected.

This will take a bit of trial and error experimentation. ;)

1. This is related to the larger issue of having the system start up this way only if it cannot find a known network to connect to. It might not be too complicated to have it do both, since technically an AP (access point) is connected to a network, and managing connections to it. However, I've only used it to create a hotspot. Having it run normally like that is probably at best pointless, so you would want to at least turn off hostapd when you are connected as a normal client/end point.

  • I don't see the answer here, just a few leads. Not very helpful for a mechanical engineer.
    – fcm
    Jul 8, 2016 at 1:39
  • @fcm Well, I definitely think Joe Platano's answer went a step beyond in terms of detail. I also think it is a shame I am the only person to have upvoted that answer thus far.
    – goldilocks
    Jul 8, 2016 at 3:09

Which version of the Pi are you running? If you have a Pi 3 you could maybe configure the Bluetooth to expose a virtual serial port that you could use as a console for configuring the SSID/Password.

Perhaps something like this could work (just with the built-in Bluetooth rather than a plug-in module.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.