OpenWrt系统概况增加cpu温度显示
创始人
2024-06-03 12:28:54

注意:随着时间的流逝,其中的信息可能已经有所发展或是发生改变。侵删!


前言

星际宝盒这款路由器散热不好,经常过热。关闭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 Copyright 2008-2011 Jo-Philipp Wich 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;<%:CM520 Temperature%>-  


开始修改 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;<%:磁盘健康检测%>-                
<%:磁盘温度%>-
<%:磁盘通电时长 (h)%>-


参考:

给 openwrt/lede 安装温度监控程序 lm-sensors 并改造首页,添加CPU温度显示 - Allen Hua 的网络博客
https://hellodk.cn/post/372?replyTo=579
废权的博客 - 因上努力,果上随缘! - OpenWrt首页改造
https://blog.yjscloud.com/archives/129

相关内容

热门资讯

苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...