1

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"

3 Answers3

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 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 # 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
  address 192.168.42.1
  netmask 255.255.255.0

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

interface=wlan0
driver=nl80211
ssid=My_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP  # You better do not use this weak encryption (only used by old client devices)
rsn_pairwise=CCMP

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.

000
  • 103
  • 3
Joe Platano
  • 852
  • 8
  • 19
1

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

Yes.

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.

Software?

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.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
0

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.