正在寻找使用RPi.GPIO和Raspberry Pi 4的帮助
我有一个简单的Greengrass Lambda函数,它试图使用RPi.GPIO模块从电阻式土壤湿度传感器收集数据。我的Lambda函数依赖于Python3.7和RPi.GPIO模块的0.7.0版。我已经用一个简化的Python脚本验证了GPIO模块在Greengrass之外的设备上安装并正常工作
import RPi.GPIO as GPIO
import RPIO
import time
channel = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)
def callback(channel):
if GPIO.input(channel):
print("No water detected")
else:
print("Water detected")
GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)
GPIO.add_event_callback(channel, callback)
while True:
time.sleep(1)
Greenglass Lambda可通过IoT组中定义的本地资源访问本地/dev/gpiomem文件系统。我使用的是Classic(V1)
但是,当我尝试部署Lambda函数时,会出现以下错误:
-lambda_runtime.py:382,Failed to initialize Lambda runtime due to exception: This module can only be run on a Raspberry Pi!
我在我的RPi上安装了两个版本的Python(2.7.16和3.7.3,Greengrass运行时使用3.7),并验证了这两个版本都具有0.7.0版本的RPi.GPIO模块
我的Lambda函数显式导入模块
import logging
import platform
import sys
import RPi.GPIO as GPIO
import time
from threading import Timer
import greengrasssdk
是否有人遇到过此问题,您会推荐什么解决方案
我也有同样的问题。问题是greengrass用户无权访问gpio引脚
只需将ggc_用户添加到th gpio组。您可以通过编辑Raspberry Pi上的/etc/group来完成此操作:
在经历了完全相同的问题后,我一直在测试
我尝试的一件事是在Lambda配置中为Lambda(容器)提供对SYS的访问权限,在这一点上,我遇到了另一个与覆盖fs问题相关的错误
我发现在Greengrass 1.10.1(我运行的是1.10.0)中有一个覆盖fs问题的修复程序,因此我将Greengrass(使用OTA更新作业)更新为1.11.3,在完成GG更新后,一切又开始工作:-)
已重新测试并确认其确实需要容器的/sys访问权限
关于信息,在提出解决方案之前,我已经尝试了各种方法,包括执行通常的apt-get更新/升级,并确保RPi.GPIO是最新的,但这些方法都没有任何区别
相关问题 更多 >
编程相关推荐