Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

esp_mqtt

> 编程语言
Open source

MQTT client library for ESP8266

1.2K stars0 likes1 views
WebsiteGitHub

About

MQTT client library for ESP8266

esp_mqtt

This is MQTT client library for ESP8266, port from: MQTT client library for Contiki (thanks)

Features:

  • Support subscribing, publishing, authentication, will messages, keep alive pings and all 3 QoS levels (it should be a fully functional client).
  • Support multiple connection (to multiple hosts).
  • Support SSL connection
  • Easy to setup and use

Prerequire:

  • ESPTOOL.PY: https://github.com/themadinventor/esptool
  • SDK 2.0 or higher: http://bbs.espressif.com/viewtopic.php?f=46&t=2451
  • ESP8266 compiler:
    • OSX or Linux: http://tuanpm.net/esp8266-development-kit-on-mac-os-yosemite-and-eclipse-ide/
    • Windows: http://programs74.ru/udkew-en.html

Compile:

  • Copy file include/user_config.sample.h to include/user_config.local.h and change settings, included: SSID, PASS, MQTT configurations ...

Make sure to add PYTHON PATH and compile PATH to Eclipse environment variable if using Eclipse

bash
git clone --recursive https://github.com/tuanpmt/esp_mqtt
cd esp_mqtt
#clean
make clean
#make
make SDK_BASE=/tools/esp8266/sdk/ESP8266_NONOS_SDK ESPTOOL=tools/esp8266/esptool/esptool.py all
#flash
make ESPPORT=/dev/ttyUSB0 flash

Usage

See file: user/user_main.c

Notes

  • The client id needs to be unique. If not, When there are more than 2 clients use the same ClientID, the following logged-in client will kick the ahead logged-in client, and so on forever

Publish message and Subscribe

c
/* TRUE if success */
BOOL MQTT_Subscribe(MQTT_Client *client, char* topic, uint8_t qos);

BOOL MQTT_Publish(MQTT_Client *client, const char* topic, const char* data, int data_length, int qos, int retain);

Already support LWT: (Last Will and Testament)

c

/* Broker will publish a message with qos = 0, retain = 0, data = "offline" to topic "/lwt" if client don't send keepalive packet */
MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0);

Default configuration

See: include/user_config.sample.h

Define protocol name in include/user_config.local.h

c
#define PROTOCOL_NAMEv31	/*MQTT version 3.1 compatible with Mosquitto v0.15*/
//PROTOCOL_NAMEv311			/*MQTT version 3.11 compatible with https://eclipse.org/paho/clients/testing/*/

Create SSL Self sign

openssl req -x509 -newkey rsa:1024 -keyout key.pem -out cert.pem -days XXX

SSL Mqtt broker for test

…

Example projects using esp_mqtt:

  • https://github.com/eadf/esp_mqtt_lcd

MQTT Broker for test

MQTT Client for test

Contributing:

Feel free to contribute to the project in any way you like!

Authors: Tuan PM

LICENSE - "MIT License"

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Cesp8266iotmqtt

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言