Add MQTT support for PicoW

Issue #309 resolved
Hans Braakmann created an issue

The wiki HTTP server page states: to access the server on http://127.0.0.0/6437. It should be http://127.0.0.0:6437.

I also tried the MQTT library with MQTT example on a PicoW…which gives the following error.

Comments (17)

  1. John Maloney repo owner

    Thanks for noticing the URL error on the Wiki page. That's now fixed.

    MQTT is not yet supported on the Pico W.

    When I last checked (in July) there was not yet an Arduino C++ library for MQTT that we could use to add MicroBlocks support. However, I see that MicroPython now has MQTT support for the Pico W so things may have changed since then. I'll take another look.

  2. John Maloney repo owner

    I don't think so. The 6473 is the port number, not a path.

    In Chrome, this URL:

    http://127.0.0.1:6473/

    Shows the HTTP server web page:

    Screen Shot 2022-11-28 at 10.14.27 AM.png

    but this one:

    http://127.0.0.1/6473

    Says the site cannot be reached. Does the second URL work for you? If so, what browser are you using?

  3. John Maloney repo owner

    We may be talking about two different HTTP servers.

    I am talking about running the HTTP server in the MicroBlocks IDE using this menu command:

    Screen Shot 2022-11-28 at 1.28.54 PM.png

    Is that the one you are talking about?

    It is also possible to run an HTTP server on a WiFi enabled board. In that case, the default port is port 80, so using ":6473" would give a "site cannot be reached".

  4. Hans Braakmann reporter

    The start HTTP SERVER confuses me, I didn’t have to start a server on my setup (PicoW, DHT11 connected to a power bank). I think it has something to do when components are using the same wifi network. Could the PicoW create or have its own web address? Still have to use: http://127.0.0.0/6473 with a slash and it even works with http://127.0.0.0. MQTT would be more straightforward and more save.

  5. John Maloney repo owner

    Ahh, I think I see.

    I believe you are not actually connecting to your Pico W when you fetch http://127.0.0.0/6473. As a test, if you disconnect and power down your Pico W, do you still get a response to that URL?

    I think you may be connecting to an HTTP server running on your local machine. MacOS has a built-in Apache server that is sometimes enabled by default. At least, it was on my recently purchased MacBook, which was very confusing! If you are running MacOS, that could be what you are connecting to. Windows and Linux may have similar built-in HTTP servers.

    The PicoW can run an HTTP server written in MicroBlocks using the HTTP library. Here's a simple example:

    scriptImage42197895.png

    If you download the above image to your desktop, you can then drag-and-drop it onto the MicroBlocks window to import that script. (Note: It doesn't work to drag the image directly from the web browser; you need to download it.)

    If you run the above script on your Pico, you should be able to connect to it. You will need to add the name and password for your WiFi network, of course. You will also need to know the IP address of the PicoW. That will be displayed in the MicroBlocks window when it first connects to the WiFi network. You can also click the:

    scriptImage42821617.png

    block from the WiFi library to get the address. That is the IP address you should use in the URL. You do not need to use the port number, so your URL will look something like this:

    http://192.168.12.17/
    

    but with your Pico W's IP address.

  6. John Maloney repo owner

    Good news! MQTT support for the Pico-W was easier than expected. It will be in the next Pilot release which should be out next week.

  7. Hans Braakmann reporter

    Very nice, making sensors on a distance more easily accessible. Looking forward to try this new release.

  8. John Maloney repo owner

    MQTT support for the Pico-W is included in the latest MicroBlocks Pilot release. (It is also in the stable webapp release.) You'll need to update your Pico-W firmware to v171 to use the MQTT library.

  9. Hans Braakmann reporter

    I gave it a try, thanks John now I can publish my sensor with MicroBlocks mqtt and subscribe to it from Snap! 👌

  10. Log in to comment