MQTT Broker for esp-idf.
This project use Mongoose networking library.
I forked from here.
Your fork is welcome.
-
In this project directory, create a components directory.
-
In the components directory, clone Mongoose: git clone https://github.com/cesanta/mongoose.git
-
In the new Mongoose directory, create a component.mk file containing:
COMPONENT_ADD_INCLUDEDIRS=.
- You have to enable MG_ENABLE_MQTT_BROKER in mongoose.h.
#ifndef MG_ENABLE_MQTT_BROKER
#define MG_ENABLE_MQTT_BROKER 1
#endif
- 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
You can choice Wifi setting.
SSID:SSID of ESP32
ESP32 have 192.168.4.1.
SSID:SSID of your Wifi router
ESP32 get IP using DHCP.
SSID:SSID of your Wifi router
ESP32 set your specific IP.
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);
}
}
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