{"id":15640571,"url":"https://github.com/256dpi/processing-mqtt","last_synced_at":"2025-04-30T08:12:49.521Z","repository":{"id":23440755,"uuid":"26804168","full_name":"256dpi/processing-mqtt","owner":"256dpi","description":"MQTT library for Processing based on the Eclipse Paho project","archived":false,"fork":false,"pushed_at":"2021-01-06T13:28:31.000Z","size":780,"stargazers_count":76,"open_issues_count":3,"forks_count":15,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-30T08:12:40.606Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","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/256dpi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-18T10:33:49.000Z","updated_at":"2025-02-14T08:20:31.000Z","dependencies_parsed_at":"2022-09-07T10:41:48.000Z","dependency_job_id":null,"html_url":"https://github.com/256dpi/processing-mqtt","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/256dpi%2Fprocessing-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/256dpi%2Fprocessing-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/256dpi%2Fprocessing-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/256dpi%2Fprocessing-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/256dpi","download_url":"https://codeload.github.com/256dpi/processing-mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251666338,"owners_count":21624295,"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":[],"created_at":"2024-10-03T11:37:33.618Z","updated_at":"2025-04-30T08:12:49.503Z","avatar_url":"https://github.com/256dpi.png","language":"Java","funding_links":[],"categories":["Libraries"],"sub_categories":["Contributions"],"readme":"# processing-mqtt\n\n**MQTT library for Processing based on the Eclipse Paho project**\n\nThis library bundles the [Java Client](https://eclipse.org/paho/clients/java/) library of the Eclipse Paho project and adds a thin wrapper to get a Processing like API.\n\n[Download the latest version of the library.](https://github.com/256dpi/processing-mqtt/releases/download/latest/mqtt.zip)\n\n*Or even better use the Library Manager in the Processing IDE.*\n\n## Example\n\nThis example sketch connects to the public shiftr.io instance and sends a message on every keystroke. After starting the sketch you can find the client here: \u003chttps://www.shiftr.io/try\u003e.\n\n```java\nimport mqtt.*;\n\nMQTTClient client;\n\nvoid setup() {\n  client = new MQTTClient(this);\n  client.connect(\"mqtt://public:public@public.cloud.shiftr.io\", \"processing\");\n}\n\nvoid draw() {}\n\nvoid keyPressed() {\n  client.publish(\"/hello\", \"world\");\n}\n\nvoid clientConnected() {\n  println(\"client connected\");\n\n  client.subscribe(\"/hello\");\n}\n\nvoid messageReceived(String topic, byte[] payload) {\n  println(\"new message: \" + topic + \" - \" + new String(payload));\n}\n\nvoid connectionLost() {\n  println(\"connection lost\");\n}\n\n```\n\n## API\n\nInstantiate a new client by supplying the parent applet:\n\n```java\nMQTTClient client = new MQTTClient(PApplet parent);\n```\n\n- The constructor expects the following method to be declared on the parent applet: `void messageReceived(String topic, byte[] payload)`. That callback will then be invoked in the future with incoming messages.\n- Additionally, the following callbacks will be detected: `void clientConnected()` and `void connectionLost()` and executed appropriately.\n\nAlternatively you can provide your own `Listener` class instead of relying on global methods:\n\n```java\nMQTTClient client = new MQTTClient(PApplet parent, Listener listener);\n```\n\n- You can find the interface here: \u003chttps://github.com/256dpi/processing-mqtt/blob/master/src/mqtt/MQTTListener.java\u003e.\n\nSet the will message that gets transmitted to the server in all subsequent connect commands:\n\n```java\nvoid client.setWill(String topic, String payload);\nvoid client.setWill(String topic, String payload, int qos, boolean retained);\n```\n\n- The QoS level and retained flag default to `0` and `false` respectively.\n\nConnect to the supplied broker by parsing the URL and setting the optionally supplied client id and clean session flag:\n\n```java\nvoid client.connect(String brokerURI);\nvoid client.connect(String brokerURI, String clientId);\nvoid client.connect(String brokerURI, String clientId, boolean cleanSession);\n```\n\n- A client id will be generated if needed and the clean session flag defaults to `true`.\n\nPublish a message to the broker using the supplied topic and the optional payload in form of a String or byte-array. If available it will set the QoS level as well as the retained flag appropriately.\n\n```java\nvoid client.publish(String topic);\nvoid client.publish(String topic, String payload);\nvoid client.publish(String topic, String payload, int qos, boolean retained);\nvoid client.publish(String topic, byte[] payload);\nvoid client.publish(String topic, byte[] payload, int qos, boolean retained);\n```\n\n- The QoS level and the retained flag default to `0` and `false` respectively.\n\nSubscribe to the supplied topic using the optionally provided QoS level that defaults to `0`:\n\n```java\nvoid client.subscribe(String topic);\nvoid client.subscribe(String topic, int qos);\n```\n\nUnsubscribe from the supplied topic:\n\n```java\nvoid client.unsubscribe(String topic);\n```\n\nDisconnect from the broker:\n\n```java\nvoid client.disconnect();\n```\n\n## Notes\n\n- If you're running the sketch via the Android Mode you need to set the `INTERNET` permission in `Android \u003e Sketch Permissions`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F256dpi%2Fprocessing-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F256dpi%2Fprocessing-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F256dpi%2Fprocessing-mqtt/lists"}