{"id":13398739,"url":"https://github.com/tuanpmt/esp_mqtt","last_synced_at":"2025-05-16T06:04:38.470Z","repository":{"id":25082881,"uuid":"28503528","full_name":"tuanpmt/esp_mqtt","owner":"tuanpmt","description":" MQTT client library for ESP8266","archived":false,"fork":false,"pushed_at":"2020-12-22T11:05:45.000Z","size":571,"stargazers_count":1149,"open_issues_count":41,"forks_count":402,"subscribers_count":154,"default_branch":"master","last_synced_at":"2025-04-08T15:14:55.401Z","etag":null,"topics":["esp8266","iot","mqtt"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuanpmt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-26T07:24:17.000Z","updated_at":"2025-03-03T01:35:54.000Z","dependencies_parsed_at":"2022-07-22T08:02:01.279Z","dependency_job_id":null,"html_url":"https://github.com/tuanpmt/esp_mqtt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuanpmt%2Fesp_mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuanpmt%2Fesp_mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuanpmt%2Fesp_mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuanpmt%2Fesp_mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuanpmt","download_url":"https://codeload.github.com/tuanpmt/esp_mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478186,"owners_count":22077675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp8266","iot","mqtt"],"created_at":"2024-07-30T19:00:31.249Z","updated_at":"2025-05-16T06:04:38.439Z","avatar_url":"https://github.com/tuanpmt.png","language":"C","funding_links":[],"categories":["Podcast","Interfaces","Libraries","Protocol Library"],"sub_categories":["Makers","MQTT","Others"],"readme":"**esp_mqtt**\n==========\n[![](https://travis-ci.org/tuanpmt/esp_mqtt.svg?branch=master)](https://travis-ci.org/tuanpmt/esp_mqtt)\n\nThis is MQTT client library for ESP8266, port from: [MQTT client library for Contiki](https://github.com/esar/contiki-mqtt) (thanks)\n\n\n\n**Features:**\n\n * Support subscribing, publishing, authentication, will messages, keep alive pings and all 3 QoS levels (it should be a fully functional client).\n * Support multiple connection (to multiple hosts).\n * Support SSL connection\n * Easy to setup and use\n\n***Prerequire:***\n\n- ESPTOOL.PY: https://github.com/themadinventor/esptool\n- SDK 2.0 or higher: http://bbs.espressif.com/viewtopic.php?f=46\u0026t=2451\n- ESP8266 compiler: \n    + OSX or Linux: http://tuanpm.net/esp8266-development-kit-on-mac-os-yosemite-and-eclipse-ide/\n    + Windows: http://programs74.ru/udkew-en.html \n\n**Compile:**\n\n- Copy file `include/user_config.sample.h` to `include/user_config.local.h` and change settings, included: SSID, PASS, MQTT configurations ...\n\n\nMake sure to add PYTHON PATH and compile PATH to Eclipse environment variable if using Eclipse\n\n\n```bash\ngit clone --recursive https://github.com/tuanpmt/esp_mqtt\ncd esp_mqtt\n#clean\nmake clean\n#make\nmake SDK_BASE=/tools/esp8266/sdk/ESP8266_NONOS_SDK ESPTOOL=tools/esp8266/esptool/esptool.py all\n#flash\nmake ESPPORT=/dev/ttyUSB0 flash\n```\n\n**Usage**\n\nSee file: `user/user_main.c`\n\n**Notes**\n- 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\n\n**Publish message and Subscribe**\n\n```c\n/* TRUE if success */\nBOOL MQTT_Subscribe(MQTT_Client *client, char* topic, uint8_t qos);\n\nBOOL MQTT_Publish(MQTT_Client *client, const char* topic, const char* data, int data_length, int qos, int retain);\n\n```\n\n**Already support LWT: (Last Will and Testament)**\n\n```c\n\n/* Broker will publish a message with qos = 0, retain = 0, data = \"offline\" to topic \"/lwt\" if client don't send keepalive packet */\nMQTT_InitLWT(\u0026mqttClient, \"/lwt\", \"offline\", 0, 0);\n\n```\n\n# Default configuration\n\nSee: **include/user_config.sample.h**\n\n**Define protocol name in include/user_config.local.h**\n\n```c\n#define PROTOCOL_NAMEv31\t/*MQTT version 3.1 compatible with Mosquitto v0.15*/\n//PROTOCOL_NAMEv311\t\t\t/*MQTT version 3.11 compatible with https://eclipse.org/paho/clients/testing/*/\n```\n\n\n**Create SSL Self sign**\n\n```\nopenssl req -x509 -newkey rsa:1024 -keyout key.pem -out cert.pem -days XXX\n```\n\n**SSL Mqtt broker for test**\n\n```javascript\nvar mosca = require('mosca')\nvar SECURE_KEY = __dirname + '/key.pem';\nvar SECURE_CERT = __dirname + '/cert.pem';\nvar ascoltatore = {\n  //using ascoltatore\n  type: 'mongo',\n  url: 'mongodb://localhost:27017/mqtt',\n  pubsubCollection: 'ascoltatori',\n  mongo: {}\n};\n\nvar moscaSettings = {\n  port: 1880,\n  stats: false,\n  backend: ascoltatore,\n  persistence: {\n    factory: mosca.persistence.Mongo,\n    url: 'mongodb://localhost:27017/mqtt'\n  },\n  secure : {\n    keyPath: SECURE_KEY,\n    certPath: SECURE_CERT,\n    port: 1883\n  }\n};\n\nvar server = new mosca.Server(moscaSettings);\nserver.on('ready', setup);\n\nserver.on('clientConnected', function(client) {\n    console.log('client connected', client.id);\n});\n\n// fired when a message is received\nserver.on('published', function(packet, client) {\n  console.log('Published', packet.payload);\n});\n\n// fired when the mqtt server is ready\nfunction setup() {\n  console.log('Mosca server is up and running')\n}\n```\n\n**Example projects using esp_mqtt:**\n\n- [https://github.com/eadf/esp_mqtt_lcd](https://github.com/eadf/esp_mqtt_lcd)\n\n[MQTT Broker for test](https://github.com/mcollina/mosca)\n\n[MQTT Client for test](https://chrome.google.com/webstore/detail/mqttlens/hemojaaeigabkbcookmlgmdigohjobjm?hl=en)\n\n**Contributing:**\n\nFeel free to contribute to the project in any way you like!\n\n\n**Authors:**\n[Tuan PM](https://twitter.com/TuanPMT)\n\n\n**LICENSE - \"MIT License\"**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuanpmt%2Fesp_mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuanpmt%2Fesp_mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuanpmt%2Fesp_mqtt/lists"}