I am trying to publish a message from a IoT Core which is a Raspberry Pi 4.
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)
Error:
OSError: /home/pi/greengrass/certs/root.ca.pem: No such file or directory
/greengrass/certs
shows that the file is there:
pi@raspberrypi:/greengrass/certs $ tree ./
./
|-- 22e7469561.cert.pem
|-- 22e7469561.private.key
|-- 22e7469561.public.key
|-- README
`-- root.ca.pem
I have already run the following command to download the root CA certificate to the /greengrass/certs
folder:
cd /greengrass/certs/
sudo wget -O root.ca.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
I also confirmed the root.ca.pem
file is not empty using:
cat root.ca.pem
Managed to fix it by changing the path to the files to:
myMQTTClient.configureCredentials("/greengrass/certs/root-ca.pem", "/greengrass/certs/22e7469561.private.key","/greengrass/certs/22e7469561.cert.pem")
But in doing so I have to run sudo to run the python script in order to access the certificates.