0

我正在尝试从 Raspberry Pi 4 的 IoT Core 发布消息。

import time
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient

def hello(self,params,packet):
    print("Received Message from AWS IoT Core")
    print(f"Topic: {packet.topic}")
    print(f"Payload: {packet.payload}")

myMQTTClient = AWSIoTMQTTClient("YudhieshID")
// Did not include endpoint here for security reasons
myMQTTClient.configureEndpoint("",8883)

myMQTTClient.configureCredentials("/home/pi/greengrass/certs/root.ca.pem", "/home/pi/greengrass/certs/22e7469561.private.key","/home/pi/greengrass/certs/22e7469561.cert.pem")
myMQTTClient.configureOfflinePublishQueueing(-1)
myMQTTClient.configureDrainingFrequency(2)
myMQTTClient.configureConnectDisconnetTimeout(10)
myMQTTClient.configureMQTTOperationTimeout(5)
print("INtitating IoT Core Topic...")
myMQTTClient.connect()
myMQTTClient.subscribe("home/helloworld",1,hello)

while True:
    time.sleep(5)

错误:

OSError: /home/pi/greengrass/certs/root.ca.pem: No such file or directory

/greengrass/certs显示该文件在那里:

pi@raspberrypi:/greengrass/certs $ tree ./
./
|-- 22e7469561.cert.pem
|-- 22e7469561.private.key
|-- 22e7469561.public.key
|-- README
`-- root.ca.pem

我已经运行以下命令将根 CA 证书下载到/greengrass/certs文件夹:

cd /greengrass/certs/
sudo wget -O root.ca.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem

我还root.ca.pem使用以下方法确认文件不为空:

cat root.ca.pem
4

1 回答 1

0

设法通过将文件的路径更改为来修复它:

myMQTTClient.configureCredentials("/greengrass/certs/root-ca.pem", "/greengrass/certs/22e7469561.private.key","/greengrass/certs/22e7469561.cert.pem")

但在这样做时,我必须运行 sudo 来运行 python 脚本才能访问证书。

于 2020-12-01T17:41:47.847 回答