peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
549 stars 116 forks source link

Woking on Pico That Uses Remote WiFI? #89

Closed Jibun-no-Kage closed 1 year ago

Jibun-no-Kage commented 1 year ago

If I attempted to load just config, without mqtt_as to get to blue_led for example. But mqtt_as is still imported? And the following error results:

Traceback (most recent call last): File "", line 11, in File "config.py", line 3, in File "mqtt_as.py", line 9, in ImportError: no module named 'usocket'

Not sure how to address or over come this. But mqtt_as attempts to load usocket as sock? Because mqtt_as import by config? Maybe the interdependence should be abstracted out? What if I just want to use config and not mqtt_as initially? Just a thought. But I digress.

The resulting issue, is on usocket as socket apparently is not core to MicroPython for Pico but only for PicoW? In point of fact I plan to use mqtt_as or revised version with Pico using socket communication with an ESP01 module in due course.

So I need to know how to add usocket as socket on a Pico using the non-pico-wifi firmware image? But again using thonny IDE this is proving difficult.

Just for reference...

Using a custom ESP01 image that supported socket communication bridged to UART is done via Arduino IDE, not using the AT command set firmware for ESP, since I see such as a better solution that driving AT commands. Of course Pico UART then can communicate to the ESP01.

ebolisa commented 1 year ago

Of course Pico UART then can communicate to the ESP01.

For $6, get a Pico W and save yourself some sanity.

Jibun-no-Kage commented 1 year ago

Got one... Pico W. I just think it is fun to do it. I already have the ESP modules and original Pico so why not! LOL You didn't think I got into mqtt_as deep as I have, without using that knowledge did you?

But to the standing question, how the heck do I get socket and other modules into the original Pico image? Do I just copy the source python files over like I did with mqtt_as and config?

peterhinch commented 1 year ago

@Jibun-no-Kage What you are trying to do is not possible with mqtt_as. You could use the MQTT bridge project to connect a Pico to the internet via an ESP8266 but I really wouldn't recommend it. A Pico W is a simple solution which works out of the box.

Jibun-no-Kage commented 1 year ago

Ah, if I implied that I was going to use mqtt_as as is or in any literal sense... that was unintended. I started with Pico W, and using mqtt_as (which is really nice by the way) as a goal and learning process. I know that ESP01 and Pico can't function as an integrated solution or platform like Pico W. What I have working, is an ESP01 image (C source via Arduino IDE) that does communicate via MQTT to the world, then drives the topic/payload from the ESP01 UART to the Pico UART, where the Pico is using MicroPython of course. The Pico accepts the topic/payload and does work, or generates results and sends same over UART to ESP01 that then translates said results to MQTT compliant communication, yes a bridged concept. :) What i plan next is to see if I can leverage I2C rather than UART, I have barely started looking at how the ESP01 can do i2C, but it will be interesting if I can see how it might work. Even came across a socket based idea that might work with some effort. The unfortunate issue, is that I can't seem to get MicroPython on an ESP01 (with 1M memory). The image loads, just no REPL. The custom image works on the ESP01 but would have loved to have an entire MicroPython based solution if possible.