注意:随着时间的流逝,其中的信息可能已经有所发展或是发生改变。侵删!
var code = “51305c2a-a023-424f-a5cb-7999ca44f09c”
前言
星际宝盒这款路由器散热不好,经常过热。关闭2.4G仅开5G后,系统概况中温度信息就不再显示了。但可以通过命令行查看,尝试通过简单配置,将温度显示在系统概况中。
提示:以下是本篇文章正文内容,下面案例可供参考
安装相关软件包
安装 lm-sensors、lm-sensors-detect、sed 、nano
opkg update
opkg install lm-sensors lm-sensors-detect sed
若报错 ,则更换opkg为清华源。之后应该就可以正常安装了:
root@CM520:~# opkg install lm-sensors lm-sensors-detect sed
Unknown package 'lm-sensors'.
Collected errors:
* opkg_install_cmd: Cannot install package
# 更改为清华源
root@CM520:~# sed -i 's_downloads.openwrt.org_mirrors.tuna.tsinghua.edu.cn/openwrt_' /etc/opkg/distfeeds.conf
安装完成测试:
root@CM520:~# sensors
ath10k_hwmon-isa-a000000
Adapter: ISA adapter
temp1: N/A
ath10k_hwmon-isa-a800000
Adapter: ISA adapter
temp1: +76.0°C
修改系统概况 index 文件
系统概况的 index.htm 文件位置。
root@CM520:~# cat /usr/lib/lua/luci/view/admin_status/index.htm
<%#
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
Licensed to the public under the Apache License 2.0.
-%>
<%
local fs = require "nixio.fs"
······
备份 index.htm 文件
root@CM520:~# cp /usr/lib/lua/luci/view/admin_status/index.htm /usr/lib/lua/luci/view/admin_status/index-original.htm
使用命令提取设备温度
# 查看当前温度
root@CM520:~# sensors
ath10k_hwmon-isa-a000000
Adapter: ISA adapter
temp1: N/A
ath10k_hwmon-isa-a800000
Adapter: ISA adapter
temp1: +75.0°C
# 提取温度的命令。根据设备不同 需要提取的关键字也不同,这里是 temp1。
root@CM520:~# sensors | grep temp1| awk -F ':' '{print $2}'
N/A
+75.0°C
ok 以上已经得到当前设备的温度了,下面将命令改造一下,方便写进系统概况的index文件中:
local c_temperature1 = luci.sys.exec("sensors | grep temp1| awk -F ':' '{print $2}'")
ctemp1 = c_temperature1,
if (e = document.getElementById('ctemp1'))
e.innerHTML = info.ctemp1;
<tr><td width="33%"><%:CM520 Temperature%></td><td id="ctemp1">-</td></tr>
开始修改 index 文件(别忘记行尾符号,例如:逗号):
>> local c_temperature1 = luci.sys.exec(“sensors | grep temp1| awk -F ‘:’ ‘{print $2}’”)
>> ctemp1 = c_temperature1,
>> if (e = document.getElementById(‘ctemp1’)) e.innerHTML = info.ctemp1;
>> <%:CM520 Temperature%>-
完成,验证一下:
其他(也可以通过 smartctl工具获取硬盘的相关数据)
local disk_health = luci.sys.exec("smartctl -H /dev/sda | grep assessment | awk -F ':' '{print $2}'")
local disk_temperature = luci.sys.exec("smartctl -A /dev/sda | grep 194 | awk -F '-' '{print $2}'")
local disk_hours = luci.sys.exec("smartctl -A /dev/sda | grep Hours | awk -F '-' '{print $2}'")
diskhe = disk_health,
disktemp = disk_temperature,
diskhours = disk_hours,
if (e = document.getElementById('diskhe'))
e.innerHTML = info.diskhe;
if (e = document.getElementById('disktemp'))
e.innerHTML = info.disktemp;
if (e = document.getElementById('diskhours'))
e.innerHTML = info.diskhours;
<tr><td width="33%"><%:磁盘健康检测%></td><td id="diskhe">-</td></tr>
<tr><td width="33%"><%:磁盘温度%></td><td id="disktemp">-</td></tr>
<tr><td width="33%"><%:磁盘通电时长 (h)%></td><td id="diskhours">-</td></tr>
参考:
给 openwrt/lede 安装温度监控程序 lm-sensors 并改造首页,添加CPU温度显示 - Allen Hua 的网络博客
https://hellodk.cn/post/372?replyTo=579
废权的博客 - 因上努力,果上随缘! - OpenWrt首页改造
https://blog.yjscloud.com/archives/129