GoogleCloudPlatform/google-cloud-iot-arduino

Name: google-cloud-iot-arduino

Owner: Google Cloud Platform

Description: Google Cloud IOT Example on ESP8266

Created: 2018-04-04 17:02:54.0

Updated: 2018-05-23 18:04:08.0

Pushed: 2018-05-23 21:23:14.0

Homepage:

Size: 88

Language: C++

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Google Cloud IOT JWT

This is an example of how to generate JSON Web Token (JWT) credentials for connecting to Google Cloud IoT Core.

This contains two parts: a library to make a JWT (json web token) which is used to authenticate with Google Cloud IOT, and Arduino sketches that demonstrate how to connect to Google Cloud IOT using the available HTTP and MQTT bridges.

This example is not an officially supported Google product, does not have a SLA/SLO, and should not be used in production.

Quickstart

First, install the library using the Arduino Library Manager.

Next, enable the Cloud IoT Core API by opening the Google Cloud IoT Core console.

Next, create your device registry as described in the Quickstart or by using the Google Cloud SDK.

If you're using the SDK, the following commands will setup PubSub and Cloud IoT Core for testing on your Arduino device:

Create the PubSub topic and subscription:

gcloud pubsub topics create atest-pub --project=YOUR_PROJECT_ID
gcloud pubsub subscriptions create atest-sub --topic=atest--pub

Create the Cloud IoT Core registry:

gcloud iot registries create atest-registry \
  --region=us-central1 --event-notification-config=topic=atest-pub

Generate an Eliptic Curve (EC) private / public key pair:

openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
openssl ec -in ec_private.pem -pubout -out ec_public.pem

Register the device using the keys you generated:

gcloud iot devices create atest-dev??region=us-central1?\
    ?registry=atest-registry \
    ?public-key path=ec_public.pem,type=es256

At this point, your registry is created and your device has been added to the registry so you're ready to connect it.

Select one of the available samples from the File > Examples > Google Cloud IoT Core JWT menu and find the configuration section (ciotc_config.h in newer examples).

Find and replace the following values first:

You will also need to extract your private key using the following command:

openssl ec -in ec_private.pem --noout -text

… and will need to copy the output for the private key bytes into the private key string in your Arduino project.

When you run the sample, the device will connect and receive configuration from Cloud IoT Core. When you change the configuration in the Cloud IoT Core console, that configuration will be reflrected on the device.

The JWT library

The JWT library is contained in the /jwt folder. To generate the library run the following commands from the jwt directory:

wt
ce compile.sh

The above command will create a new directory jwt/jwt which is a working Arduino library. To install it copy it to the libraries folder of your Arduino installation (~/Arduino/libraries on linux). When we publish the library, the output of that folder is placed into the /src.

To clean the output run source compile.sh clean.

Known issues
HTTP Examples
ESP32-MQTT
License

Apache 2.0; see LICENSE for details.

Disclaimer

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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.