user2902947
user2902947

Reputation: 27

How to edit options in openwrt libuci

I'm trying to edit the options of routers ssid using libuci. I can read properly but not getting how to edit. With the reference of below link i can read but how to edit(like if i want to change network.lan.proto).

How to find out if the eth0 mode is static or dhcp?

Upvotes: 2

Views: 5376

Answers (3)

Paktwis Homayun
Paktwis Homayun

Reputation: 330

The network configuration is located in /etc/config/network. Here is an example of a configuration you can use:

config wifi-iface
    option 'device'     'radio0'
    option 'mode'       'sta'
    option 'ssid'       'Some Wireless Network'
    option 'encryption' 'psk2'
    option 'key'        '12345678'
    option 'network'    'wwan'

You can find more documentation here: OpenWRT network config

Upvotes: -1

devilfish_mm
devilfish_mm

Reputation: 88

If you want to use the C API for UCI, you can use the following code:

#include <uci.h>

void main()
{
   char path[]="network.lan.proto";
   char buffer[80];
   struct  uci_ptr ptr;
   struct  uci_context *c = uci_alloc_context();

   if(!c) return;

   if ((uci_lookup_ptr(c, &ptr, path, true) != UCI_OK) ||
         (ptr.o==NULL || ptr.o->v.string==NULL)) 
   { 
     uci_free_context(c);
     return;
   }

   if(ptr.flags & UCI_LOOKUP_COMPLETE)
      strcpy(buffer, ptr.o->v.string);

   printf("%s\n", buffer);

   // setting UCI values
   // -----------------------------------------------------------
   // this will set the value to 1234
   ptr.value = "1234";
   // commit your changes to make sure that UCI values are saved
   if (uci_commit(c, &ptr.p, false) != UCI_OK)
   {
      uci_free_context(c);
      uci_perror(c,"UCI Error");
      return;
   }

   uci_free_context(c);
}

Reference is from this post: OpenWrt LibUbi implementation

Upvotes: 4

urban_raccoons
urban_raccoons

Reputation: 3497

There's a lot of documentation at the openwrt wiki:

http://wiki.openwrt.org/doc/uci

To change network.lan.proto from the command line you can use:

uci set network.lan.proto=dhcp

oh and then you'll want to commit the changes and restart the network:

uci commit network /etc/init.d/network restart

Upvotes: 1

Related Questions