Wifi bridge for RPI Pico

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
User avatar
pythoncoder
Posts: 5143
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Wifi bridge for RPI Pico

Post by pythoncoder » Sun Apr 11, 2021 10:41 am

frustr8dlec wrote:
Fri Apr 09, 2021 2:45 pm
...
Peter is there any possibility that you would be able to clarify if an ESP-01 module would be useable with your MQTT system,
...
I have no ESP-01 hardware or experience. The underlying mqtt_as library has been extensively tested with the reference board (Adafruit Feather Huzzah) and with the WeMOS D1 mini. I would expect it to work on any device which brings out the relevant pins and has at least 2MB of flash. However it uses no subtle features, doing basic bit-banging of the pins in Python. If you feel like porting it to the -01 it might be worth a try, and maybe others can offer advice.
Peter Hinch

HermannSW
Posts: 179
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Wifi bridge for RPI Pico

Post by HermannSW » Mon Apr 12, 2021 2:35 pm

"Pico HTTPS GET through ESP01 serial2wifi"
viewtopic.php?f=21&t=10122
Pico (USB) reboot/reflash tool
https://gist.github.com/Hermann-SW/ca07 ... 6d81de01a7

Pico HTTPS GET through ESP01 serial2wifi
viewtopic.php?f=21&t=10122

Wireless Pico Micropython REPL
viewtopic.php?f=21&t=10109

User avatar
pythoncoder
Posts: 5143
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Wifi bridge for RPI Pico

Post by pythoncoder » Mon Apr 12, 2021 5:07 pm

My understanding of @frustr8dlec's question was to ask whether it was possible to re-flash an ESP-01 with code for the WiFi MQTT bridge. Using the ESP-01 as designed is a given - but supporting MQTT that way would be, er, difficult.
Peter Hinch

frustr8dlec
Posts: 2
Joined: Fri Apr 09, 2021 2:25 pm

Re: Wifi bridge for RPI Pico

Post by frustr8dlec » Fri Apr 16, 2021 2:06 pm

Thank you for the input Peter, given that although ESP01 is an 8266 micro processor but only has 1mb flash on board I am guessing this is probably going to be a dead end. Thanks for detailing the reference board that helps me greatly. I May revisit the esp01 to see if it is possible. I am curious about the content of firmware bin file on the github repository.

I really like the Pii Pico but supplying it without WiFi seriously limits it's capabilities. I have a Pico connected to the web using AT commands. But I really want MQTT client services running with it. The lack of a hardware and a library for such a device seems counter intuitive to me given the efforts they put into raspberry pi.

HermannSW
Posts: 179
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Wifi bridge for RPI Pico

Post by HermannSW » Sat Apr 17, 2021 4:57 pm

pythoncoder wrote:
Mon Apr 12, 2021 5:07 pm
... - but supporting MQTT that way would be, er, difficult.
Difficult, but not impossible.
MQTT Client only does three imports, and ubinascii is available on Pico MicroPython:
https://github.com/micropython/micropyt ... /simple.py

That leaves usocket and ussl not being available on the Pico.

I think two scenarios are valid for Pico MicroPython MQTT Client:
  • Pico connected to ESP01 via UART
  • Pico connected to some kind of Unix over USB (eg. Raspberry Pi OS)
MicroPython has ESP8266 port for ESP01 as well as Unix port for Unix.
So Pico could just implement usocket and ussl modules that proxy usocket/ussl on "the other side" over UART/USB and provide full usocket functionality via the ESP01/Unix MicroPython running on the other side.

This approach would allow to run not only MQTT Client but any MicroPython code on Pico MicroPython that only needs usocket and ussl ...
Pico (USB) reboot/reflash tool
https://gist.github.com/Hermann-SW/ca07 ... 6d81de01a7

Pico HTTPS GET through ESP01 serial2wifi
viewtopic.php?f=21&t=10122

Wireless Pico Micropython REPL
viewtopic.php?f=21&t=10109

kevinkk525
Posts: 925
Joined: Sat Feb 03, 2018 7:02 pm

Re: Wifi bridge for RPI Pico

Post by kevinkk525 » Sat Apr 17, 2021 6:11 pm

I'm still working on my implementation of a socket over uart with an Esp32 or esp8266 as the wifi module but it's going rather slow due to my personal situation.
I have a small working code, it communicates fine with an echo server but it's far from good enough for mqtt because currently there is no buffering, so every call to the socket is being sent to the esp, which makes it really slow.

Also at the moment there seem to be a few bugs with threading on the Pico, which I would like to use, so that the main thread is not impacted by the socket communication (sending 100 bytes takes 10-30ms so that could have quite an impact on an application, therefore running it on the 2nd core would be better).

I plan on making it a replacement for usocket so that every application can run with it (eventually.. First step would be basic socket operations for mqtt). Ussl however is a different matter. I can imagine exposing the Ussl library of the esp. But I have never worked with ssl in micropython so that's currently a bit out of my knowledge.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5143
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Wifi bridge for RPI Pico

Post by pythoncoder » Sun Apr 18, 2021 12:18 pm

HermannSW wrote:
Sat Apr 17, 2021 4:57 pm
...
Difficult, but not impossible...
I was suggesting that supporting MQTT using the ESP in its original "modem" mode would be problematic.

I fully accept that it should be possible to write a MicroPython driver to provide a BSD socket to a non-networked client. This would communicate via a UART with a specially programmed ESP8266. In that way the client could support any protocol, including (given a build compiled with the right libraries) protocols running via SSL/TLS. This has been discussed at various times and someone (I forget who) started work on it a year or two ago, then went quiet. Kevin Köck (@kevinkk525) is currently making an attempt on it.

I consider this a challenging problem. However, I have confidence that Kevin will achieve it.
Peter Hinch

Post Reply