Skip to content

ESP-IDF example for sending and receiving files using MQTT

License

Notifications You must be signed in to change notification settings

nopnop2002/esp-idf-mqtt-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esp-idf-mqtt-file

ESP-IDF example for sending and receiving files using MQTT.
I found this article.
It's great to be able to exchange files using MQTT.
Since the python code was publicly available, I ported it to esp-idf.

Software requirements

ESP-IDF V4.4/V5.x.
ESP-IDF V5.0 is required when using ESP32-C2.
ESP-IDF V5.1 is required when using ESP32-C6.

Installation

git clone https://github.com/nopnop2002/esp-idf-mqtt-file
cd esp-idf-mqtt-file
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

Configuration

config-top config-app

WiFi Setting

Set the information of your access point.
config-wifi

Broker 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-broker-1

Specifies the username and password if the server requires a password when connecting.
Here's how to install and secure the Mosquitto MQTT messaging broker on Debian 10.

config-broker-2

How to use

Run the following python script on the host side.

$ python3 -m pip install paho-mqtt

$ vi mqtt-file.py
Set the broker you will use.

$ python3 mqtt-file.py
usage python3 mqtt-file.py put path_to_host
usage python3 mqtt-file.py get path_to_spiffs
usage python3 mqtt-file.py list
usage python3 mqtt-file.py delete path_to_spiffs

Example of use.

# Put README.md to SPIFFS
$ python3 mqtt-file.py put README.md

# SPIFFS file list
$ python3 mqtt-file.py list

$ mv README.md README.md.md

# Get README.md from SPIFFS
$ python3 mqtt-file.py get README.md

# Compare two files
$ diff README.md README.md.md

# Delete README.md from SPIFFS
$ python3 mqtt-file.py delete README.md

MQTT Topic

This project uses the following topics:

MQTT_PUT_REQUEST="/mqtt/files/put/req"
MQTT_GET_REQUEST="/mqtt/files/get/req"
MQTT_LIST_REQUEST="/mqtt/files/list/req"
MQTT_DELETE_REQUEST="/mqtt/files/delete/req"

MQTT_PUT_RESPONSE="/mqtt/files/put/res"
MQTT_GET_RESPONSE="/mqtt/files/get/res"
MQTT_LIST_RESPONSE="/mqtt/files/list/res"
MQTT_DELETE_RESPONSE="/mqtt/files/delete/res"

When using public brokers, these topics may be used for other purposes.
If you want to change the topic to your own, you will need to change both the ESP32 side and the python side.
You can use this as your personal Broker.

About

ESP-IDF example for sending and receiving files using MQTT

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published