A simple example how to send continously a captured image from the Camera to a MQTT Broker and receive them from a webpage. The publisher of the ESP32 is written in Micropython.
You need a running MQTT Broker like Eclipse Mosquitto or HiveMQ
The ESP32 will automatically connect to your WLAN, install necessary packages and send continously the captured image to a MQTT Broker. There are two files to set up the program. In the config.py
you set the WLAN and MQTT information. In the boot.py
you can change the camera settings.
With the example clients you can test that everything works and build your own use cases. An example image you can find in the Example Image section.
Disclaimer: CMD == Command Line == Powershell
- Set the voltage support of the FT232rl to 5V
- Connect FT232rl and ESP32-Cam with jumper cables according this table\
Pin FT232rl Pin ESP32-Cam RX U0T TX U0R VCC 5V GND GND (under U0T) - Use another jumper cable to connect IO0 and GND (both on ESP32) to reach the bootloader/flash mode
Notes for Windows: In this chapter you need to do changes on your System Environment Variables and install packages with PIP. If you change the variables you need to close the cmd to apply the changes. Sometimes when you install packages with pip then it fails. Then you need to open a cmd in administration mode.
- Install Python (3.x) with pip your system.
- (Windows) Add the folder
PYTHON_HOME/lib/site-packages
(PYTHON_HOME: Installation directory of Python) to thePATH
variable in the system environment variables - Install the package esptool (Flash tool)
pip install esptool
- (Windows) Install the package ampy (Serial Communitcation tool)
pip install adafruit-ampy
In order to access the camera we need a customized image of micropython with camera support. In the folder firmware
you can find an image from 2022-01-28 with micropython 1.17
. In this repository maybe you can find a newer version and a tutorial how to build and compile your own micropython with native camera support.
- Connect your computer with the FT232. (Maybe you need to download the FTDI Drivers for windows)
- Check with
mode
(Windows) orls /dev/ttyUSB*
(Linux) if the ESP32 is connected - Erase the flash memory of the ESP32 (replace <YOUR_PORT> with COM (Windows) or /dev/ttyUSB (Linux) and the according port number)
esptool.py --chip esp32 --port <YOUR_PORT> erase_flash
- Flash the customized micropython firmware to the ESP32
esptool.py --chip esp32 --port <YOUR_PORT> --baud 460800 write_flash -z 0x1000 ./firmware/micropython_3a9d948_esp32_idf4.x_ble_camera.bin
- Remove the jumper cable between GND and IO0 and reboot the ESP32
Micropython will automatically run at startup the
boot.py
script and immediately afterwards themain.py
script.
- Update the
config.py
andmain.py
(camera settings) file to meet your requirements - Copy the files (boot.py, main.py, config.py) from the root directory (no subfolders) to the ESP32 (order is not relevant)
ampy -p <YOUR_PORT> put <FILE>
- Restart the ESP32 (reconnect to Computer or use this command). If everything has been set correctly, the ESP32 should now send images to the MQTT broker at the set interval.
ampy -p <YOUR_PORT> reset
With ampy it is also possible to run the code from the command line or bash. Just copy the file to the ESP32 and then use ampy -p <YOUR_PORT> run <FILE>
. This is very useful for debugging purposes.
If the ESP32 successfully sends the image to the MQTT Broker you can receive it with any MQTT client, like Eclipse Paho. In the folder clients
you can find 2 examples for that. The HTML client won't need any webserver. You can open it in your browser directly.