{"id":13801945,"url":"https://github.com/chrismoorhouse/micropython-mqtt","last_synced_at":"2025-05-13T12:32:05.131Z","repository":{"id":139939286,"uuid":"127582104","full_name":"chrismoorhouse/micropython-mqtt","owner":"chrismoorhouse","description":"Async MQTT library with auto reconnect for MicroPython devices such as the ESP32 or Pycom devices","archived":false,"fork":false,"pushed_at":"2018-04-01T18:36:57.000Z","size":22,"stargazers_count":32,"open_issues_count":5,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-22T12:33:26.130Z","etag":null,"topics":["library","micropython","mqtt","mqtt-client"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrismoorhouse.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-04-01T00:21:29.000Z","updated_at":"2024-03-12T15:10:42.000Z","dependencies_parsed_at":"2024-01-07T21:53:15.060Z","dependency_job_id":"9b817c5f-73e6-471c-93c2-087909901dab","html_url":"https://github.com/chrismoorhouse/micropython-mqtt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrismoorhouse%2Fmicropython-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrismoorhouse%2Fmicropython-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrismoorhouse%2Fmicropython-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrismoorhouse%2Fmicropython-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrismoorhouse","download_url":"https://codeload.github.com/chrismoorhouse/micropython-mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253942500,"owners_count":21988067,"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":["library","micropython","mqtt","mqtt-client"],"created_at":"2024-08-04T00:01:31.186Z","updated_at":"2025-05-13T12:32:04.866Z","avatar_url":"https://github.com/chrismoorhouse.png","language":"Python","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"readme":"# micropython-mqtt\nAsync MQTT client library with auto reconnect for MicroPython devices such as the ESP32 or Pycom devices\n\n#### Installation\n- Download the **mqtt.py** file and add it to your /libs folder\n\n#### Features\nThe **MQTTClient** class is a simple lightweight MQTT client for basic MQTT pub / sub functionality. It has the following features:\n- Auto reconnect to the broker when the connection is lost\n- Supports QOS 0 and 1 for publish and subscribe\n- Publish, subscribe and receipt of published messages are all async\n- Automatically handles ping requests if no messages are sent for a period of time\n\n#### Usage\nSee the **basic-example.py** file in the **examples** folder for a simple example of using the **MQTTClient** class\n\n##### `from libs.mqtt import MQTTClient`\nImport the MQTTClient class\n\n##### `client = MQTTClient('192.168.1.1', port=1883)`\nConstruct a new instance of the **MQTTClient** class\n- Parameter: **server** - the address of the MQTT broker\n  - Type: string\n- Parameter: **port** - the TCP/IP port to connect to\n  - Type: number\n- Optional Parameter: **reconnect_retry_time** - the time in seconds between reconnect retry attempts\n  - Type: number\n  - Default: 10\n- Optional Parameter: **keep_alive** - the time in seconds of no activity before a ping is sent to the broker\n  - Type: number\n  - Default: 15\n- Optional Parameter: **ssl** - set True to use SSL\n  - Type: boolean\n  - Default: False\n- Optional Parameter: **ssl_params** - the SSL parameters to use if using SSL\n  - Type: object\n\n##### `set_connected_callback(cb)`\nSet the callback method which is fired when the **connected** status changes. This callback is optional\n- Parameter: **cb** - the callback method\n  - Type: method name\n  - Callback Signature: `def connected_cb(status)` where **status** is True if the client is connected or False if disconnected\n\n##### `set_message_callback(cb)`\nSet the callback method which is fired when a new MQTT message arrives. This callback is optional\n- Parameter: **cb** - the callback method\n  - Type: method name\n  - Callback Signature: `def message_cb(topic, payload)` where **topic** is the message topic and **payload** is the message payload\n\n##### `set_puback_callback(cb)`\nSet the callback method which is fired when a publish command succeeds. This callback is optional\n- Parameter: **cb** - the callback method\n  - Type: method name\n  - Callback Signature: `def puback_cb(msg_id)` where **msg_id** is a message ID. This can be matched with a message ID returned from the **publish** method to confirm that a publish has succeeded\n\n##### `set_suback_callback(cb)`\nSet the callback method which is fired when a subscribe command succeeds. This callback is optional\n- Parameter: **cb** - the callback method\n  - Type: method name\n  - Callback Signature: `def suback_cb(msg_id)` where **msg_id** is a message ID. This can be matched with a message ID returned from the **subscribe** method to confirm that a subscribe has succeeded\n\n##### `set_unsuback_callback(cb)`\nSet the callback method which is fired when an ubsubscribe command succeeds. This callback is optional\n- Parameter: **cb** - the callback method\n  - Type: method name\n  - Callback Signature: `def unsuback_cb(msg_id)` where **msg_id** is a message ID. This can be matched with a message ID returned from the **unsubscribe** method to confirm that an unsubscribe has succeeded\n\n##### `connect(client_id, user=None, password=None, clean_session=True, will_topic=None, will_qos=0, will_retain=False, will_payload=None)`\nConnect the MQTT client to the broker. This method is non-blocking and returns before the connection has completed.\n- Parameter: **client_id** - the ID of this MQTT client\n  - Type: string\n- Optional Parameter: **user** - the username used to authenticate with the broker\n  - Type: string\n  - Default: None\n- Optional Parameter: **password** - the password used to authenticate with the broker\n  - Type: string\n  - Default: None\n- Optional Parameter: **clean_session** - set true to start a clean session with the broker\n  - Type: boolean\n  - Default: True\n- Optional Parameter: **will_topic** - the last will and testament topic.\n  - Type: string\n  - Default: None\n- Optional Parameter: **will_qos** - the last will and testament QOS level. QOS values of 0, 1 and 2 are valid\n  - Type: number \n  - Default: 0\n- Optional Parameter: **will_retain** - the last will and testament message retain flag\n  - Type: boolean \n  - Default: False\n- Optional Parameter: **will_payload** - the last will and testament message payload\n  - Type: string \n  - Default: None\n\n##### `disconnect()`\nDisconnect the MQTT client from the broker\n\n##### `isconnected()`\nGet the status of the connection between the MQTT client and broker\n- Returns: True if the client is connected, else False\n\n##### `publish(topic, payload, retain=False, qos=0)`\nPublish an MQTT message to the broker\n- Parameter: **topic** - the message topic\n  - Type: string\n- Parameter: **payload** - the message payload\n  - Type: string\n- Optional Parameter: **retain** - the message retain flag\n  - Type: boolean\n  - Default: False\n- Optional Parameter: **qos** - the message QOS level. QOS values of 0 and 1 are valid. This library does not currently support QOS 2\n  - Type: number\n  - Default: 0\n- Returns: QOS = 0, None. QOS = 1, the publish message ID. This can be used with the *set_puback_callback* to verify that a message has been published\n- Raises: MQTTException if the message cannot be published\n\n##### `subscribe(topic, qos=0)`\nSubscribe to an MQTT topic\n- Parameter: **topic** - the topic to subscribe to. MQTT wildcards can be used\n  - Type: string\n- Optional Parameter: **qos** - the subscription QOS level. QOS values of 0 and 1 are valid. This library does not currently support QOS 2\n  - Type: boolean\n  - Default: False\n- Returns: the subscribe message ID. This can be used with the *set_suback_callback* to verify that a subscription was successful\n- Raises: MQTTException if the subscribe message cannot be sent\n\n##### `unsubscribe(topic)`\nUnsubscribe from an MQTT topic\n- Parameter: **topic** - the topic to unsubscribe from. MQTT wildcards can be used\n  - Type: string\n- Returns: the unsubscribe message ID. This can be used with the *set_unsuback_callback* to verify that an unsubscription was successful\n- Raises: MQTTException if the unsubscribe message cannot be sent","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrismoorhouse%2Fmicropython-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrismoorhouse%2Fmicropython-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrismoorhouse%2Fmicropython-mqtt/lists"}