OpenWrt Forum Archive

Topic: CBI questions

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

I've discovered the beauty of CBI and want to create a "Quick WiFi Setup" page, but I have a question.

Right now this is what my cbi file looks like:

local iface = luci.model.uci.cursor():get_first("wireless", "wifi-iface")
m = Map("wireless", "WiFi Quick Config")
s1 = m:section(NamedSection, iface, "wifi-iface", "WiFi Options")
p11 = s1:option(Value,"ssid","WiFi Name")
p12 = s1:option(Value,"key","WiFi Password")
s2 = m:section(NamedSection, "radio0", "wifi-device", "WiFi Device Options")
p21 = s2:option(ListValue, "channel", "Channel")
p21:value("auto", "Auto Channel")
p21:value("1", "Channel 1")
p21:value("2", "Channel 2")
p21:value("3", "Channel 3")
p21:value("4", "Channel 4")
p21:value("5", "Channel 5")
p21:value("6", "Channel 6")
p21:value("7", "Channel 7")
p21:value("8", "Channel 8")
p21:value("9", "Channel 9")
p21:value("10", "Channel 10")
p21:value("11", "Channel 11")
return m

And it of course creates two sections (as per screenshot below).
https://s18.postimg.org/lr9wegpnd/Screen_Shot_2016_11_24_at_07_45_54.png

How can I roll all these settings into one section visually?

Also, how can I create an item which would depend on another item not containing specific value, but just being non-empty? I want to add the encryption only if the password is non-empty. What's the best way to do that?

stangri wrote:

I've discovered the beauty of CBI and want to create a "Quick WiFi Setup" page, but I have a question.

Right now this is what my cbi file looks like:

local iface = luci.model.uci.cursor():get_first("wireless", "wifi-iface")
m = Map("wireless", "WiFi Quick Config")
s1 = m:section(NamedSection, iface, "wifi-iface", "WiFi Options")
p11 = s1:option(Value,"ssid","WiFi Name")
p12 = s1:option(Value,"key","WiFi Password")
s2 = m:section(NamedSection, "radio0", "wifi-device", "WiFi Device Options")
p21 = s2:option(ListValue, "channel", "Channel")
p21:value("auto", "Auto Channel")
p21:value("1", "Channel 1")
p21:value("2", "Channel 2")
p21:value("3", "Channel 3")
p21:value("4", "Channel 4")
p21:value("5", "Channel 5")
p21:value("6", "Channel 6")
p21:value("7", "Channel 7")
p21:value("8", "Channel 8")
p21:value("9", "Channel 9")
p21:value("10", "Channel 10")
p21:value("11", "Channel 11")
return m

And it of course creates two sections (as per screenshot below).
https://s18.postimg.org/lr9wegpnd/Screen_Shot_2016_11_24_at_07_45_54.png

How can I roll all these settings into one section visually?

Also, how can I create an item which would depend on another item not containing specific value, but just being non-empty? I want to add the encryption only if the password is non-empty. What's the best way to do that?


not sure if this is what you're after...

local iface = luci.model.uci.cursor():get_first("wireless", "wifi-iface")
m = Map("wireless", "WiFi Quick Config")
s1 = m:section(NamedSection, iface, "wifi-iface", "WiFi Options")
p11 = s1:option(Value,"ssid","WiFi Name")
p12 = s1:option(Value,"key","WiFi Password")
p12.password = true
p21 = s1:option(ListValue, "channel", "Channel")
p21:value("auto", "Auto Channel")
p21:value("1", "Channel 1")
p21:value("2", "Channel 2")
p21:value("3", "Channel 3")
p21:value("4", "Channel 4")
p21:value("5", "Channel 5")
p21:value("6", "Channel 6")
p21:value("7", "Channel 7")
p21:value("8", "Channel 8")
p21:value("9", "Channel 9")
p21:value("10", "Channel 10")
p21:value("11", "Channel 11")
return m
hostle19 wrote:

not sure if this is what you're after...

local iface = luci.model.uci.cursor():get_first("wireless", "wifi-iface")
m = Map("wireless", "WiFi Quick Config")
s1 = m:section(NamedSection, iface, "wifi-iface", "WiFi Options")
p11 = s1:option(Value,"ssid","WiFi Name")
p12 = s1:option(Value,"key","WiFi Password")
p12.password = true
p21 = s1:option(ListValue, "channel", "Channel")
p21:value("auto", "Auto Channel")
p21:value("1", "Channel 1")
p21:value("2", "Channel 2")
p21:value("3", "Channel 3")
p21:value("4", "Channel 4")
p21:value("5", "Channel 5")
p21:value("6", "Channel 6")
p21:value("7", "Channel 7")
p21:value("8", "Channel 8")
p21:value("9", "Channel 9")
p21:value("10", "Channel 10")
p21:value("11", "Channel 11")
return m

That doesn't work because there's no channel option in wifi-iface section.

you can just remove the title from the second section .. this will just space it a little different. Other than that I think its more work then it's worth ...

local iface = luci.model.uci.cursor():get_first("wireless", "wifi-iface")
m = Map("wireless", "WiFi Quick Config")
s1 = m:section(NamedSection, iface, "wifi-iface", "WiFi Options")
p11 = s1:option(Value,"ssid","WiFi Name")
p12 = s1:option(Value,"key","WiFi Password")
p12.password = true
s2 = m:section(NamedSection, "radio0", "wifi-device")
p21 = s2:option(ListValue, "channel", "Channel")
p21:value("auto", "Auto Channel")
for i=1,11 do
 p21:value(i, "Channel "..i)
end
return m

(Last edited by hostle19 on 1 Dec 2016, 04:26)

Thanks for your suggestion, it would still show channel in a separate cbi-box. I'm guessing the answer to my quest would be use of templates to combine configs from different sections into one "box".

The discussion might have continued from here.