Reputation: 67
I have this error when I try to connect to my thing in AWS
Traceback (most recent call last):
File "/home/pi/labs/p11/test.py", line 27, in <module>
my_rpi.connect()
File "/usr/local/lib/python2.7/dist-packages/AWSIoTPythonSDK/MQTTLib.py", line 403, in connect
return self._mqttCore.connect(keepAliveIntervalSecond)
File "/usr/local/lib/python2.7/dist-packages/AWSIoTPythonSDK/core/protocol/mqttCore.py", line 287, in connect
self._pahoClient.tls_set(self._cafile, self._cert, self._key, ssl.CERT_REQUIRED, ssl.PROTOCOL_SSLv23) # Throw exception...
File "/usr/local/lib/python2.7/dist-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 600, in tls_set
raise IOError(ca_certs+": "+err.strerror)
IOError: rootca.pem: No such file or directory
This is my code that I use to run
# Import SDK packages
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
from time import sleep
from gpiozero import MCP3008
adc = MCP3008(channel=0)
# Custom MQTT message callback
def customCallback(client, userdata, message):
print("Received a new message: ")
print(message.payload)
print("from topic: ")
print(message.topic)
print("‐‐‐‐‐‐‐‐‐‐‐‐‐‐\n\n")
host = "YourEndPoint.amazonaws.com"
rootCAPath = "rootca.pem"
certificatePath = "certificate.pem.crt"
privateKeyPath = "private.pem.key"
my_rpi = AWSIoTMQTTClient("basicPubSub")
my_rpi.configureEndpoint(host, 8883)
my_rpi.configureCredentials(rootCAPath, privateKeyPath, certificatePath)
my_rpi.configureOfflinePublishQueueing(-1) # Infinite offline Publish queueing
my_rpi.configureDrainingFrequency(2) # Draining: 2 Hz
my_rpi.configureConnectDisconnectTimeout(10) # 10 sec
my_rpi.configureMQTTOperationTimeout(5) # 5 sec
# Connect and subscribe to AWS IoT
my_rpi.connect()
my_rpi.subscribe("sensors/light", 1, customCallback)
sleep(2)
# Publish to the same topic in a loop forever
loopCount = 0
while True:
light = round(1024‐(adc.value*1024))
my_rpi.publish("sensors/light", str(light), 1)
sleep(5)
So my code is about retrieving light from my GPIO, send it to the MQTT broker(AWS) then send it to my Gmail.
I have ensured that paho-mqtt is installed, AWSIoTPythonSDK is installed. The 3 files, rootca.pem, certificate.pem.crt, private.pem.key are in the same folder as the python file above. Is there a reason that cause the error above?
Upvotes: 0
Views: 742
Reputation: 11
after .pem there should be a .crt or.key also that is usually hidden in your file directory so its hard to notice and write the full path.
Upvotes: 1