(Adafruit_Python_DHT - Raspberry Pi) 在 get_platform RuntimeError: Unknown platform [英] (Adafruit_Python_DHT - Raspberry Pi) in get_platform RuntimeError: Unknown platform
问题描述
我有一台与 DHT22 传感器相连的 Raspberry Pi 4,我想从我的传感器读取数据.
I have a Raspberry Pi 4 connected with a DHT22 sensor, and I want to read data from my sensor.
所以我安装了库 Adafruit_DHT
sudo pip3 install Adafruit_DHT
然后,我导航到目录 Adafruit_Python_DHT/examples/
,然后,
then, I navigate to the directory Adafruit_Python_DHT/examples/
, and then,
因为我有一个 DHT22 传感器连接到 GPIO pi n° 4,
since I have a DHT22 sensor connected to GPIO pi n° 4,
我跑
python AdafruitDHT.py 22 4
我明白了
(lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/examples# python AdafruitDHT.py 2302 4
Traceback (most recent call last):
File "AdafruitDHT.py", line 41, in <module>
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 63, in get_platform
raise RuntimeError('Unknown platform.')
RuntimeError: Unknown platform.
(lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/examples# python AdafruitDHT.py 22 4
Traceback (most recent call last):
File "AdafruitDHT.py", line 41, in <module>
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 63, in get_platform
raise RuntimeError('Unknown platform.')
RuntimeError: Unknown platform.
(lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/examples#
由于回溯表明
'未知平台.'
我对Adafruit_Python_DHT库的github仓库做了一点研究,发现脚本Adafruit_Python_DHT/Adafruit_DHT/common.py
.
在这里我看到有一个 If/elif 结构 def get_platform()
旨在识别调用库的设备,但仅对 RPi 1、2 和 3 进行赋值,而 RPi缺少 4 个.
所以我敢打赌这就是错误 unknown platform
发生的原因.
I did a little research on the github repository of Adafruit_Python_DHT library, and I found the script Adafruit_Python_DHT/Adafruit_DHT/common.py
.
Here I see there is an If/elif structure def get_platform()
that aims to identify the device calling the library, but there is value assignment only for RPi 1, 2 and 3, while RPi 4 is missing.
So I bet this is the reason why the error unknown platform
occurs.
我浏览了库源代码并找到了目录 Adafruit_Python_DHT/Adafruit_DHT/
,其中最后一次提交显示包含 Raspberry Pi 4".
这是一个模块 platform_detect.py
似乎旨在以某种方式升级"库以识别 Raspberry Pi 4.
I navigated the library source code and I found out the directory Adafruit_Python_DHT/Adafruit_DHT/
, in which the last commit says "included Raspberry Pi 4".
Here is a module platform_detect.py
that seems to be designed to somehow "upgrade" the library in order to recognize Raspberry Pi 4.
所以我尝试升级"我的图书馆这样做:
So I tryed to "upgrade" my library by doing this:
在(lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/Adafruit_DHT#
,
我跑
platform_detect.py
而且我没有从提示中得到任何输出,所以我想一切都很顺利.
And I don't get any output from the prompt, so I guess everything has gone right.
然后我导航到目录 Adafruit_Python_DHT/examples/
并再次运行
Then I navigate to the directory Adafruit_Python_DHT/examples/
and run again
python AdafruitDHT.py 22 4
但我仍然遇到同样的错误.
but I still get the same error.
那么如何使用 Adafruit_Python_DHT 库从连接到 GPIO pi n° 4 的 DHT22 传感器获取数据?
So how can I get data from a DHT22 sensor connected to GPIO pi n° 4 by using Adafruit_Python_DHT library?
推荐答案
SOLVED:
这不是一个干净的方法,但它解决了我的问题.
This isn't a clean method, but it solved my problem.
通过使用 Filezilla,我连接到了我的 Raspberry Pi 4,我导航到 Adafruit_Python_DHT/Adafruit_DHT/
并下载了 platform_detect.py
和 common.py代码>在我的本地电脑上.
By using Filezilla, I connected to my Raspberry Pi 4, I navigated to Adafruit_Python_DHT/Adafruit_DHT/
and downloaded platform_detect.py
and common.py
on my local pc.
然后我用Notepad++编辑这两个文件如下:
Then I edited these two files with Notepad++ as follows:
在第 112-144 行我替换了
At line 112-144 I substituted
else:
# Something else, not a pi.
return None
与:
else:
# Something else, like PI 4 MODEL B
# my personal changes to the code
return 3
在第 62-63 行我替换了:
at lines 62-63 I substituted:
else:
raise RuntimeError('Unknown platform.')
与:
else:
#raise RuntimeError('Unknown platform.')
"""Use Pi 2 driver even though running on Pi 4"""
#my personal changes to the code, do it only if you are using a RPi 2, 3 or 4.
from . import Raspberry_Pi_2
return Raspberry_Pi_2
然后我保存了这两个文件并将它们上传到我的 RPi4 上的同一目录中,从而重写了旧文件.
Then I saved the two files and uploaded them on the same directory on my RPi4, thus rewriting the older ones.
然后,在我的命令提示符下,我运行
Then, with my command prompt, I run
sudo su
然后我打开虚拟环境并导航到/var/www/lab_app/Adafruit_Python_DHT
,我在这里运行:
then I turn up the virtual environment and navigate to
/var/www/lab_app/Adafruit_Python_DHT
, and here I run:
python setup.py install
现在安装库时没有我的提示显示任何平台检测错误.
And now the library gets installed without my prompt showing any error of platform detecting.
最后我导航到 /var/www/lab_app/Adafruit_Python_DHT/examples
并运行:
In the end I navigate to /var/www/lab_app/Adafruit_Python_DHT/examples
and run:
python AdafruitDHT.py 22 4
图书馆工作,返回我的传感器跟踪的值
And the library works, returning me the values tracked by my sensor
温度=22.3* 湿度=54.1%
Temp=22.3* Humidity=54.1%
这篇关于(Adafruit_Python_DHT - Raspberry Pi) 在 get_platform RuntimeError: Unknown platform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!