Atom Matrix with FW 1.13.1 not connecting to AWS
-
EBADF means that the client on the atom is trying to send to a closed connection.
At one point I had to store the Public and private keys generated by amazon along with the cert on the client to get a connection.
Try setting Keep alive to 500.
Will need to see the full code to work out what's happening.
AWS is constantly changing so my guides are probably out of date and need updating. I hate AWS as it a Pain.
-
It is still not working... Due to the fact that I'm not receiving anything on AWS, I believe it is connected to the networking on the device.
I see a number of contradicting information and unclear guidance. Here the current approach and questions:
1/ Internet Mode vs. App Mode. Is MQTT/IOT supposed to work in both modes?
2/ How I'm supposed to configure networking on the new firmwares? I see the following options:
wifiCfg.autoConnect(lcdShow=False)
wifiCfg.reconnect()
wifiCfg.doConnect('', '')
wlan.connect('', '')
3/ Playing with different firmwares because I believe this is buggy. -
Ah I see the Issue now.
So in Internet mode the WIFI connection is already active because UIFLOW is using it to send and test programs where as in APP mode the WIFI connection is not activated because you haven't opened the connection.In App mode you must add the wifi configuration and setup blocks to the code for the Wireless connection to work.
Sorry, I have been battling a chest infection and so wasn't able to clearly see the solution. While I did write the crappy book on IOT found on amazon, things have changed and I am already writing an update while working on the other deep guides.
-
Your setup need to look like this:
-
Still have the problem. I rebuilt the whole program to make sure there are no "old" blocks in there. Don't even see a connection attempt on AWS (IoT Core with enabled debug logging)
ATOM Matrix
Firmware: 1.13.2Both in Internet and App mode
-- Code --
from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
import time
from IoTcloud.AWS import AWS
from libs.json_py import *
import unitrgb.set_screen([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
tvoc_0 = unit.get(unit.TVOC, unit.PORTA)CO2 = None
TVOC = None
H2 = None
Ethanol = NonewifiCfg.doConnect('Guest', 'xxx')
wifiCfg.autoConnect(lcdShow=False)
wait(5)
aws = AWS(things_name='CO2SENSOR', host='xxx.iot.eu-central-1.amazonaws.com', port=8883, keepalive=500, cert_file_path="/flash/res/certificate.pem.crt", private_key_path="/flash/res/private.pem.key")
aws.start()
while True:
CO2 = tvoc_0.eCO2
TVOC = tvoc_0.TVOC
H2 = tvoc_0.H2
Ethanol = tvoc_0.Ethanol
aws.publish(str('m5stack/bla'),str((py_2_json({'CO2':CO2,'TVOC':TVOC,'H2':H2,'Ethanol':Ethanol}))))
print('submitted to AWS')
wait(5)— Serial Log --
submitted to AWS
[10490] MQTTException -> [Errno 9] EBADF
reconnect start ...
reconnect finish ...
[14075] MQTTException -> [Errno 9] EBADF
reconnect start ...
reconnect finish ...
submitted to AWS
[17541] MQTTException -> [Errno 9] EBADF
reconnect start ...
reconnect finish ...
submitted to AWS
[20998] MQTTException -> [Errno 9] EBADF
reconnect start ...
reconnect finish ...
[24577] MQTTException -> [Errno 9] EBADF
reconnect start ...
reconnect finish ...
submitted to AWS -
Okay - testet the very same code with an MStickC. Runs very smooth without issues. Either there are bugs in the code of the Atom Matrix or the device has just too less resources to handle an external sensor along with an IoT connection.
-
Nice work keeping at it. there is one more thing I can think of which is basically a last thing to try.
Add
import gc
to the import code and then at the beginning of the loop add
gc.collect()
This forces garbage collection in micropython on each pass emptying the memory on each loop.
Look up Micropython Garbage collection function for more information on this.
unfortunately I can't get into my AWS account and so haven't been able to test but it could be that you have genuinely found an issue in the Atom firmware.
-
added it as directed above. Still weird behaviour of the Atom Matrix on FW 1.13.2.
Here is the log:
I print out "submitted to aws" after the publish block in the loop.APIKEY: xxx
submitted to aws
[17797] MQTTException -> 128
reconnect start ...
reconnect finish ...
submitted to aws
submitted to aws
submitted to aws
submitted to aws
submitted to aws -
okay some more learnings...
All S3 devices are supported by UIFlow 2.0 only. And UIFlow 2.0 is not yet supporting AWS IoT unless I missed something.
M5StickC Plus is working as a charm. Like M5StickC. I guess I stick with those.My summary as of Feb 2024 and Firmware 1.13.2 and UIFlow 2.0 (Alpha 29):
Forget all new devices that are supported by UIFlow 2.0 only (e.g. *S3) and the small ATOMs if you wanna do AWS IoT stuff. Hope you find this before you bought too many devices...
-
and for completness here my working setup with M5StickC / Plus
Will also followup with AWS details.
-
@chr1g1 said in Atom Matrix with FW 1.13.1 not connecting to AWS:
added it as directed above. Still weird behaviour of the Atom Matrix on FW 1.13.2.
Here is the log:
I print out "submitted to aws" after the publish block in the loop.APIKEY: xxx
submitted to aws
[17797] MQTTException -> 128
reconnect start ...
reconnect finish ...
submitted to aws
submitted to aws
submitted to aws
submitted to aws
submitted to awsWell there is an improvement as you are no longer getting the
[24577] MQTTException -> [Errno 9] EBADF
Which means the Atom is now workingError 128 means that it tried to subscribe to the AWS topic before the connection was made.
If you make a subscribe and a call, according to your log it should be present.add a 5 second delay after the AWS start.