Openwrt and UCI.

In my previous blog i wrote about how to compile openwrt firmware,  I flashed it on Nanostation and Nanostation M2 (How to flash it, I will write about it later).  I finished flashing and started reading how to configure it for my requirement and I came across openwrt wiki page which mention about UCI (Unified Configuration Interface), reading first few lines found out very interesting and wanted to try out how stuff works with UCI. This blog is main about how to use UCI  to configure your openwrt AP.

Use of UCI – To set values in configuration file,  instead of  opening the file and editing it we can do it from shell using UCI.

Working – UCI set the values in temporary location  and then when we commit its written in configuration file and  using init.d script the configuration are read from configuration file .

To see UCI configuration/options just type “UCI” inside openwrt.

By Default : UCI looks into /etc/config dir and file inside it.

I will be covering few command with example :

All My example will be on  wireless config file in /etc/config/wireless

1) Export

This is reading the file in machine readable format that’s what wiki say 🙂  actually it “cat’s” the configuration file on terminal.

Example : uci export wireless 

Above command will cat complete configuration file on terminal

uci export wireless | grep ssid | awk ‘{print $1}’  – This will give you the SSID your AP.  🙂

2) changes & commit

As explained earlier , UCI writes the configuration to a temp location and after commit the configuration its written in config file. Changes is used to check the configuration settings which was made  before committing it.

Commit this will write changes to the configuration file.

Example :  uci changes wireless

This will list you the changes which you have made.

1) uci get wireless.@wifi-iface[1].ssid – This will give you present SSID of AP

2) uci set wireless.@wifi-iface[1]ssid=dipin –  This will set wireless SSID to dipin 🙂

3) uci changes wireless –  This will print wireless.cfg*****.ssid=dipin

4) uci commit wireless  –   This will replace old SSID with new SSID = dipin.

NOTE : After doing above 4 steps , your SSID will not change. For changes to get effect you need to restart the service  like /etc/init.d/network restart

3) show

“Show” give you the compressed notation which can be used in uci set,  get and other command. Like give a config file how will understand to get the SSID of a interface ?

Example  uci show wireless

This will print the compressed format which need to be used like <config>[.<section>[.<option>]]]

uci show wireless   this will print lot of stuff like below,

Above printed message can be used to is get command like : uci get ,  which will print your channel on which  the radio is running.

4) get

This is used to get values from configuration files.

Example :

1) uci  get wireless.@wifi-iface[1].ssid –  This will get SSID of  your first radio .

2) uci get uhttpd .main.listen_https –  This will get https port on which AP is listening.

3) uci get network.wan.ifname –    This will get your WAN interface.

5) set

This is used to set values to given options.

Example :

1) uci set wireless.@wifi-iface[1],ssid=dipin         –  set SSID to one of your radio.
2) uci set uhttps.main.listen_https=444               –   Set https port to 444 from 443
3) uci set wirelss.radio0.disable=1                       –     This will stop the wireless broadcast.

If you  have any doubt feel free to contact me, I will always be ready to help you out 🙂


3 thoughts on “Openwrt and UCI.

  1. uci export wireless | grep ssid | awk ‘{print $1}’

    could be written shorter and with one process less :
    uci export wireless | awk ‘/ssid/ {print $1}’

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s