我正在尝试从 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