Create a new Google Cloud project
To get started, we need to create a new project on Google Cloud.
Make sure you give your project a unique name and select a billing account.
When the creation of the new project has completed, select it on your Google Cloud Console.
Start Google Cloud IoT Core
If your navigation bar at the right side of your Browser window doesn’t show, select the „Hamburger“ icon and select IoT Core.
For IoT Core to function correctly, you will have to enable the Cloud IoT API.
Google Cloud IoT Core includes a Device Registry to hold the information for all the authorized devices, that communicate with IoT Core. Please follow the on-screen dialog and create a Device Registry.
You will have to give the Device Registry a name and select a Region for it to run in. You will also have to create a MQTT Topic for the devices telemetric data.
On of Google Cloud IoT Core functions is to a Protocol Bridge which works in combination with Google Cloud Pub/Sub. In our case we want to receive message via MQTT ( HTTP is selected as a possible protocol in the screenshot as well, but not used in this setup ) and want to forward them for further processing. So with the Create a topic step we actually create a MQTT Topic in Google Cloud Pub/Sub, while IoT Core will make sure to bridge the incoming messages to this MQTT Topic in Pub/Sub.
Later, when we adapt the code of our ESP8266 we will see how to address the MQTT Topic of IoT Core.
Let’s complete the creation of our IoT Core instance on Google Cloud
To complete this Google Cloud IoT Core and Google Cloud Pub/Sub preparation, we need to allow IoT Core to send messages to Pub/Sub. For this you will have to go to our command prompt. If not yet done, please install the gcloud command line tool and run the following commands:
Install some Beta capabilities
gcloud components install beta
Login to Google Cloud
gcloud auth login
Give IoT Core the permissions to publish messages
gcloud projects add-iam-policy-binding <YOUR_PROJECT_NAME> --member=serviceAccount:email@example.com --role=roles/pubsub.publisher
please make sure to replace <YOUR_PROJECT_NAME> with the name you gave your newly create Google Cloud project during an earlier step of this tutorial. In my case it is
gcloud projects add-iam-policy-binding psteiner-iot-demo-test-8 --member=serviceAccount:firstname.lastname@example.org --role=roles/pubsub.publisher
This concludes the preparation of Google Cloud IoT Core and Pub/Sub. The next blog will explain how to adapt the ESP8266 created via Mongoose OS to send messages to our cloud instance.