{"id":13801769,"url":"https://github.com/GoogleCloudPlatform/iot-core-micropython","last_synced_at":"2025-05-13T11:31:51.134Z","repository":{"id":55565189,"uuid":"191653255","full_name":"GoogleCloudPlatform/iot-core-micropython","owner":"GoogleCloudPlatform","description":null,"archived":true,"fork":false,"pushed_at":"2020-12-21T20:10:08.000Z","size":63,"stargazers_count":52,"open_issues_count":9,"forks_count":14,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-19T22:18:32.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleCloudPlatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-12T22:30:06.000Z","updated_at":"2023-08-11T08:20:27.000Z","dependencies_parsed_at":"2022-08-15T03:20:17.080Z","dependency_job_id":null,"html_url":"https://github.com/GoogleCloudPlatform/iot-core-micropython","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/GoogleCloudPlatform%2Fiot-core-micropython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fiot-core-micropython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fiot-core-micropython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fiot-core-micropython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleCloudPlatform","download_url":"https://codeload.github.com/GoogleCloudPlatform/iot-core-micropython/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253932958,"owners_count":21986484,"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-08-04T00:01:27.066Z","updated_at":"2025-05-13T11:31:46.124Z","avatar_url":"https://github.com/GoogleCloudPlatform.png","language":"Python","readme":"MicroPython Example with Google IoT Core\n============================================\n\nThis sample demonstrates how to use MicroPython to connect to Cloud IoT Core incorporating parts from [TrackingPrototype](https://github.com/jbrichau/TrackingPrototype).\n\n## Quickstart with Espressif ESP32\n\n1. Clone or download this repository\n\n```\n    git clone https://github.com/GoogleCloudPlatform/iot-core-micropython\n    cd iot-core-micropython\n```\n\n2. Create a virtual environment and install the tools for ESP32.\n\n```\n    virtualenv env\n    source env/bin/activate\n    pip install esptool adafruit-ampy rsa\n```\n\n3. Determine the port your board is on and set an environment variable to be reused later.\n\n```\n    ls /dev/ | grep -i \"tty\" | grep -i \"usb\"\n    export SERIALPORT=\"/dev/tty.SLAB_USBtoUART\"\n```\n\n4. Test flashing your device.\n\n```\n    esptool.py --port $SERIALPORT flash_id\n```\n\n5. [Download and install MicroPython](http://micropython.org/download).\n\n```\n    esptool.py --chip esp32 --port $SERIALPORT erase_flash\n    esptool.py --chip esp32 --port $SERIALPORT --baud 460800 write_flash -z 0x1000 ~/Downloads/esp32–20190529-v1.11.bin\n```\n\n6. Generate your public / private keypair.\n\n```\n    openssl genrsa -out rsa_private.pem 2048\n    openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem\n```\n\n7. Create your registry and device, [as described in the Cloud IoT Core documentation](https://cloud.google.com/iot/docs/how-tos/devices), using the keys from the previous step.\n\n8. Translate the RSA key for device configuration and install the output into a new file based on `config.py.example`.\n\n```\n    cp config.py.example config.py\n    python utils/decode_rsa.py \u003e\u003e config.py\n    ...\n```\n\n9. Update config.py to use the key you appended to the file and set the Google Cloud Confiugration section of the file based on the device and registry you set up in the previous step.\n\n10. Copy the Python sources to the device.\n\n```\n    ampy --port $SERIALPORT --baud 115200 put third_party\n    ampy --port $SERIALPORT --baud 115200 put config.py\n    ampy --port $SERIALPORT --baud 115200 put main.py\n```\n\n11. Connect to the device over the serial port and press reset on the device.\n\n```\n    screen -L $SERIALPORT 115200\n```\n\nNote that on machines without screen, you can use other software such as the\n[Arduino IDE](https://arduino.cc) for accessing the terminal.\n\nIf everything worked you should see output similar to the following.\n\n    Publishing message {“temp”: 113, “device_id”: “esp32-oled-1”}\n    Publishing message {“temp”: 114, “device_id”: “esp32-oled-1”}\n    Publishing message {“temp”: 114, “device_id”: “esp32-oled-1”}\n\nYou can read the telemetry from PubSub using the following [Google Cloud SDK](https://cloud.google.com/sdk) command.\n\n    gcloud pubsub subscriptions pull \u003cyour-pubsub-repo\u003e --auto-ack --limit=500\n\n## Troubleshooting\nIf the device freezes around the time network initialization completes you may\nwant to try using a different pin for the LED. This can resolve some issues.\n\n## Hardware target(s)\n* Espressif ESP32\n\n## Dependencies\n* Some small modifications have been done to [python-rsa](https://github.com/sybrenstuvel/python-rsa) library to allow this to work on MicroPython.\n\n## Pre-requisites\n* Google Cloud Project with the Cloud IoT Core API enabled\n* ESP32 compatble device\n\n## See Also\n* [Connecting MicroPython devices to Cloud IoT Core](https://medium.com/google-cloud/connecting-micropython-devices-to-google-cloud-iot-core-3680e632681e)\n\n## License\n\nApache 2.0; see [LICENSE](LICENSE) for details.\n\n## Disclaimer\n\nThis project is not an official Google project. It is not supported by Google\nand Google specifically disclaims all warranties as to its quality,\nmerchantability, or fitness for a particular purpose.\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleCloudPlatform%2Fiot-core-micropython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoogleCloudPlatform%2Fiot-core-micropython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleCloudPlatform%2Fiot-core-micropython/lists"}