{"id":20077448,"url":"https://github.com/drogue-iot/micropython-examples","last_synced_at":"2026-04-06T21:31:31.987Z","repository":{"id":103179390,"uuid":"561222616","full_name":"drogue-iot/micropython-examples","owner":"drogue-iot","description":"Examples of using Drogue Cloud with micropython devices","archived":false,"fork":false,"pushed_at":"2022-11-03T13:20:58.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-01-30T17:53:04.520Z","etag":null,"topics":["iot","micropython","mqtt","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drogue-iot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-03T08:14:49.000Z","updated_at":"2023-03-27T09:15:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"cc87f220-190a-4927-b9c0-013c858b00b0","html_url":"https://github.com/drogue-iot/micropython-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drogue-iot/micropython-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drogue-iot%2Fmicropython-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drogue-iot%2Fmicropython-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drogue-iot%2Fmicropython-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drogue-iot%2Fmicropython-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drogue-iot","download_url":"https://codeload.github.com/drogue-iot/micropython-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drogue-iot%2Fmicropython-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31491096,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T17:22:55.647Z","status":"ssl_error","status_checked_at":"2026-04-06T17:22:54.741Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["iot","micropython","mqtt","raspberry-pi"],"created_at":"2024-11-13T15:08:15.800Z","updated_at":"2026-04-06T21:31:31.973Z","avatar_url":"https://github.com/drogue-iot.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# micropython-examples\n\nExamples on how to use Drogue Cloud with micropython! There are two examples:\n\n* [HTTP](src/http.py)\n* [MQTT](src/mqtt.py)\n\nBoth of them read some sensor data and reports this data periodically. The device also accepts commands for turning on or off an on-board LED.\n\nThe overall architecture looks like this:\n\n``` yaml\n+--------+                      +--------------+                    +-----+\n| Device | \u003c-- MQTT or HTTP --\u003e | Drogue Cloud | \u003c-- MQTT or WS --\u003e | App |\n+--------+                      +--------------+                    +-----+\n```\n\nAs the \"App\", we'll be using the `drg` command line utility, but you can use any MQTT or WebSocket-cabable client.\n\n## Prerequisites \n\n### Hardware\n\nFor this example, we're using [Raspberry Pi Pico W](https://www.raspberrypi.com/products/raspberry-pi-pico/), but it should work on any board that can run\nmicropython, provided you modify the hardware-specific sensor reading.\n\nHave a look at [this reference](https://docs.micropython.org/en/latest/rp2/quickref.html) to learn more on how to interact with the peripherals.\n\n## Software\n\n### Micropython\n\nInstall [micropython](https://www.raspberrypi.com/documentation/microcontrollers/micropython.html) on your device:\n\n* Plug in your board, a USB storage device should appear\n* Copy the .uf2 file for your board onto the USB storage device\n\nKeep your device powered for a few seconds until micropython has been flashed to the device.\n\n### Command line tools\n\nOn your computer connected to the board, you need the following tools installed:\n\n* `drg` - Download the [latest release](https://github.com/drogue-iot/drg/releases) for your platform.\n* `mpremote` - Run `pip3 install mpremote` (assumes you have Python installed)\n\n#### Installing dependencies\n\nTo run the MQTT example, you need to install the MQTT client library as well:\n\n``` yaml\nmpremote mip install umqtt.simple\n```\n\n## Configuring Drogue Cloud\n\nThese instructions assume that you'll be using the [Drogue Cloud Sandbox](https://sandbox.drogue.cloud), but you can also [install Drogue Cloud](https://book.drogue.io/drogue-cloud/dev/admin-guide/index.html) yourself.\n\nLog in to the sandbox (or another Drogue Cloud instance):\n\n```\ndrg login https://api.sandbox.drogue.cloud\n```\n\nThis will open a browser window where you can log in using your GitHub account.\n\nNext, create the application and device with credentials (replace `example-app` and `device1` with the application name and device name you want to use):\n\n```\ndrg create application example-app\ndrg create device --application example-app device1\ndrg set password device1 hey-rodney --application example-app\n```\nNOTE: Applications are global in Drogue Cloud, so if you're using the sandbox, make sure you choose a unique application name.\n\n## Configuring the application\n\nUse the [mqtt.py](src/mqtt.py) example if you want to use MQTT, or [http.py](http.py) if you want to use HTTP. In order to run the application, you need to modify a few variables:\n\n* WIFI\\_SSID - You local wifi access point SSID.\n* WIFI\\_PSK - You local wifi access point key.\n* APPLICATION - The Drogue Cloud application name.\n* DEVICE - The Drogue Cloud device name.\n* PASSWORD - The device credentials.\n* (Optional) `HOST` - If you're using a server different from the Drogue Cloud sandbox, change this.\n* (Optional) `PORT` - If you're using a server different from the Drogue Cloud sandbox, change this.\n\n## Running the application\n\nUse the `mpremote` command to run the examples:\n\nFor MQTT:\n\n``` yaml\nmpremote run src/mqtt.py\n```\n\nFor HTTP:\n\n``` yaml\nmpremote run src/http.py\n```\n\nLogs from your application will appear in the console, and the device should start to publish the temperature once it's connected.\n\nTo learn more about how to send data to Drogue Cloud, have a look at the [endpoint documentation](https://book.drogue.io/drogue-cloud/dev/user-guide/endpoint-http.html).\n\n## Streaming the data\n\nYou can consume the data from Drogue Cloud using MQTT or WebSockets, but for the sake of simplicity you can use the `drg` tool for that as well:\n\n```\ndrg stream --application example-app\n```\n\nFor more information about connection applications to MQTT or WebSockets, have a look at [the documentation](https://book.drogue.io/drogue-cloud/dev/user-guide/integration.html).\n\n## Sending commands\n\nTo send a command back to the device, you can use the `drg command` command:\n\n``` yaml\ndrg command --app \u003capp\u003e -p '{\"led\":\"on\"}' \u003cdevice\u003e pico\n```\n\nReplace `\u003capp\u003e` and `\u003cdevice\u003e` with the Drogue Cloud application and device you're sending the command to. The `pico` keyword corresponds to the channel the device is sending telemetry to, using the default from the example is fine.\n\nFor more information about sending commands to device\n\n## Troubleshooting\n\n### I'm getting a Conflict when creating the application and/or device\n\nApplication names are global, which means that if someone else has already created this application on the Drogue Cloud instance, it is already taken and you need to choose a different name.\n\n### I'm sending commands but the device does not print them\n\nFor the device to accept commands, it must be connected to the endpoint when the command is sent. Drogue Cloud does not queue the commands for the device, since in a typical IoT application you need to provide the\n'response' to the command at the application layer anyway.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrogue-iot%2Fmicropython-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrogue-iot%2Fmicropython-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrogue-iot%2Fmicropython-examples/lists"}