Comments (7)
把这里注释改掉,放if上面去,再运行一下
然后对照自己电脑找找需要的参数把上面的self.observe_types 改改
大概就可以了,我的是AMD的CPU,所以可能会不一样
from esp32c3_observer.
谢谢,这个库貌似没有12代intel的温度传感器,我把cpu温度改成gpu功耗了,但是跑起来我发现数据根本对不上,如图:
import ctypes
import sys
import clr
import time
from pathlib import Path
import socket
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
class Observer:
def __init__(self) -> None:
clr.AddReference(
str(Path(__file__).parent.absolute()/'LibreHardwareMonitorLib.dll'))
from LibreHardwareMonitor.Hardware import Computer
self.computer = Computer()
self.computer.IsCpuEnabled = True
self.computer.IsGpuEnabled = True
self.computer.Open()
self.observe_types = (
('cpu load', 'CPU Total', 'load'),
('cpu temp', 'GPU Package', 'power'),
('gpu load', 'GPU Core', 'load'),
('gpu temp', 'GPU Core', 'temperature'),
)
""" self.observe_types = (
(
'cpu占用',
'cpu温度',
'gpu占用',
'gpu温度',
),
(
'CPU Total',
'Core (Tctl/Tdie)',
'GPU Core',
'GPU Core',
),
('load', 'temperature', 'load', 'temperature'),
) """
self.sensor_index = [[_[0]] for _ in self.observe_types]
for hardware in range(0, len(self.computer.Hardware)):
for sensor in range(0, len(self.computer.Hardware[hardware].Sensors)):
match_identifier = [
index for index, (title, _name, _id) in enumerate(self.observe_types)
if _name in str(self.computer.Hardware[hardware].Sensors[sensor].Name)
and _id in str(self.computer.Hardware[hardware].Sensors[sensor].Identifier)
]
print(self.computer.Hardware[hardware].Sensors[sensor].Name,
self.computer.Hardware[hardware].Sensors[sensor].Identifier,
self.computer.Hardware[hardware].Sensors[sensor].Value)
if len(match_identifier) > 0:
self.sensor_index[match_identifier[0]].extend(
[hardware, sensor])
def getData(self):
# 更新硬件信息
# print(self.sensor_index)
for h in set([_[1] for _ in self.sensor_index]):
self.computer.Hardware[h].Update()
data = ''
for title, hardware, sensor in self.sensor_index:
data += f'{title} : {str(self.computer.Hardware[hardware].Sensors[sensor].Value)}{"%" if "load" in title else "℃"}\n'
# print(title, str(self.computer.Hardware[hardware].Sensors[sensor].Value))
return data
def main():
ob = Observer()
addr = '192.168.31.69'
port = 34567
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
try:
print('尝试连接 ', f'{addr}:{port}', end='\r')
soc.connect((addr, port))
print('连接成功')
while True:
print(ob.getData())
soc.send((ob.getData()+"\0").encode('utf-8'))
time.sleep(1)
except ConnectionError as e:
print(e.strerror)
print('连接关闭')
soc.close()
time.sleep(1)
if __name__ == '__main__':
main()
from esp32c3_observer.
抱歉,这是老版的程序,适用lvgl的程序小修改一下就好
在getData
中第二个for下面那行改成这样
data.append(str(int(self.computer.Hardware[hardware].Sensors[sensor].Value))+" ")
from esp32c3_observer.
抱歉,这是老版的程序,适用lvgl的程序小修改一下就好
在
getData
中第二个for下面那行改成这样
data.append(str(int(self.computer.Hardware[hardware].Sensors[sensor].Value))+" ")
可以了!,不过要改成data+=(str(int(self.computer.Hardware[hardware].Sensors[sensor].Value))+" ")
,不然报错字符串对象没有append
方法
from esp32c3_observer.
抱歉,这是老版的程序,适用lvgl的程序小修改一下就好
在
getData
中第二个for下面那行改成这样
data.append(str(int(self.computer.Hardware[hardware].Sensors[sensor].Value))+" ")
大佬,我还想请教一个问题,下位机的有个main文件有什么区别?
from esp32c3_observer.
from esp32c3_observer.
懂了,谢谢。
from esp32c3_observer.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp32c3_observer.