Preparing Google Cloud IoT Core to Receive Messages

March 29, 2018

In this blog we will connect the Mongoose OS based ESP8266 with Google Cloud IoT Core and Google Cloud Pub/Sub, which we will be using for it’s MQTT Broker capability.

We will not cover the basics of handling and navigating in Google Cloud Console, if you are new to it, please do look at the learning capabilities provided by Google.

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

The newly created instance doesn’t know yet about and devices, but this will change when we “introduce” our ESP8266 to it.

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 protected] --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:[email protected] --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.

Next Step

In the next blog we will cover how to enable our ESP to send MQTT Message to Google Cloud IoT Core.

2 replies on “Preparing Google Cloud IoT Core to Receive Messages”

Leave a Reply

close

Subscribe to our newsletter.

Please select all the ways you would like to hear from Open Sourcerers:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our newsletter platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.