Skip to content

nopnop2002/esp-idf-mqtt-camera

Repository files navigation

esp-idf-mqtt-camera

Take a picture and Publish it via MQTT.
This project use ESP32 Camera Driver.

slide0001 slide0002

Hardware requirements

ESP32 development board with OV2640 camera.
If you use other camera, edit sdkconfig.default.
From the left:

  • Aithinker ESP32-CAM
  • Freenove ESP32-WROVER CAM
  • UICPAL ESPS3 CAM
  • Freenove ESP32S3-WROVER CAM (Clone)

es32-camera

Software requirements

esp-idf v4.4/v5.0.

Installation

For AiThinker ESP32-CAM, You have to use a USB-TTL converter.

ESP-32 USB-TTL
U0TXD RXD
U0RXD TXD
GPIO0 GND
5V 5V
GND GND
git clone https://github.com/nopnop2002/esp-idf-mqtt-camera
cd esp-idf-mqtt-camera
idf.py set-target {esp32/esp32s3}
idf.py menuconfig
idf.py flash monitor

Start firmware

For AiThinker ESP32-CAM, Change GPIO0 to open and press the RESET button.

Configuration

Set the following items using menuconfig.

config-main config-app

Wifi Setting

config-wifi-1

You can connect using the mDNS hostname instead of the IP address.
config-wifi-2

You can use static IP.
config-wifi-3

Using mDNS hostname

You can connect using the mDNS hostname instead of the IP address.

  • esp-idf V4.3 or earlier
    You will need to manually change the mDNS strict mode according to this instruction.
  • esp-idf V4.4
    If you set CONFIG_MDNS_STRICT_MODE = y in sdkconfig.defaults, the firmware will be built with MDNS_STRICT_MODE.
    If MDNS_STRICT_MODE is not set, mDNS name resolution will not be possible after long-term operation.
  • esp-idf V4.4.1
    mDNS component has been updated.
    If you set CONFIG_MDNS_STRICT_MODE = y in sdkconfig.defaults, the firmware will be built with MDNS_STRICT_MODE.
    Even if MDNS_STRICT_MODE is set, mDNS name resolution will not be possible after long-term operation.
  • esp-idf V5.0 or later
    mDNS component has been updated.
    Long-term operation is possible without setting MDNS_STRICT_MODE.
    The following lines in sdkconfig.defaults should be removed before menuconfig.
    CONFIG_MDNS_STRICT_MODE=y

MQTT Server Setting

MQTT broker is specified by one of the following.

  • IP address
    192.168.10.20
  • mDNS host name
    mqtt-broker.local
  • Fully Qualified Domain Name
    broker.emqx.io

You can download the MQTT broker from here.

config-mqtt

Select Board

config-board

Select Frame Size

Large frame sizes take longer to take a picture.

config-framesize-1 config-framesize-2

Select Shutter

You can choose one of the following shutter methods

  • Shutter is the Enter key on the keyboard
    For operation check.
    When using the USB port provided by the USB Serial/JTAG Controller Console, you need to enable the following line in sdkconfig.
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y

config-shutter-1

  • Shutter is a GPIO toggle

    • Initial Sate is PULLDOWN
      The shutter is prepared when it is turned from OFF to ON, and a picture is taken when it is turned from ON to OFF.

    • Initial Sate is PULLUP
      The shutter is prepared when it is turned from ON to OFF, and a picture is taken when it is turned from OFF to ON.

I confirmed that the following GPIO can be used.

GPIO PullDown PullUp
GPIO12 OK NG
GPIO13 OK OK
GPIO14 OK OK
GPIO15 OK OK
GPIO16 NG NG

config-shutter-2

  • Shutter is MQTT Publish

config-shutter-3

You can use mosquitto_pub as shutter.

mosquitto_pub -h your_broker -p 1883 -t "/take/picture" -m ""

Flash Light

ESP32-CAM by AI-Thinker have flash light on GPIO4.

config-flash

PSRAM

When you use ESP32S3-WROVER CAM, you need to set the PSRAM type.

config-psram

View pictures using opencv-python

You can use subscribe.py as image viewer.

python3 -m pip install -U wheel
python3 -m pip install 'paho-mqtt>=1.0.0,<2.0.0'
python3 -m pip install opencv-python
python3 -m pip install numpy

python3 ./subscribe.py --help
usage: subscribe.py [-h] [--host HOST] [--port PORT] [--topic TOPIC] [--output OUTPUT]

options:
  -h, --help       show this help message and exit
  --host HOST      mqtt broker
  --port PORT      mqtt port
  --topic TOPIC    mqtt topic
  --output OUTPUT  output file name

opencv

Save pictures using node.js

You can use saveFile.js to save pictures.

npm install mqtt
npm saveFile.js

Take & view pictures using flask

Read this.

Take & view pictures using android

Read this.

Built-in WEB Server

ESP32 works as a web server.
You can check the photos taken using the built-in WEB server.
Enter the ESP32's IP address and port number in the address bar of your browser.
You can connect using mDNS hostname instead of IP address.

browser

MQTT client Example

Example code in various languages.
https://github.com/emqx/MQTT-Client-Examples

References

https://github.com/nopnop2002/esp-idf-mqtt-broker

https://github.com/nopnop2002/esp-idf-mqtt-image-viewer

https://github.com/nopnop2002/esp-idf-mqtt-image-client

Releases

No releases published

Packages

No packages published