snip3rnick / PyHardwareMonitor

Thin Python layer for LibreHardwareMonitor
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

How to use ? #1

Closed LRF520 closed 2 years ago

LRF520 commented 2 years ago

How to use ?

snip3rnick commented 2 years ago

Hi, I just threw this together for using it in a project some time in the future and did not expect anyone to use this so soon. When I find the time in the coming days I will add a proper README with references and example use. For now I can refer you to the testing example which is the equivalent replica of the C# example in LibreHardwareMonitor repository.

But I will definitely get back to you once the installation and usage instructions are added ;).

Cheers

LRF520 commented 2 years ago

嗨, 我只是把它放在一起,以便将来在某个项目中使用它,没想到有人这么快就使用它。 当我在接下来的几天里找到时间时,我将添加一个适当的 README,其中包含参考和示例使用。 现在我可以参考测试示例,它是LibreHardwareMonitor 存储库中C#示例的等效副本。

但是,一旦添加了安装和使用说明,我一定会回复您;)。

干杯

Librehardware monitor provides a way to obtain JSON data. If pyhardwardware monitor can also provide such JSON data or dict data in the future, it is very good because it is convenient to use. It does not need to run the GUI interface of librehardware monitor because it consumes too much CPU.

I have studied pyhardwaremonitor for two days. If you can continue to do it, I think this scheme is very good.

image

snip3rnick commented 2 years ago

It would not be very difficult to write a utility for json serialization for the LibreHardwareMonitor objects. I can certainly look into that this coming weekend. The server made with pythons standard library may look as simple as this

from wsgiref import simple_server

def app(environ, respond):
    if environ['PATH_INFO'].lower() == "/data.json":
        json_str = '{}'  # TODO: insert PyHardwareMonitor serialization here
        respond('200 OK', [('Content-Type', 'application/json')])
        return [json_str.encode()]
    else:
        respond('404 Not Found', [('Content-Type', 'application/json')])
        return [b'not found']

httpd = simple_server.make_server('', 8085, app)
print(f"Serving on port {httpd.server_port}, press 'ctrl + C' to stop")
try:
    httpd.serve_forever()
except KeyboardInterrupt:
    httpd.server_close()
snip3rnick commented 2 years ago

I have updated some files and added a more useful README which should help with using this package. An example script for a webserver based sensor data provider will be added shortly.

Cheers

snip3rnick commented 2 years ago

The WSGI example sensor provider is now uploaded.
This script runs a background timer to update the sensor values and sends the entire data as JSON string when accessing localhost:8085/data.json.

Remember that LibreHardwareMonitor requires admin privileges for most sensors to properly readout values.

NOTE: Fields in the JSON are currently the names of the .NET object members and not generalized like LibreHardwareMonitor does.

LRF520 commented 2 years ago

WSGI 示例传感器提供程序现已上传。此脚本运行后台计时器以更新传感器值,并在访问localhost:8085/data.json 时将整个数据作为 JSON 字符串发送。

请记住,LibreHardwareMonitor 需要管理员权限才能让大多数传感器正确读取值。

注意:JSON 中的字段当前是 .NET 对象成员的名称,不像 LibreHardwareMonitor 那样通用。

Still unavailable

image

snip3rnick commented 2 years ago

comment redundant to issue #2