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: 5956
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
Index to my micropython libraries.

HermannSW
Posts: 197
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-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell

User avatar
pythoncoder
Posts: 5956
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
Index to my micropython libraries.

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: 197
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-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell

kevinkk525
Posts: 969
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: 5956
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
Index to my micropython libraries.

johnprime
Posts: 1
Joined: Sat Aug 14, 2021 4:17 pm

Re: Wifi bridge for RPI Pico

Post by johnprime » Sat Aug 14, 2021 4:48 pm

I see it's been a quiet in this thread for the last few months -- has there been any further progress here, or with other methods?

I see in other threads the ESP01 (with the AT firmware) over UART has been successful. I briefly considered this approach for my project, but when I look for info about the AT firmware I see discussions dating back 5 years ago about poor TLS/certificate support since there are limitations due to the max firmware size.

The ESP32 ("AirLift") approach by Adafruit seems modernized and more ideal, and HTTPS connections sound trivial since they burn in every root CA. but still seems to be lacking the MicroPython support.

I guess I'm just curious what others are doing for their projects, and if there is a generally accepted method for WiFi communication from an RP2040 -- specifically for making various HTTPS requests.

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

Re: Wifi bridge for RPI Pico

Post by kevinkk525 » Sun Aug 15, 2021 10:17 am

My project is currently "paused" because I have too much going on..
The Airlift project sounded great but I could never get it to work with micropython. I wrote a basic wrapper based on the circuitpython project and could communicate with the Airlift and connect to a wifi but any attempt to create a socket connection just failed.. If you get that working, it would certainly make things easier.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

tobbz123
Posts: 1
Joined: Thu Oct 21, 2021 8:13 am

Re: Wifi bridge for RPI Pico

Post by tobbz123 » Thu Oct 21, 2021 9:46 am

pythoncoder wrote:
Fri Jan 29, 2021 12:38 pm
If you only need MQTT we have already done this. Our micropython-mqtt repo has a library designed to bring MQTT to the Pyboard 1.x. With the advent of the Pyboard D I regarded it as obsolescent, but it could have a new role with the Pico.

There is a bit of pyb specific stuff there but it might be worth investigating making it cross-platform.
Hello sir, I'm beginner in micropython here, I want to make realtime control machine with mqtt, So main board I would go for Pyb v1.1 because i quite like Stm32, Now for wifi bridge I search around and i like this micropython-mqtt, I have a question can I use ESP32 instead of ESP8266 ? I try put esp8266 bridge code to ESP32 it reset after run with WDT-Reset something, so it wont run with esp8266 code, Did I missing something (I very new to uPython)
I also try to use Esp32 with adafruit firmware, I manage to make it run Mqtt with uPython on pyb board, But it seem very heavy I need to cut some code out to make it not mem allocation error, and it take alot ot pyb cpu time to takecare of wifi so i don't think will work on my project.
And because I have alot of Esp32 board but not have esp8266 so I wonder that how to make esp8266 bridge code work with Esp32?
Thank you

Post Reply