Connecting MicroPython devices to Google Cloud IoT Core

Carl Krauss
Jun 12 · 6 min read

Intro

Select a device

pip install esptool adafruit-ampy
ls /dev/ | grep -i "tty" | grep -i "usb"
export SERIALPORT="/dev/tty.SLAB_USBtoUART"
esptool.py —-port $SERIALPORT flash_id
esptool.py —-chip esp32 —-port $SERIALPORT erase_flashesptool.py —-chip esp32 —-port $SERIALPORT —-baud 460800 write_flash -z 0x1000 ~/Downloads/esp32–20190529-v1.11.bin
ampy —-port $SERIALPORT -—baud 115200 ls
openssl genrsa -out rsa_private.pem 2048openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem

Configure Google Cloud IoT Core

Device Setup

git clone https://github.com/GoogleCloudPlatform/iot-core-micropythoncd iot-core-micropython/
pip install rsapython utils/decode_rsa.py
ampy —-port $SERIALPORT —-baud 115200 put libampy —-port $SERIALPORT —-baud 115200 put config.pyampy —-port $SERIALPORT —-baud 115200 put main.py
ampy —-port /dev/tty.SLAB_USBtoUART —-baud 115200 ls/boot.py
/config.py
/lib
/main.py
screen -L /dev/tty.SLAB_USBtoUART 115200 -L
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”}

Wrapping Up

gcloud pubsub subscriptions pull —-limit=10 —-auto-ack projects/[your-project-id]/subscriptions/[your-subscription-id]

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Carl Krauss

Written by

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.