LuCI options are not created

Hello everyone.
I recently created a topic on LuCi.
The entire custom application was made in js, but I realized that in order to implement the command output in the terminal, namely to implement the tio command terminal, I need to write the application in lua.
I read the guide:

After which I got the following application structure:
изображение
Yes, the entire application is made without a controller, but it works:


But now I have a problem creating options.
applications/luci-app-tiod/luasrc/model/cbi/config.lua:

m = Map("config", "Конфигурация")

s = m:section(TypedSection, "controlport", "Контрольный порт")

o = s:option(Value, "device", "Устройство", "Имя устройства для подключения.<br/>Должно быть в виде /dev/ttyS* (4,5,6).")
o.rmempty = false
o.default = "/dev/ttyS4"

s = m:section(TypedSection, "default", "Настройки по умолчанию")

o = s:option(ListValue, "speed", "Скорость передачи в бодах", "Скорость, на которой должен работать порт устройства.")
o:value(300)
o:value(1200)
o:value(2400)
o:value(4800)
o:value(9600)
o:value(19200)
o:value(38400)
o:value(57600)
o:value(115200)
o.default = 9600

o = s:option(ListValue, "databits", "Биты данных")
o:value(8)
o:value(7)
o:value(6)
o:value(5)
o.default = 8

o = s:option(ListValue, "parity", "Чётность")
o:value("none", "Отсутствует")
o:value("even", "Чётный")
o:value("odd", "Нечётный")
o.default = "none"

o = s:option(ListValue, "stopbits", "Стоповые биты")
o:value(1)
o:value(2)
o.default = 1

return m

Result:


The cache is empty, I checked everything several times, but options are not created or displayed.

I realized what was wrong.
In line

m = Map("config", "Конфигурация")

You need to specify the correct name so that it is linked to the config:

m = Map("tiod", "Конфигурация")

Options have appeared, but now for some reason there are other inscriptions that I don’t need.


How to remove CFG0125AB and CFG02548A?

Okaaaay i got it:

local fs = require "nixio.fs"

m = Map("tiod", "Конфигурация")

if fs.access("/etc/config/tiod") then
    s = m:section(TypedSection, "controlport", "Контрольный порт")
    s.anonymous = true
    s.addremove = false

    o = s:option(Value, "device", "Устройство", "Имя устройства для подключения.<br/>Должно быть в виде /dev/ttyS* (4,5,6).")
    o.default = "/dev/ttyS4"

    s = m:section(TypedSection, "default", "Настройки по умолчанию")
    s.anonymous = true
    s.addremove = false

    o = s:option(ListValue, "speed", "Скорость передачи в бодах", "Скорость, на которой должен работать порт устройства.")
    o:value(300)
    o:value(1200)
    o:value(2400)
    o:value(4800)
    o:value(9600)
    o:value(19200)
    o:value(38400)
    o:value(57600)
    o:value(115200)
    o.default = 9600

    o = s:option(ListValue, "databits", "Биты данных")
    o:value(8)
    o:value(7)
    o:value(6)
    o:value(5)
    o.default = 8

    o = s:option(ListValue, "parity", "Чётность")
    o:value("none", "Отсутствует")
    o:value("even", "Чётный")
    o:value("odd", "Нечётный")
    o.default = "none"

    o = s:option(ListValue, "stopbits", "Стоповые биты")
    o:value(1)
    o:value(2)
    o.default = 1
end

return m

Now how i can remove this?


On JS i just was writes:

handleSaveApply: null,
handleSave: null,
handleReset: null

How i can do it in Lua?

I don't have a controller file and all pages configure in
applications/luci-app-tiod/root/usr/share/luci/menu.d/luci-app-tiod.json:

{
	"admin/services/tiod": {
		"title": "RS232",
		"order": 90,
		"action": {
			"type": "firstchild"
		},
		"depends": {
			"acl": [ "luci-app-tiod" ]
		}
	},

	"admin/services/tiod/tiod": {
		"title": "Терминал",
		"order": 1,
		"action": {
			"type": "cbi",
			"path": "tiod",
			"post": { "cbi.submit": true }
		}
	},

	"admin/services/tiod/config": {
		"title": "Конфигурация",
		"order": 2,
		"action": {
			"type": "cbi",
			"path": "config",
			"post": { "cbi.submit": true }
		}
	}
}

In general, I figured it out, I still had to make a controller.
As a result, the project structure looks like this:
изображение
applications/luci-app-tiod/luasrc/controller/tiod.lua:

module("luci.controller.tiod", package.seeall)

function index()
	entry({"admin", "services", "tiod"}, firstchild(), "RS232", 60)
	entry({"admin", "services", "tiod", "tiod"}, cbi("tiod", {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}), "Терминал", 1)
	entry({"admin", "services", "tiod", "config"}, cbi("config"), "Конфигурация", 2)
end

Everything now works as I need, all that remains is to implement the terminal on the web.....

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.