2024-05-14 16:11:08 +03:00

3.2 KiB

MQTT Example

This is nRF24L01 and MQTT gateway application.

            +----------+           +----------+           +----------+           +----------+
            |          |           |          |           |          |           |          |
            |Publisher |--(MQTT)-->|  Broker  |--(MQTT)-->|  ESP32   |--(SPI)--->| nRF24L01 |==(Radio)==>
            |          |           |          |           |          |           |          |
            +----------+           +----------+           +----------+           +----------+

            +----------+           +----------+           +----------+           +----------+
            |          |           |          |           |          |           |          |
==(Radio)==>| nRF24L01 |--(SPI)--->|  ESP32   |--(MQTT)-->|  Broker  |--(MQTT)-->|Subscriber|
            |          |           |          |           |          |           |          |
            +----------+           +----------+           +----------+           +----------+

Configuration

config-top config-app

WiFi Setting

config-wifi

Radioi Setting

MQTT to Radio

Subscribe with MQTT and send to Radio.
You can use mosquitto_pub as Publisher.
sh ./mqtt_pub.sh

            +----------+           +----------+           +----------+           +----------+
            |          |           |          |           |          |           |          |
            |Publisher |--(MQTT)-->|  Broker  |--(MQTT)-->|  ESP32   |--(SPI)--->| nRF24L01 |==(Radio)==>
            |          |           |          |           |          |           |          |
            +----------+           +----------+           +----------+           +----------+

config-radio-2

Radio to MQTT

Receive from Radio and publish as MQTT.
You can use mosquitto_sub as Subscriber.
sh ./mqtt_sub.sh

            +----------+           +----------+           +----------+           +----------+
            |          |           |          |           |          |           |          |
==(Radio)==>| nRF24L01 |--(SPI)--->|  ESP32   |--(MQTT)-->|  Broker  |--(MQTT)-->|Subscriber|
            |          |           |          |           |          |           |          |
            +----------+           +----------+           +----------+           +----------+

config-radio-1

Specifying an MQTT Broker

You can specify your MQTT broker in one of the following ways:

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

You can use this as broker.
https://github.com/nopnop2002/esp-idf-mqtt-broker

Communicate with Arduino Environment

Run this sketch.
ArduinoCode\Peer-to-peer\StringTest