AWS IoT Core and Shadow on WiPy
-
I am using the aws-pycom library to connect to AWS IoT wthi WiPy over MQTT. What I need is to send messages over MQTT to a topic (working) and create a shadow for the device so I can interact with it. (partialy working).
The problem I have is that once I connect to two MQTT Clients (pycomAwsMQTTClient & pycomAwsMQTTShadowClient) I get errors. My conclusion is that WiPy can't handle two MQTT connections at once. Is this right or have I go it wrong?
I would also like to read messages written in a AWS topic but I can't seem to figure that one either. Any suggestions?
Thanks
-
@dbada Sorry for the late reply. Yes for me the first problem was that I tried to make two MQTT connections one for sub/pub topics one for shadows. You need to first init the AWSIoTMQTTShadowClientand than access the MQTT client with
pycomAwsMQTTShadowClient.getMQTTConnection()
The next thing is to make sure that the certificate is Activeted. Go to AWS IoT Core console, your thing/security/certificates/Action/Activate
And then it works.
Code for setting up AWS
pycomAwsMQTTShadowClient = AWSIoTMQTTShadowClient(CLIENT_ID) pycomAwsMQTTShadowClient.configureEndpoint(AWS_HOST, AWS_PORT) pycomAwsMQTTShadowClient.configureCredentials(AWS_ROOT_CA, AWS_PRIVATE_KEY, AWS_CLIENT_CERT) pycomAwsMQTTShadowClient.configureConnectDisconnectTimeout(CONN_DISCONN_TIMEOUT) pycomAwsMQTTShadowClient.configureMQTTOperationTimeout(MQTT_OPER_TIMEOUT) pycomAwsMQTTClient = pycomAwsMQTTShadowClient.getMQTTConnection() pycomAwsMQTTClient.configureOfflinePublishQueueing(OFFLINE_QUEUE_SIZE) pycomAwsMQTTClient.configureDrainingFrequency(DRAINING_FREQ) pycomAwsMQTTClient.configureConnectDisconnectTimeout(CONN_DISCONN_TIMEOUT) pycomAwsMQTTClient.configureMQTTOperationTimeout(MQTT_OPER_TIMEOUT) pycomAwsMQTTClient.configureLastWill(LAST_WILL_TOPIC, LAST_WILL_MSG, 1) print("Trying to connect to AWS") try: while not pycomAwsMQTTClient.connect(): print("Connecting to AWS...") time.sleep(0.5) except Exception as e: print("Exception: Can't connect to AWS") print(e) print('AWS connection succeeded')
I am planning on writing a detailed Medium Article, I'll link it here if you have any more problems.
-
@milan-nikolic Did you manage to solve this issue? I am experiencing the same problem.
-
This post is deleted!
-
Update
I managed to connect to both the topic I want to post to and use IoT Shadows, now the only problem I have is that I can't read anything from device shadow or any other topic. Has anyone solved this?
-
@Gijs
Yes I did try to connect to AWS core over pybytes and it works, at least for sending messages to a topic. I didn't try the shadow feature (if it even exists over pybytes).
-
Hi,
Im not completely sure on this as I've never tried AWS, but I believe the library is from 2017 and not completely up to par with the latest firmware and AWS API. Did you try the AWS IoT feature through Pybytes (pybytes.pycom.io) and if that works for you?
-
@milan-nikolic said in AWS IoT Core and Shadow on WiPy:
MBEDTLS_ERR_NET_RECV_FAILED
According to Net Socket Documentation it is
Reading information from the socket failed
Which probably means that either AWS closed your connection or your WiFy is disconnected
-
@bitvijays In the project I am using threading but the error happens even when it is not used.
The error I get is:Socket receive error: [Errno -76] MBEDTLS_ERR_NET_RECV_FAILED
And it just writes it out a billion times.
When I use threading to send messages to topic messages are still going out even when error is repeatedly shown, and the shadow is also updated regardless of the error.For reading from topic I don't get any errors since I haven't found a way to do it.
-
This post is deleted!
-
What are the errors you are facing? Are you using threading?