Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
utils Initial commit on behalf of @C4 Jun 12, 2019 Initial commit on behalf of @C4 Jun 12, 2019
LICENSE Initial commit on behalf of @C4 Jun 12, 2019 Add quickstart instructions Jun 21, 2019 Initial commit on behalf of @C4 Jun 12, 2019 Initial commit on behalf of @C4 Jun 12, 2019

MicroPython Example with Google IoT Core

This sample demonstrates how to use MicroPython to connect to Cloud IoT Core. It incorporates parts from

Quickstart with Espressif ESP32

  1. Clone or download this repository
    git clone
    cd iot-core-micropython
  1. Create a virtual environment and install the tools for ESP32.
    virtualenv env
    source env/bin/activate
    pip install esptool adafruit-ampy rsa
  1. Determine the port your board is on and set an environment variable to be reused later.
    ls /dev/ | grep -i "tty" | grep -i "usb"
    export SERIALPORT="/dev/tty.SLAB_USBtoUART"
  1. Test flashing your device. —-port $SERIALPORT flash_id
  1. Download and install MicroPython. —-chip esp32 —-port $SERIALPORT erase_flash —-chip esp32 —-port $SERIALPORT —-baud 460800 write_flash -z 0x1000 ~/Downloads/esp32–20190529-v1.11.bin
  1. Generate your public / private keypair.
    openssl genrsa -out rsa_private.pem 2048
    openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem
  1. Create your registry and device, as described in the Cloud IoT Core documentation, using the keys from the previous step.

  2. Translate the RSA key for device configuration and install the output into a new file based on

    python utils/ >>
  1. Update 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.

  2. Copy the Python sources to the device.

    ampy —-port $SERIALPORT —-baud 115200 put lib
    ampy —-port $SERIALPORT —-baud 115200 put
    ampy —-port $SERIALPORT —-baud 115200 put
  1. Connect to the device over the serial port and press reset on the device.
    screen -L /dev/tty.SLAB_USBtoUART 115200 -L

If everything worked you should see output similar to the following.

Publishing message {“temp”: 113, “device_id”: “esp32-oled-1”}
Publishing message {“temp”: 114, “device_id”: “esp32-oled-1”}
Publishing message {“temp”: 114, “device_id”: “esp32-oled-1”}

You can read the telemetry from PubSub using the following Google Cloud SDK command.

gcloud pubsub subscriptions pull <your-pubsub-repo> --auto-ack --limit=500

Hardware target(s)

  • Espressif ESP32


  • Some small modifications have been done to python-rsa library to allow this to work on MicroPython.


  • Google Cloud Project with the Cloud IoT Core API enabled
  • ESP32 compatble device

See Also


Apache 2.0; see LICENSE for details.


This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.

You can’t perform that action at this time.