OpenWrt Forum Archive

Topic: Can I set set the SSID name using a boot variable?

The content of this topic has been archived on 28 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I want to let my client use a flash drive to pull out and put in his computer to set the SSID in a text file named "ssid.txt". Then upon sticking it back into the router, and reboot, it picks up this name and uses it. Possible?

More: I am wanting a very easy way for my client to change the open Wi-Fi name and this seems easier and more direct than having them log in and do it. If I put the name in a text file sitting on the USB flash drive ( which they will leave in the router ), it can simply be rebooted, pickup the new/changed SSID and then work. They'll take that flash drive out and edit the file directly naming it whatever they want and I don't have to intervene or be troubled. This is my plan.

Note: I am a n00b ( first forum post ) at OpenWRT but have some exp. with DOS batch files and some terminal exp on OSX.

(Last edited by usermac on 14 Apr 2013, 20:01)

Why does the client need to change ssids? Why not just keep the same one always?
If you want to do this for a variety of routers then you need root access for them all. If you already have this, why not just fix them all once?
The way you suggest seems very insecure to me.
If you only want to "fix" them all once, you will still need to access each router at least once to add some sort of script to get the job done, so why not just edit the ssid then, instead.

I want the client to be able to change the SSID at will without a login to the admin webpage.

(Last edited by usermac on 14 Apr 2013, 21:14)

You can't change the ssid without logging in.
You could write a one-click-script for his PC that logs in and changes it for him.
If it was possible to do what you want, then anyone could do it. That's the point of having to log in: it authenticates the person trying to modify the router.

Assuming you will auto-mount the USB drive in /home, you can try something like this on the start up script.

[ -f /home/ssid.txt]&&(ssid=`cat /home/ssid.txt`; uci set wireless.@wifi-iface[0].ssid='$ssid'; uci commit wireless; /sbin/wifi down; /sbin/wifi up)

Note: I didn't personally test this and it does not perform any sanity check on the ssid.txt input content. So you'll need handle that if you worry about security and malformed input in your text file. The uci section "wireless.@wifi-iface[0].ssid=" is specific to my device. You can run "uci show wireless" to determine the right section specific to your router.

(Last edited by phuque99 on 15 Apr 2013, 08:45)

Thank you @phuque99 as I just got my router in over the weekend. I put your code in System > Startup > Local Startup section but one part seems to not work and that is the line that starts with " -f":

# Mount the usb
cd /mnt/usb
# Below is compliments of @phuque99 
# Read the contents of the wifiname.txt 
 -f /home/wifiname.txt]&&(ssid='cat /home/wifiname.txt'
# Set the wireless ssid to that content
uci set wireless.@wifi-iface[0].ssid='cat /home/wifiname.txt'
# Commit the change
uci commit wireless
# Drop wireless to stop old name
/sbin/wifi down
# Bring up the wireless to use the new name
/sbin/wifi up
# I don't know what this does
exit 0

CORRECTED because I really botched some lines while testing things. This is my next best attempt.

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
# Mount the usb
cd /mnt/usb
# Below is compliments of @phuque99 via openwrt.org forum April 2013 
# Read the contents of the wifiname.txt 
 -f /mnt/usb/wifiname.txt]&&(ssid='cat /mnt/usb/wifiname.txt'
# Set the wireless ssid to that content
uci set wireless.@wifi-iface[0].ssid='$ssid'
# Commit the change
uci commit wireless
# Drop wireless to stop old name
/sbin/wifi down
# Bring up the wireless to use the new name
/sbin/wifi up
# I don't know what this does
exit 0

(Last edited by usermac on 22 Apr 2013, 12:42)

You omitted the opening square bracket ("[") in the "-f" test.

You also have a clause beginning "(".  Where does it end?  What is its significance in the original posting?  You need to look up the syntax of cli/bash scripts (a steep hill, admittedly).

I wonder know if there is a way to set ssid without using uci.
I tried iwconfig and iw, both a fail (Operation not supported) on my machine.
I use LInkesys w54g and OpenWrt 10.03.1.

Why not create a hotplug script and change the ssid on the fly when the usb stick is connected?
Also I don't really see the point to set the ssid without uci.

The discussion might have continued from here.