如何在Raspberry PI 4上运行AWS Greenggrass Core中的RPI.GPIO模块

2024-09-28 13:13:16 发布

您现在位置:Python中文网/ 问答频道 /正文

正在寻找使用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
   

是否有人遇到过此问题,您会推荐什么解决方案


Tags: 模块lambda函数import版本gpiotimeas
2条回答

我也有同样的问题。问题是greengrass用户无权访问gpio引脚

只需将ggc_用户添加到th gpio组。您可以通过编辑Raspberry Pi上的/etc/group来完成此操作:

gpio:x:997:pi,ggc_user

在经历了完全相同的问题后,我一直在测试

我尝试的一件事是在Lambda配置中为Lambda(容器)提供对SYS的访问权限,在这一点上,我遇到了另一个与覆盖fs问题相关的错误

我发现在Greengrass 1.10.1(我运行的是1.10.0)中有一个覆盖fs问题的修复程序,因此我将Greengrass(使用OTA更新作业)更新为1.11.3,在完成GG更新后,一切又开始工作:-)

It may not need the SYS access as I have yet to change that back and see if it was just the Greengrass update that was needed.

已重新测试并确认其确实需要容器的/sys访问权限

关于信息,在提出解决方案之前,我已经尝试了各种方法,包括执行通常的apt-get更新/升级,并确保RPi.GPIO是最新的,但这些方法都没有任何区别

相关问题 更多 >

    热门问题