The ESP32 is a low-cost, low-power system-on-a-chip microcontroller with integrated WiFi and dual-mode Bluetooth. A Tensilica Xtensa LX6 microprocessor provides the computing power of the ESP32. Its small footprint and low power requirements make it ideal for Internet of Things (IoT) applications.
In this tutorial, we use the camera module available for the ESP32 to build an IoT Photobooth. It will allow us to take photos, publish them on a
SMILE topic using IoT Hub and store our photos in an Object Storage bucket.
Note: Make sure you connect the camera module to the ESP32 module before continuing with this tutorial.
1 . Launch the Arduino IDE on your local computer.
2 . Open the Arduino preferences by clicking on Arduino > Preferences
3 . Add the ESP32 board by adding the following board manager URL to the IDE:
https://dl.espressif.com/dl/package_esp32_index.json. Confirm by clicking OK:
4 . Open the Board Manager by clicking on Tools > Board: “…“ (the board name may differ on your computer) > Boards Manager:
5 . Type esp32 in the search bar to locate the package including the official Espressif boards. Click Install to download and install them. In this tutorial, we use Version 1.0.5.
6 . Select the ESP32-CAM by clicking on Tools > Board: “…“ > ESP32 Arduino > AI Thinker ESP32-CAM:
1 . Go to the IoT Hub section in your Scaleway console. Click Create a Hub to launch the Hub creation wizard:
2 . Choose the Free SHARED Plan and enter your Hub’s details:
3 . Click Create and add a device to deploy your Hub in a few seconds.
In this tutorial, we will add two distinct devices: The camera itself, our ESP32-CAM hardware, and a software called “MQTT Explorer”, which we will be using to trigger the camera and to view the payloads that are going through our Hub.
1 . Enter a name for the first device, in our case,
camera. For this tutorial, we allow insecure connections to make it easier. In a production environment you should always deny insecure connections for security reasons. Click Add a Device to your Hub to add the device:
2 . Click Add a new Device and repeat the steps above for the second device, called
3 . Click Close once the device is added. Your Hub should now have two devices:
MQTT Explorer is a lightweight MQTT client, available for Windows, macOS, and most Linux distributions. It provides a structured overview of your MQTT topics and simplifies working with devices/services on your broker. If you have not installed MQTT-Explorer yet, download it from the official website.
Launch MQTT-Explorer on your local computer and fill in the following connection information:
Note: The Device ID can be found on the overview tab when clicking on a device (see below).
1 . Create an Object Storage bucket to store your pictures in. Click on Object Storage in the side-menu, then Create a Bucket:
2 . Name your bucket and chose a region in which your data will be stored:
3 . Click on Create a bucket to complete the bucket-creation process.
IoT Routes allow your IoT Hub to forward messages to non-MQTT destinations. In this project, we will use the Object Storage Route, which will enable us to communicate with the bucket created in the previous step.
1 . Go back to the IoT Hub section of the Scaleway console, select your Hub and click on Routes:
2 . Create a new route with the following parameters:
3 . Click Add a new Route to save the form and to create the new route.
As the cloud environment is set up, we will load our program on the ESP32-CAM module. Either start with the
CameraWebServer example sketch, modifying the code according to your needs, or open the
SCW_Photobooth sketch in this GitHub repository.
This tutorial uses the
SCW_Photobooth.ino sketch, ready to support MQTT connections.
1 . Go to the Arduino IDE and open the
SCW_Photobooth.ino sketch, available in the
SCW_Photobooth folder of the repository.
2 . Set your WiFi config and edit one variable to make it working (the
mqttUser must be your Scaleway Device ID):
//WIFI config const char* ssid = "your-ssid"; const char* password = "your-passord"; //MQTT config bool useMQTT = true; const char* mqttServer = "iot.fr-par.scw.cloud"; const char* HostName = "Photobooth_Scaleway"; const char* mqttUser = "your-device-id"; const char* mqttPassword = ""; const char* topic_PHOTO = "SMILE"; const char* topic_PUBLISH = "PICTURE"; const char* topic_FLASH = "FLASH"; const int MAX_PAYLOAD = 60000; // Maximum payload size to be sent using MQTT (in Bytes)
3 . Include the
PubSubClient library in the Sketch by clicking on Sketch > Include Library > Add .ZIP library. You find the library in the
libraries folder of the repository.
4 . Connect your ESP32-CAM board to a USB port of your compter to power it up. Select the USB port from the Tools > Port menu and upload the sketch by clicking on the Play button.
5 . Open the serial console by clicking on Tools > Serial Monitor. Once the code is uploaded your device will restart and boot the new code. Your device is ready once you will see a message like the following example:
.............................................. WiFi connected Starting web server on port: '80' Starting stream server on port: '81' Camera Ready! Use 'http://192.168.43.23' to connect Attempting MQTT connection...connected
Note: The device’s IP configuration uses DHCP. Your local WiFi requires a running DHCP server.
5 . On the MQTT Explorer client, you can send an empty payload under the
SMILE topic. Click on
PUBLISH, and your camera will take a picture and publish it under the
6 . To see your pictures, go back to your Object Storage bucket in the Scaleway console. You should see your bucket populate more and more as you take new photos.
CameraWebServer sketch also provides a web interface to take pictures and change settings. In this tutorial, we use a slightly modified
app_httpd.cpp code to also send the picture when captured using the web interface.
To open the web interface, copy/paste the local IP provided by the Serial console in your web browser:
Click on Get still at the bottom left corner. Once taken, the picture will be published under the PICTURE MQTT topic and then forwarded to your Object Storage bucket!
You can observe the upload from the serial console:
Sending picture... Picture sent ? : 1 JPG: 4022B 28ms
Below is some further reading if you’d like to take a deep dive into the subject:
Credits for Louis Moreau, who initially wrote this tutorial. All sources are available on his public GitHub account.