Code Monkey home page Code Monkey logo

Comments (7)

imshixin avatar imshixin commented on July 22, 2024

yuy_22-07-12_19 15
把这里注释改掉,放if上面去,再运行一下
yuy_22-07-12_19 20
然后对照自己电脑找找需要的参数把上面的self.observe_types 改改
yuy_22-07-12_19 17_0
大概就可以了,我的是AMD的CPU,所以可能会不一样

from esp32c3_observer.

CodeChenL avatar CodeChenL commented on July 22, 2024

谢谢,这个库貌似没有12代intel的温度传感器,我把cpu温度改成gpu功耗了,但是跑起来我发现数据根本对不上,如图:

IMG_20220724_195409
IMG_20220724_195407
这是我的上位机代码:

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.

imshixin avatar imshixin commented on July 22, 2024

抱歉,这是老版的程序,适用lvgl的程序小修改一下就好

getData中第二个for下面那行改成这样

data.append(str(int(self.computer.Hardware[hardware].Sensors[sensor].Value))+" ")

from esp32c3_observer.

CodeChenL avatar CodeChenL commented on July 22, 2024

抱歉,这是老版的程序,适用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.

CodeChenL avatar CodeChenL commented on July 22, 2024

抱歉,这是老版的程序,适用lvgl的程序小修改一下就好

getData中第二个for下面那行改成这样

data.append(str(int(self.computer.Hardware[hardware].Sensors[sensor].Value))+" ")

大佬,我还想请教一个问题,下位机的有个main文件有什么区别?

from esp32c3_observer.

imshixin avatar imshixin commented on July 22, 2024

from esp32c3_observer.

CodeChenL avatar CodeChenL commented on July 22, 2024

懂了,谢谢。

from esp32c3_observer.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.