0

I am writing to you because I have the following problem: I have generated a code that allows controlling a 32x32 RGB led matrix through mqtt (AWS IoTCore) using a RPi Zero W with an Adafruit RGB Matrix Bonnet.

To manage the matrix, I generate a class that allows to have different viewing modes: scrolling image, static image, text, etc. This class is based in the python bindings.

On the other hand, the main code is responsible for managing the connection to the broker and for executing different actions based on the received mqtt messages.

When I instantiate the class that controls the screen before connecting to mqtt:

# Screen Class Instance
screen = Screen()
# MQTT CONNECTION
connflag = False
mqttc = paho.Client()
mqttc.on_connect = on_connect
mqttc.on_message = on_message
awshost = "data.iot.us-east-1.amazonaws.com"
awsport = 8883
clientId = "myThingName"
mqttc.tls_set(CREDENTIALS_PATH + "CA.pem", certfile=CREDENTIALS_PATH + "device_CA.pem.crt",
             keyfile=CREDENTIALS_PATH + "device_private.pem.key", cert_reqs=ssl.CERT_REQUIRED,
             tls_version=ssl.PROTOCOL_TLSv1_2,
             ciphers=None)
mqttc.connect(awshost, awsport, keepalive=60)
mqttc.loop_start()

The following error occurs: enter image description here

On the other hand, when I generate the connection to mqtt before instantiating the class that controls the screen, the code runs without problems.

# MQTT CONNECTION
connflag = False
mqttc = paho.Client()
mqttc.on_connect = on_connect
mqttc.on_message = on_message
awshost = "data.iot.us-east-1.amazonaws.com"
awsport = 8883
clientId = "myThingName"
mqttc.tls_set(CREDENTIALS_PATH + "CA.pem", certfile=CREDENTIALS_PATH + "device_CA.pem.crt",
             keyfile=CREDENTIALS_PATH + "device_private.pem.key", cert_reqs=ssl.CERT_REQUIRED,
             tls_version=ssl.PROTOCOL_TLSv1_2,
             ciphers=None)
mqttc.connect(awshost, awsport, keepalive=60)
mqttc.loop_start()
# Screen Class Instance
screen = Screen()

However, this second case is not the ideal, since in case of not connecting to the broker or the internet, the screen will not show anything, since the class that controls it has not been instantiated.

I have tried changing the permissions with chmod 777, but I have not managed to solve this problem. If anyone has had similar problems or has any idea of what it might be, I would appreciate it if you would comment.

regards

UPDATE Feb 19: Despite not having found the cause of the problem, I found a workaround that allows me to instantiate the screen before connecting to AWS. It is enough to instantiate the class that controls the screen between the mqttc.tls_set and mqttc.connect lines. In this way it is possible to "configure" the credentials without error and instantiate the screen before making the connection.

  • What's CREDENTIALS_PATH set to? Can your user read that path? – Dougie Feb 18 at 20:25
  • The CREDENTIALS_PATH is set to the path: /home/pi/.aws/. I checked if the user can find this path using os.path.isdir and os.path.isfile and It can find this path and the credentials files. I was able to find a workaround that I will describe above in the description of the question. – Jose Luis Feb 19 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.