OpenWrt Forum Archive

Topic: Read 1 item from list of configs

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

Hello guys,

I need to read just one item from my wireless config file. There are 2 networks, I want to read the data from the [0] item :

here is how Im trying to read that information

m = Map("wireless", translate("Wifi Zero"), translate("blah blah blahj")) 
d = m:section(TypedSection, "wifi-iface", "List wifi networks, but I only want one")
a = d:option(Value, "ssid", "Network Name"); a.optional=false; a.rmempty = false;  
return m

here is my /etc/config/wireless

config wifi-iface
    option device 'radio0'
    option network 'lan'
    option mode 'ap'
    option ssid 'OpenWrt'
    option encryption 'psk'
    option key 'pass999'

config wifi-iface
    option device 'radio0'
    option mode 'ap'
    option ssid 'Freedom'
    option network 'lan'
    option encryption 'psk'
    option key 'pass888'

Ohhh, I found an solution

-- /usr/lib/lua/luci/model/cbi/testapp-testmodule/cbi_tab.luai
m = Map("wireless", translate("Sua Rede Wifi"), translate("Alterar/Salvar/Aplicar"))
d = m:section(TypedSection, "wifi-iface", "Rede Wifi")                              
function d.filter(self, section)                                                    
    return self.map:get(section, "ssid") ~= "CTBCWifi"           
end                                                              
a = d:option(Value, "ssid", "Nome da Rede"); a.optional=false; a.rmempty = false;
return m 

reference : http://www.martin.cc/OpenWrt/luci

The discussion might have continued from here.