Skip to content

Commit

Permalink
temperature display
Browse files Browse the repository at this point in the history
  • Loading branch information
thun888 committed Aug 25, 2023
1 parent 2ff08be commit f21377f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 42 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

![router_index](https://github.com/thun888/mirouter-ui/assets/63234268/1ddce346-7abd-4816-bc55-fe55d3dc70c9)

#### 温度显示(仅支持部分设备)

![Snipaste_2023-08-25_13-33-54](https://github.com/Mirouterui/mirouter-ui/assets/63234268/0926dafd-a63e-4ee6-bc61-f381c1dfc199)


### 部署
Expand All @@ -48,6 +51,7 @@
#### 获取key和iv

> 自动获取:[Mirouterui/MiKVIVator](https://github.com/Mirouterui/MiKVIVator)
> ps:我在3个路由器上发现了一样的数值,已添加为默认值,如果无法登录再尝试更改吧
打开路由器登录页面,右键,点击`查看页面源代码`,按下`CTRL + F`组合键打开搜索框,搜索`key:`,不出意外你能看见以下结果

Expand All @@ -66,8 +70,8 @@
| 配置名 | 默认值 | 解释 |
| ---------- | ------------ | --------------------------------------- |
| password | | 路由器管理后台密码 |
| key | | 路由器管理后台key |
| iv | | 路由器管理后台iv |
| key | a2ffa5c9be07488bbb04a3a47d3c5f6a | 路由器管理后台key |
| iv | 64175472480004614961023454661220 | 路由器管理后台iv |
| ip | 192.168.31.1 | 路由器IP |
| tiny | false | 启用后,不再下载静态文件,需搭配[在线前端](http://mrui.hzchu.top:8880/)使用|
| routerunit | false | 启用后,程序通过`gopsutil`库获取CPU占用 |
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION="1.1.0"
read -p "版本号: " VERSION
echo "Building MirouterUI $VERSION..."
echo "Deleting old build..."
rm mirouterui_win_amd64.exe
Expand Down
6 changes: 3 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"password": "your_password",
"key": "your_key",
"iv": "your_iv",
"password": "",
"key": "a2ffa5c9be07488bbb04a3a47d3c5f6a",
"iv": "64175472480004614961023454661220",
"ip": "192.168.31.1",
"tiny": false,
"routerunit": false,
Expand Down
Binary file added main.exe
Binary file not shown.
78 changes: 42 additions & 36 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var (
hardware string
tiny bool
routerunit bool
cpu_cmd *exec.Cmd
w24g_cmd *exec.Cmd
w5g_cmd *exec.Cmd
)

type Config struct {
Expand Down Expand Up @@ -84,6 +87,7 @@ func init() {
debug = config.Debug
port = config.Port
tiny = config.Tiny
routerunit = config.Routerunit
// fmt.Println(password)
// fmt.Println(key)
// fmt.Println(iv)
Expand Down Expand Up @@ -287,54 +291,57 @@ func debugPrint(msg string) {
}

// 红米AX6专用
func getCPUTemperature(c echo.Context) error {
cmd := exec.Command("cat", "/sys/class/thermal/thermal_zone0/temp")
out, err := cmd.Output()

if err != nil || routerunit == false {
func getTemperature(c echo.Context) error {
if routerunit == false {
return c.JSON(http.StatusOK, map[string]interface{}{
"code": 1100,
"temperature": -1,
"code": 1100,
"msg": "未开启routerunit模式",
})
}
if hardware == "RA69" {
cpu_cmd = exec.Command("cat", "/sys/class/thermal/thermal_zone0/temp")
w24g_cmd = exec.Command("cat", "/sys/class/ieee80211/phy0/device/net/wifi1/thermal/temp")
w5g_cmd = exec.Command("cat", "/sys/class/ieee80211/phy0/device/net/wifi0/thermal/temp")

return c.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
"temperature": string(out),
})
}
func get24gWifiTemperature(c echo.Context) error {
cmd := exec.Command("cat", "/sys/class/ieee80211/phy0/device/net/wifi1/thermal/temp")
out, err := cmd.Output()

if err != nil || routerunit == false {
} else {
return c.JSON(http.StatusOK, map[string]interface{}{
"code": 1100,
"temperature": -1,
"code": 1101,
"msg": "设备不支持",
})
}
cpu_out, err1 := cpu_cmd.Output()
w24g_out, err2 := w24g_cmd.Output()
w5g_out, err3 := w5g_cmd.Output()

return c.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
"temperature": string(out),
})
}
func get5gWifiTemperature(c echo.Context) error {
cmd := exec.Command("cat", "/sys/class/ieee80211/phy0/device/net/wifi0/thermal/temp")
out, err := cmd.Output()

if err != nil || routerunit == false {
if err1 != nil || err2 != nil || err3 != nil {
return c.JSON(http.StatusOK, map[string]interface{}{
"code": 1100,
"temperature": -1,
"code": 1100,
"msg": "获取温度失败,报错信息为" + err1.Error() + err2.Error() + err3.Error(),
})
}

return c.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
"temperature": string(out),
"code": 0,
"cpu_temperature": string(cpu_out),
"w24g_temperature": string(w24g_out),
"w5g_temperature": string(w5g_out),
})
}
func getconfig(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
"key": key,
"iv": iv,
"ip": ip,
"tiny": tiny,
"port": port,
"routerunit": routerunit,
"debug": debug,
// "token": token,
"hardware": hardware,
})
}

func main() {
e := echo.New()
if debug == true {
Expand Down Expand Up @@ -376,9 +383,8 @@ func main() {
})
}
})
e.GET("/api/cputemperature", getCPUTemperature)
e.GET("/api/24gWifiTemperature", get24gWifiTemperature)
e.GET("/api/5gWifiTemperature", get5gWifiTemperature)
e.GET("/_api/gettemperature", getTemperature)
e.GET("/_api/getconfig", getconfig)

// var contentHandler = echo.WrapHandler(http.FileServer(http.FS(static)))
// var contentRewrite = middleware.Rewrite(map[string]string{"/*": "/static/$1"})
Expand Down

0 comments on commit f21377f

Please sign in to comment.