Skip to content

luisomoreau/ESP32-cam-MQTT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Get started with the ESP32 cam module and store pictures in the Cloud

In this tutorial, we will see how to take a picture publishing a message on a SMILE topic and forward this message to a S3-compatible Object Storage bucket.

diagram

To do this, we will be using the default example code for the esp32 camera module which will be slightly modified to add the MQTT compatibility.

Material

esp32-cam

Get the boards:

The external antenna is optional but will give you a better Wifi coverage.

Prerequisties

arduino-installer

Setting up your developer environment

Open Arduino preferences:

arduino-preferences

and add the board https://dl.espressif.com/dl/package_esp32_index.json as followed:

arduino-preferences

Go to your board manager:

board-manager-menu

And add the offical Espressif boards:

board-manager

Select the AI Thinker ESP32-CAM:

select-board

Creating the message broker (IoT Hub) and provision the devices

Go to the IoT Hub tab in the Scaleway's console:

create hub

Create your first Hub and choose the Free SHARED Plan:

create hub 1

Click on create and add a device, your hub will be ready in few seconds.

Adding a device

In this tutorial, we will add two distinguish devices: The camera itself, which be be our ESP32 cam hardware, and the MQTT explorer, which is a software that we will be using to trigger the camera and to view the payloads that are going through our Hub.

create device

Please, for this tutorial, choose Allow unsecure connections so we can easily connect our devices to our hub.

scw-view-devices

Finally, add another device that will be called mqtt-explorer:

create device 1

Once done, we will download MQTT Explorer and test the connection.

MQTT Explorer

MQTT Explorer is a comprehensive MQTT client that provides a structured overview of your MQTT topics and makes working with devices/services on your broker dead-simple.

To install a lightweight MQTT, just download it here: mqtt-explorer.com

Open MQTT Explorer and fill the following information:

Host: iot.fr-par.scw.cloud

Username: your-device-id (the Device ID can be found on the overview tab when clicking on a device, see below)

scw-device-id

mqtt-explorer

Click on Connect, you should see the following screen:

mqtt-explorer-connected

Create an Object Storage bucket

To create an object storage bucket to store our pictures, navigate under the Object Storage tab and click on + create a bucket:

scw-create-obj-storage

Give a name to your bucket and select a region :

scw-create-obj-storage-1

Click on Create a bucket and you are done.

Setting up an IoT Route

The IoT Routes allow your IoT Hub to forward messages to non-MQTT destinations. In this project, we will use the Object Storage Route.

Go back to your IoT Hub tab, select your hub and click on Routes:

scw-create-route

scw-create-route-1

Once done, your cloud environment is all set. It is time to program our ESP32 cam module

ESP32 Cam Programm

You can either start with the CameraWeServer example sketch and add modify the code or open the SCW_Photobooth sketch in this Github repository.

arduino-camerawebserver-example

If you choose to open the SCW_Photobooth.ino sketch, you just need to modify the following variable to make it work (the mqttUser being 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)

And do not forget to add the PubSubClient library:

arduino-import-pubsub-lib

You will fin this library under the library folder in the Github repository.

Now you can connect your board, select the port and uplaod the sketch. Then open the Serial console and the MQTT explorer client:

arduino-console-mqtt-explorer

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 PICTURE topic.

To see your pictures, you can go back to your Object Storage bucket in the Scaleway console. You should see your pictures being populated as you take new pictures.

scw-bucket-pic

Going further

The default CameraWebServer also provides a web interface to take pictures and change settings. I slightly modified the app_httpd.cpp code to also send the picture when captured using the web interface.

To open the web interface just copy past the local IP provided by the Serial console. Click on Get still at the bottom left corner. Once taken, the picture will be publish under the PICTURE MQTT topic and then forwarded to your Object Storage bucket!

diagram-2

camerawebserver

Ressources

Here is some interesting readings if you'd like to deep dive into the subject:

About

Scaleway photobooth project using the ESP32 cam (AI thinker)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published