Skip to content

lzbgt/esp-idf-mqtt-broker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

esp-idf-mqtt-broker

MQTT Broker for esp-idf.
This project use Mongoose networking library.
I forked from here.
Your fork is welcome.


  1. In this project directory, create a components directory.

  2. In the components directory, clone Mongoose: git clone https://github.com/cesanta/mongoose.git

  3. In the new Mongoose directory, create a component.mk file containing:

COMPONENT_ADD_INCLUDEDIRS=.
  1. You have to enable MG_ENABLE_MQTT_BROKER in mongoose.h.
#ifndef MG_ENABLE_MQTT_BROKER
#define MG_ENABLE_MQTT_BROKER 1
#endif
  1. Compile this project.

git clone https://github.com/nopnop2002/esp-idf-mqtt-broker
cd esp-idf-mqtt-broker
mkdir -p components
cd components/
git clone https://github.com/cesanta/mongoose.git
cd mongoose/
echo "COMPONENT_ADD_INCLUDEDIRS=." > component.mk
vi mongoose.h
Enable MG_ENABLE_MQTT_BROKER
cd ../..
make menuconfig
make flash

Wifi Setting

You can choice Wifi setting.

config-menu

Access Point Mode

config-ap

SSID:SSID of ESP32
ESP32 have 192.168.4.1.

Station Mode

config-sta

SSID:SSID of your Wifi router
ESP32 get IP using DHCP.

Station Mode of Static Address

config-static

SSID:SSID of your Wifi router
ESP32 set your specific IP.


Monitor

Show all incoming message

show_all

Show event only

show_event


Bug Fix to mongoose.c

There is some bug in mongoose.c.
So you have to fix manually.

void mg_mqtt_suback(struct mg_connection *nc, uint8_t *qoss, size_t qoss_len,
                    uint16_t message_id) {
  size_t i;
  uint16_t netbytes;

  //Comment by nopnop2002
  //mg_send_mqtt_header(nc, MG_MQTT_CMD_SUBACK, MG_MQTT_QOS(1), 2 + qoss_len);
  //Add by nopnop2002
  mg_send_mqtt_header(nc, MG_MQTT_CMD_SUBACK, 0, 2 + qoss_len);

  netbytes = htons(message_id);
  mg_send(nc, &netbytes, 2);

  for (i = 0; i < qoss_len; i++) {
    mg_send(nc, &qoss[i], 1);
  }
}

MQTT Broker over web sockets

config-web-socket

You can test WebSocket using test-socket.py.
I forked this.

curl https://bootstrap.pypa.io/get-pip.py -o - | sudo python
sudo pip install paho-mqtt
python ./test-socket.py

About

MQTT Broker for esp-idf

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 91.3%
  • Python 6.3%
  • Makefile 2.0%
  • CMake 0.4%