Openwrt-Luci 开发介绍(三)

2022年12月24日12:05:20 科技 1910

这篇重点讲如何在源码中Web开发

1. 创建目录及文件(以下重点讲RSSI和NicRate这两部分功能)


进入 openwrt源码/qsdk/qca/feeds/luci/applications
,添加下图中目录文件结构:

Openwrt-Luci 开发介绍(三) - 天天要闻

2. 上图luci-app-myapplication/Makefile文件中添加以下代码:

include $(TOPDIR)/rules.mk




LUCI_TITLE:=LuCI Support for Test

LUCI_DEPENDS:=




include ../../luci.mk

# call BuildPackage - OpenWrt buildroot signature

3. 在luasrc/controller/myapp/mobi.lua添加以下代码:

function index()

entry({"admin", "MOBI"}, firstchild(),"MOBI", 30).dependent=false

entry({"admin", "MOBI", "RSSI"}, template("rssi_test"), _("信号强度"), 1)

entry({"admin", "MOBI", "NicRate"}, cbi("mymodule/gateway"), translate("网卡速率"), 2)

end

4. 在/luasrc/view/myview/rssi_test中添加以下代码:

<%

local fs = require "nixio.fs"

local util = require "luci.util"

local log = require "luci.log"

require "luci.model.uci"

if luci.http.formvalue("status") == "1" then

local file = io.open('/sys/class/net/wlan0/device/prs_attrs/rx_rssi','r')

local ret

if file then

ret = file:read('*all')

file:close()

luci.http.prepare_content("application/json")

luci.http.write_json(ret)

return

else

ret = "Error"

log.print("ret="..ret)

luci.http.prepare_content("application/json")

luci.http.write_json(ret)

return

end

end

-%>

<%+header%>

<script type="text/javascript" src="<%=resource%>/cbi.js"></script>

<script type="text/javaScript">

XHR.poll(2,'<%=REQUEST_URI%>',{status:1},function(x,info) {

var ret = info;

document.getElementById("contxt").innerText = info;

}

);

</script>

<h1><a id="content" name="content"><%:Signal Strength:%></a></h1>

<h2><b id="contxt" name="content"><%%></b></h2>

<%+footer%>

5.在/luasrc/model/cbi/mymodule/gateway.lua中添加以下代码:

local fs = require "nixio.fs"

m = Map("test_file","Nic Rate" ,translate("Nic Rate")) -- cbi_file is the config file in /etc/config

s = m:section(TypedSection,"arguments","")

s.addremove=false

s.anonymous=true

o = s:option(ListValue,"collection","NicRate")

o:value("first item","10G")

o:value("second item","2.5G")

local apply = luci.http.formvalue("cbi.apply")

if apply then

io.popen("/etc/init.d/NicTestSH.sh start")

end

return m

6. 在openwrt源码/qsdk/package/base-files/files/etc/init.d/NisTestSH.sh添加以下代码:

#!/bin/sh etc/rc.common

START=50

run_mobi()

{

local enable

config_get_bool enable $1 enable

local collection

config_get collection $1 collection

if [ "$collection" == "first item" ]; then

ethtool -s eth1 speed 2500 duplex full

else

ethtool -s eth1 speed 10000 duplex full

fi

}

start()

{

config_load test_file

config_foreach run_mobi arguments

}



7. 执行Luci更新:

回退到openwrt源码目录,以此执行以下命令:

./scripts/feeds update luci

./scripts/feeds install -a -p luci

8.make menuconfig中勾选:

LuCI --->
	Collections --->
			<*> luci
			<*> luci-ssl
	Translations--->
			<*> Chinese(zh-cn)   //支持中文
			<*> English (en)     支持英文
LuCI --->
	Applications --->
	      <*> luci-app-myapplication.............. LuCI Support for Test 

Openwrt-Luci 开发介绍(三) - 天天要闻

Openwrt-Luci 开发介绍(三) - 天天要闻

9. 然后执行 make V=s 进行编译

10. 烧录固件,查看web界面

Openwrt-Luci 开发介绍(三) - 天天要闻

Openwrt-Luci 开发介绍(三) - 天天要闻

属于自己的第一个页面就完成了呢,是不是很激动

,接下来继续挖掘研究吧!

科技分类资讯推荐

引领科技豪华MPV新风尚 第二代腾势D9西安车展亮相 - 天天要闻

引领科技豪华MPV新风尚 第二代腾势D9西安车展亮相

兼具宜商气度与家用温情的科技豪华旗舰MPV,第二代腾势D9迎来西安地区正式亮相。新车依托全球新能源MPV冠军底蕴,以第二代刀片电池、双阀云辇-C、天神之眼5.0智驾等核心技术全面升级,兼顾商务体面与家庭舒适,为西北高端用户带来一站式全能出行解决方案。
采购禁入!科华数据材料造假被拒门外 - 天天要闻

采购禁入!科华数据材料造假被拒门外

本报(chinatimes.net.cn)记者胡雅文 北京报道这家赶上AI算力风口的公司,因投标材料造假,被相关采购方列入禁入名单两年,其此前提出的复议申请也被正式驳回。相关采购平台近日发布公告,明确驳回科华数据股份有限公司(下称“科华数据”,002335.SZ)此前提交的复议申请。早在一年前,科华数据已被认定在“信息通信枢纽...
快评乐道L80:15万元级买大五座,这波值得冲? - 天天要闻

快评乐道L80:15万元级买大五座,这波值得冲?

日前,乐道L80正式发布并开启预售,其整车购买预售价为24.58万元起,租电购买预售价则低至15.98万元起。面对大型SUV市场“细分再细分”之竞争趋势,这款乐道年度重磅新车都有哪些优势?又能否成为“大五座SUV革新之作”?下面,圈哥就带大家全方位感受。
成都直击凯威德:纯电全尺寸SUV的张扬与大气 - 天天要闻

成都直击凯威德:纯电全尺寸SUV的张扬与大气

4月22日,凯迪拉克以奥斯卡级盛典规格,将上海保利大剧院点亮为璀璨舞台,在品牌代言人倪妮与全场嘉宾的共同见证下,凯迪拉克全尺寸纯电公路旗舰——凯威德耀然上市。新车共推出长续航四驱Pro、高性能四驱Ultra两款配置,官方售价区间为46.88万-50.88万元。