arduino/arduino-iot-cloud-py

ucloud.py references asynio which is not available on a MCU running Micropython. RP2040NANO

anglerfish27 opened this issue · 5 comments

Per the Arduino documentation and example I found that on the RP2040NANO will fail immediately to try to connect to the IoT cloud per the example to connect given on the webpage: https://docs.arduino.cc/arduino-cloud/getting-started/iot-cloud-micropython

it immediately fails saying it cannot find the module asyncio, which does not exist on the MicroPython image provided by Arduino or Micropython.org.

There is an uasyncio module loaded with Micropython.

I started messing with the ucloud.py file and ended up replacing all of the instances of asyncio with uasyncio. Now I'm able to at least partially connect. Something is still wrong..the code Arduino provides for IoT cloud connections does not work in MP at least on the RP2040NANO.

After hacking the ucloud.py file, this is as far as I get now, the IDE does not error it just sits there running my device is offline in the IoT cloud, it shows online for a very short period of time before the last error message is printed. If this is user error please let me know otherwise this is a big failure on Arduino. They state "full support for MP" yet they are including critical connection files for IoT that reference a module that doesn't exist in MP. Who know what else is wrong too..

sample out after hacking so it could at least not stop immediately before any code rules complaining that asyncio does not exist

MPY: soft reboot
19:55:37.000 WiFi Connected ('192.168.1.83', '255.255.255.0', '192.168.1.1', '192.168.1.1')
23:55:46.000 RTC time set from NTP.
23:55:46.000 task: ledSwitch created.
23:55:46.000 task: conn_task created.
23:55:46.000 Connecting to Arduino IoT cloud...
23:55:57.000 task: discovery created. <-----At this point the device shows online in the cloud
23:55:57.000 task: mqtt_task created.
23:55:57.000 Subscribe: b'/a/d/MYSECRET KEY/e/i'.
23:55:59.000 task: discovery complete.
23:55:59.000 task: conn_task raised exception: can't gather. <-----Now the IDE just sits there and I'm disconnected from the cloud and I have no idea how to hack this or what's going on.

Firmware has been updated to 1.5 for the WiFi chip.
All instructions scattered about on your site have been done.
used command line on my mac to download the IoT files to the NANO and the command that gives you the serial # of the MCU
I have the agent running in the background.
created on things in the cloud before even importing the device 2040NANO.
device completes and is added to the cloud using the secrets.py I created per the webpage.
it connects but as you can from the REPL output it is extremely short lived.
I even tried replacing the files that were loaded by the command line by manually importing the same files from your github page here to ensure I had the latest files. Same thing with asyncio.

How is this going to be fixed?

Take an RP2040NANO and install MP following the instructions and try and connect to your cloud, I bet you hit the asyncio issue right off the bat.

Please help. I feel this was never tested on the rp2040NAN0.

I tried first connecting using the ino sketch method and that worked perfectly I could control the onboard led from the cloud or even my phone. Switching to MicroPython results in total fail.

Hi, please revert all changes and just use the latest micropython nightly build + the latest iot client (0.0.9) and it will work just fine (using basic authentication username/password), I just tested it and can confirm that works on RP2040. The nightly builds can be found here:
https://micropython.org/download/ARDUINO_NANO_RP2040_CONNECT/

I will try to answer some of your questions:

There is an uasyncio module loaded with Micropython.

All modules starting with a u prefix (eg uasyncio) were renamed recently in micropython upstream, and the prefix was removed, it should have been possible to import a module using both names (uasyncio or asyncio) for backwards compatibility, at least for a while before it stops working, but it seems that's not the case (at least not the case with that particular stable release or the rp2 port).

23:55:59.000 task: conn_task raised exception: can't gather. <-----Now the IDE just sits there and I'm disconnected from the cloud and I have no idea how to hack this or what's going on.

This happens when a task fails immediately before the code gets a chance to await on it. It's hard to print a useful message in this case when running on micropython, it's just one of the implementation differences between CPython and MicroPython.

NOTE: The Nano-RP2040 is not officially mentioned in the docs because it may have an issue when connecting using key/cert, it should still work fine with the basic authentication (username/password), just something to keep in mind if you use it.

Thank you I will give this a try and see if it works. If so awesome and we close down this ticket.

Is the NANO ESP32-S3 compatible with Micropython to connect to the cloud. I noticed it had the async modules frozen in the release. After using the test code on the website and loading MP on it its blazed through and connected but then I noticed it created an infinite amount of copies of the /lib/arduino_iot_cloud (or whatever the name is I forget)..meaning the directory structure looked like
/lib/arduino_iot_cloud/arduino_iot_cloud /arduino_iot_cloud and so on. It corrupted the flash and I had to figure how to reformat the flash using the esptool which is something I'm not familiar with (fairly new to the ESPS3). I finally got it erased because manual attempts using REPL failed with access denied and it was not deletable from any IDE it would instantly crash the connection when I double clicked the top root folder. Thank goodness the flash erase works. Now I'm too scared to try again and have the same problem. It flew through and connected perfectly and the IoT Cloud showed it connected(green).

Anywho I'm going to stop tinkering on the ESP for now and go back to the RP2040NANO and test out your steps. "fingers crossed!"

Good news! Worked great, I deleted the old files and had them auto import using my and the 2040's Serial#. I found that when I flashed the daily build of MP that it did not wipe everything off my flash. So I had the old files still there. So I just got rid of them and downloaded per the instructions on your website using mpremote on my Mac. I went and created a simple dashboard with a slider switch and LED and ran the sample code and it works great I can control the onboard LED perfectly via cloud and also I tried from my phone and it worked too.

Thank you so much for your help, I cant believe all it required was using the nightly build of MP vs the stable release. I'm glad its fixed and I do hope you update your documentation on your website accordingly asap with respect. For example the sample code creates an object "LEDB" when controls the blue light on the 2040. However your Pinout document doesn't indicate this at all. I stumbled across once somewhere on your site that had a more "detailed" pinout which showed the I2C ports but I didn't save it at the time and I can find it again. Your instructions to load micropython vary on the webpage you are on, one says get the latest release from MP,. another page says get the nightly build. In my humble opinion you whoever handles documentation needs to clean it up and make sure its accurate. A separate link for each board with what it can and cannot do in MP should be clearly outlined. I messed around for hours yesterday trying to generate an API key in hopes that would fix it. I got a very common error that was submitted as a bug and it said it was fixed and merged. I ran that code and got the same error. This stuff should be clearly called out instead of banging your head trying to figure it out. That's just my opinion.

Again thank you so much for the fix I really appreciate it. I would love to hear back about the ESP32S3 and if can connect to the cloud with MP (I know it can as I did it but the resulting fallout as I explained was bizarre..). I hope that will be fined tuned and updated properly on your website. Too much stuff is mixed together. Again thank you!

Repectfully,
Anglerfish27

reopened by accident, apologies

You're welcome, and yes I asked for the documentation to be updated to mention the RP2040, but you may want to report those other documentation and API issues on the Arduino forums.

I would love to hear back about the ESP32S3

The Nano ESP32 is supported and can connect to the cloud, and the firmware includes all of the needed modules just like the RP2040, Portenta etc..