Modify LUCI(include new tab) to display a file in text format

I am fairly new to Opnenwrt. I am trying to modify luci to display a file with auto refresh capability.

So, i am generating a file at tmp/xxxx and it's updating every 4 seconds. I have managed to display it on Luci but i want auto-refresh functionality.

I am currently using this code in usr/lib/lua/luci/controller/admin/chng.lua to generate 2 new tabs, xxxx will be used for displaying the file.

module("luci.controller.admin.chng", package.seeall)

function index()
	entry({"admin", "chng"}, firstchild(), "Chng", 60).depedent=false
	entry({"admin", "chng", "tab_one"}, template("yyy"),_("yyy"), 1)
	entry({"admin", "chng", "tab_two"}, form("xxxx"),_("xxxx"), 2)
end

And to display I am using following code at usr/lib/lua/luci/model/cbi/xxxx.lua to display the file in simple text format(or as it is in the file).


<%#local fs  = require "nixio.fs"
local sys = require "luci.sys"


f = SimpleForm("rc", translate("Look This Is It!!"))


t = f:field(TextValue, "rcs")
t.rmempty = true
t.rows = 20


function t.cfgvalue()
	return fs.readfile("/tmp/kamnu")
end

return f
-%>

which is similar to the startup tab of the luci(that displays rc.local file), can someone help me to make this auto refreshing i found that "XHR.poll" can be used but i cant figure it out as I don't have experience with html and javascript, please help me.

Hi dontknow,

I'm trying to add my own page to Luci too. I followed your instruction.

What I've done:

  1. created a file usr/lib/lua/luci/controller/admin/chng.lua with first snippet of code
  2. created a file usr/lib/lua/luci/model/cbi/xxxx.lua with second snippet of code
  3. restarted my router

I don't see new tabs in a main menu strip. Maybe I should do anything else?

Can you just do the autorefresh in javascript?

well the first file chng.lua is all you need actually to make the tabs. And the other file xxxx.lua is commented out you should remove " <%#.....%>".
for starters just try out a simple html view file. Like, for using html you need to show it as template so try it out with yyy tab just make a simple html file at .....luci/view/yyy.htm for example,

<%+header%>
<h1><%:hmm%></h1>
<%+footer%>
1 Like

I guess so, but I don't have any experience with javascript so wanted some help so i can use it as a reference.

Yes, I've done it. Thanks for help.
My next step is to send any symbol to serial port pressing a button on this page. Maybe you know how... :blush:

Regarding your problem. You can use a code below (your page will refresh every 4 seconds without javascript):

yes, actually that was my last hope to use auto refresh in the page but man, i dont know how to print my file using html so its not working.

For your problem I think you should look into GPIO part it should be somewhat similar.

Look at the syslog or kernel log pages for examples

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