I am using openwrt 17.02 LEDE for a router based project. I am trying to write to /etc/config/snmpd from my lua file in model/cbi. I am taking input from GUI and the input is being sent to /etc/config/snmpd using uci commands. Following is the code snippet from my lua file :
function m3.on_commit(map)
local uci = require("luci.model.uci").cursor()
local location = self:formvalue("cbid.snmp.snmpd.location")
local contact = self:formvalue("cbid.snmp.snmpd.contact")
local name = self:formvalue("cbid.snmp.snmpd.name")
local ro_community = self:formvalue("cbid.snmp.snmpd.ro_community")
local rw_community = self:formvalue("cbid.snmp.snmpd.rw_community")
-- Send values to /etc/config/snmpd
uci:set("snmpd", "system", "sysLocation", location)
uci:set("snmpd", "system", "sysContact", contact)
uci:set("snmpd", "system", "sysName", name)
-- Configure com2sec for public ro
uci:section("snmpd", "com2sec", "public", {
secname = "ro",
source = "default",
community = ro_community
})
-- Configure com2sec for private RW
uci:section("snmpd", "com2sec", "private", {
secname = "rw",
source = "localhost",
community = rw_community
})
uci:commit("snmpd")
luci.sys.call("/etc/init.d/snmpd restart")
end
But on clicking the save and apply in the GUI, I getting error : "bad argument #4 to 'set' (string expected, got nil)" for uci:set command.
I have checked the HTML form for the textbox entries and I had put the same values but I am not able to understand what I doing wrong with the formvalues command.