In this folder you will find an example of using MQTT with a simple client. Note that this example uses MicroPython as the development environment.

To use the example, MicroPython must be flashed on the device.

In the Resources folder you will find a UF2 file that can be used to flash the Raspberry Pi Pico W board. Simply hold down the boot button while powering on the board. It will be reset and will show up as a simple drive on your computer. Drag the UF2 file to the board - it will reboot and have MicroPython installed.

## ESP32

It is possible to use the example with an ESP board by Espressive as well (tested with ESP32 Wroom)

Installing MicroPython on the ESP32 is slightly more complex, and requires the installation of "esptool", a python library that will allow you to flash a binary file to the board.

The steps include:

* Download the propery binary for the board
* Set up a virtual environment for Python
* Install esptool
* Identify the port the device is on
* Use esptool to flash the binary your downloaded to the board

### Set up Virtual Environment

Setting up a virtual environment for Python is necessary because Python is now regularly used by the operating system. Accordingly, the OS will not typically allow packages to be installed by another package manager, otherwise critical packages could be overwritten. A virtual environment allows all package dependencies to be installed in a virtual location, protecting system Python packages.

`python -m venv esptoolenv`

Now you can activate the environment, which will allow us to install the tool (see below)

`source esptoolenv/bin/activate`

### Install ESPTool

In the virutal environment you can use the pip installer to get the tool.

`pip install esptool`

### Identify the port device is on

`ls /dev/tty*`

### Flash the binary

`esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 ESP32_GENERIC-20240602-v1.23.0.bin`

### Deactivate the virtual environment

`deactivate`

You can now use your code editor (like Thonny) to connect to your device and write the python code you find here.

As with the RP2040 you'll need to copy the MQTT client library onto the device.