MQTT with an Arduino Nano RP2040 Connect #18911
Replies: 9 comments 18 replies
-
|
My arduino rp2040 connect board was still on my desk from trying the network sockets issue you had a couple of days ago, but sadly this time I can only confirm a problem. A simple test snippet for the mqttsimple module ran OK on the rpi picoW but failed on the arduino rp2040. For me it failed on self.sock.connect(addr) in the connect function in mqttsimple. I put a try / except around this line: and got "An error occurred: no available NIC" Maybe someone will understand whats going wrong with the arduino rp2040 network/wifi module, but for me this board is back in the useless drawer again :( |
Beta Was this translation helpful? Give feedback.
-
|
Well I just posted in too much haste! I had put an auto connect to wifi in the rpi pico and forgot about it in the arduino rp2040. Well the arduino rp2040 are back in play again :) |
Beta Was this translation helpful? Give feedback.
-
|
Very strange. To check I copied the code from my post and saved it to my nano with a new name and it worked OK. I normally use the @peterhinch mqtt_as module for my mqtt client and I just checked to see if that works on the nano. A slight hitch was that Peter's code gets the platform which is 'rp2' for both the pico and nano and it then performs some nano incompatable tweaks at points in the code. I found the easy way to overcome this was to simply alter the line of code (about line 30) to override the platform to be 'nano' e.g. |
Beta Was this translation helpful? Give feedback.
-
|
@peterhinch The tweak I did to make mqtt_as work with the nano was simply to change the setting of the variable 'platform' from 'rp2' so that the RP2 = platform == "rp2" ends up as False thus the following code is not actioned. I suppose that the #Disable auto-sleep and # 1 is STAT_CONNECTING would be specific to the wifi that the pico uses and certainly the nano objects to these. I'm not sure of the impact of ignoring the RP2 BUSY_ERRORS but note the default is then set to just I did have a quick test and all seemed to work OK on the nano, but I've not used it in earnest. As both the nano and pico both have the platform of 'rp2' I don't know how one could make the code work equally for the nano and the pico automatically. I just hacked the mqtt_as code as placed on the nano. Firstly of course the nano's wifi must be made to work. Like you I have an early nano. When I first had the nano it immediately needed a firmware update to make the wifi work at all. (this is an Arduino firmware update, nothing to do with micropython firmware.) Back then, if I remember correctly, I had to update the Arduino firmware via an Arduino web link. Sometime later the wifi stopped working with micropython and updates via the Arduino web link no longer worked. Recently, through a suggestion from @Josverl I found there was a firmware updater program called arduino-fwuploader. I download this to my mac computer along with the latest micropython for the nano from the mp download page. To upload this to the arduino board I had to use the following command: Rather than change the mqtt_as code I suggest it may be better to simply put a note in your docs about the use of the nano board should you see fit. Well at least I may have enabled you resuscitate your Arduino nano board which is probably languishing in a forgotten electronics bits drawer like mine was, though I'm not so sure you will make any good use of it :) |
Beta Was this translation helpful? Give feedback.
-
|
@scruss Following your suggestions I got to the point where "FIRMWARE-VERSION: 3.0.1" was displayed. I put the board into bootloader mode by powering up with However I have completely failed to connect to the WLAN. The following script (which runs on a Pico W) hangs at 'connecting to network...' import network
import ubinascii
import machine
# import network
sta_if = network.WLAN(network.STA_IF)
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.active(False) # deactivate the interface
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect('misspiggy', 'redacted')
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
a = sta_if.config('mac')
print(f"MAC {a[0]:02x}:{a[1]:02x}:{a[2]:02x}:{a[3]:02x}:{a[4]:02x}:{a[5]:02x}", end="")
print(f' b"\\x{a[0]:02X}\\x{a[1]:02X}\\x{a[2]:02X}\\x{a[3]:02X}\\x{a[4]:02X}\\x{a[5]:02X}"', end="")
print(f' {ubinascii.hexlify(machine.unique_id())}') # Verify that this is MAC
The accursed thing is almost working... Any thoughts? |
Beta Was this translation helpful? Give feedback.
-
|
@peterhinch |
Beta Was this translation helpful? Give feedback.
-
|
I probably should have also put in the REPL responses for my previous post script :) |
Beta Was this translation helpful? Give feedback.
-
|
It turns out that my Arduino board actually works - it concealed this status by being remarkably insensitive. It connects reliably in the same room as the AP. I've now been able to test with mqtt_as and have pushed an update. While I have not tested for resilience it publishes and responds correctly to incoming messages. Thanks to @beetlegigg and @scruss who advised on arduino-fwuploader and @beetlegigg who correctly identified the necessary changes to the library. |
Beta Was this translation helpful? Give feedback.
-
|
-53dBm? My board would have no truck with that. See below. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to get an Arduino Nano RP2040 Connect board to run as an MQTT publisher. This is another case for me where the code works (usually) on a real Raspberry Pi Pico W, but not on the Arduino board. I was previously having trouble with other network connections; see https://github.com/orgs/micropython/discussions/18901. Here was a solution for my NTP time problem that worked for both the Arduino and the Raspberry. I'm hoping someone has a solution for MQTT, or at least some insights as to what's going on. Thanks for any help.
Arduino results:
Raspberry results:
Beta Was this translation helpful? Give feedback.
All reactions