Unparalleled suite of productivity-boosting Web APIs & cloud-based micro-service applications for developers and companies of any size.

APIAutomationJavascriptLocationSecurity

Ultimate Guide To Integrate apilayer And Google Cloud IoT Core Locally on Windows

google cloud iot core apilayer windows blog banner

Table of Contents

What is Google Cloud IoT Core?

Service Components and Data Flow of Google Cloud IoT Core. Image Source: Google QwikLabs.

Google Cloud IoT Core is a fully managed service that allows you to easily and securely connect, manage, and ingest data from millions of globally dispersed devices. 

Cloud IoT Core, in combination with other services on the Google Cloud IoT platform, provides a complete solution for collecting, processing, analyzing, and visualizing IoT data in real-time to support improved operational efficiency.

What We Need to Know about IoT Key Concepts?

Here are some key concepts you need to be familiar with, to understand Google Cloud IoT Core and possibly geolocation (source: Google QwikLabs):

“1. Internet of Things (IoT)

A collective term for the physical objects that are connected to the internet and can exchange data without user involvement.

2. Device

A “Thing” in the Internet of Things – a processing unit that is capable of connecting to the internet and exchanging data with the cloud. Devices are often called “smart devices” or “connected devices”. They communicate two types of data: telemetry and state.

3. Telemetry

All event data (for example, measurements about the environment) is sent from devices to the cloud. Telemetry data sent from a device to the cloud is called “device telemetry event” data. You can use Google Cloud Big Data Solutions to analyze telemetry data.

4. Device State

An arbitrary, user-defined blob of data that describes the current status of the device. Device state data can be structured or unstructured and flows only in the device-to-cloud direction.

5. Device Configuration

An arbitrary, user-defined blob of data is used to control or change a device’s state. Configuration data can be structured or unstructured and flows only in the cloud-to-device direction.

6. Device Registry

A container of devices with shared properties. You “register” a device with a service (like Cloud IoT Core) so that you can manage it (see the next item in this list).

7. Device Manager

The service you use to monitor device health and activity, update device configurations, and manage credentials and authentication.

8. MQTT

An industry-standard IoT protocol (Message Queue Telemetry Transport). MQTT is a publish/subscribe (pub/sub) messaging protocol.”

What is apilayer, and What Makes it Trusted by 1 Million++ Customer Worldwide?

apilayer Products. Browse Our Homepage apilayer.com for More Information.

apilayer is an unparalleled suite of productivity-boosting Web APIs & cloud-based microservice applications for developers and companies of any size.

The world’s most innovative companies use apilayer to gain efficiency by automating data verification, lookup, and verification using straightforward API interfaces. Thousands of applications also request currency data every day, and hundreds of thousands of users leverage apilayer’s microservice APIs to automate workflows.

How to Get Started with Google Cloud IoT Core and APIs With Node.js?

If this is the first time for you to use Google Cloud IoT Core, please read our previous articles for initial setups:

https://blog.apilayer.com/ultimate-guide-to-google-cloud-iot-core-and-apis-with-node-js/
https://blog.apilayer.com/how-to-empower-google-cloud-iot-core-with-geolocation-rest-api/

How to Create a Google Cloud Service Account?

Before we begin, let’s create a service account. Here are the steps to do it:

1. In the Cloud Console, go to the Create service account page, and select a project.

2. In the Service account name field, enter a name. The Cloud Console will fill in the Service account ID field based on this name.

In the Service account description field, enter a description. For example, “apilayer with IoT on Windows”.

3. Click Create and continue.

4. Click the Select a role field.

Under Quick access, click Basic, then click Owner.

5. Click Continue.

6. Click Done to finish creating the service account.

Do not close your browser window. You will use it in the next step.

How to Create a Google Cloud Service Account Key?

Here are the steps to create a service account key:

1. In the Cloud Console, click the email address for the service account that you created, and then click Keys.

2. Click Add Key, then click Create new key.

3. Click Create. A JSON key file would be downloaded to your computer.

This is how the private key will look like:

4. Click Close.

How to Set the Environment Variable?

To use service accounts with the Cloud SDK, you need to set an environment variable where your code runs. In this tutorial, we will run our code on Windows.

Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS. This variable only applies to your current shell session, so if you open a new session, you need to set the variable again.

Here is an example to run on your Windows command prompt:

Replace KEY_PATH with the path of the JSON file that contains your service account key:

Setting the environment variable allows us to provide credentials separately from our application, without making changes to the application code when we deploy.

How to Verify Authentication using Node.js?

After setting the environment variable, you don’t need to explicitly specify your credentials in code when using a Google Cloud client library. The client library can determine your credentials implicitly. For this reason, you can verify that authentication works by setting the environment variable and then running client library code, such as the following example.

Here is the script to verify the authentication using this Node.js script:

Save the above script as quickstart.js, and run it in your Windows command prompt using this command:

If the request succeeds, the authentication works!

 

How to Enable gcloud on Windows?

To run Google Cloud IoT Core locally on your Windows, first, you need to enable gcloud on your Windows system. gcloud is the primary CLI tool to work with Google Cloud resources.

With gcloud CLI, you can create, modify and delete various types of Google Cloud resources like Google Compute Engine virtual machines, Google Cloud SQL instances, Google Kubernetes Engine clusters, Google Cloud DNS, Google Cloud Deployment Manager, Google Cloud IoT Core, etc.

Further, it can be used to deploy App Engine applications, manage authentication to cloud resources, customize resource configuration, and various such administrative tasks.

Google Cloud gives you the option to open a shell with gcloud CLI already available and configured to use with your cloud account. To learn more about how to activate this, read our previous articles:

https://blog.apilayer.com/ultimate-guide-to-google-cloud-iot-core-and-apis-with-node-js/
https://blog.apilayer.com/how-to-empower-google-cloud-iot-core-with-geolocation-rest-api/

But if you want to use gcloud to manage your Google Cloud account directly from your Windows system, you must install it first. In this article, we’ll be covering the installation of gcloud CLI on Windows as part of the Google Cloud SDK setup.

1. Download the latest package of Cloud SDK installer here.

2. Launch the installer and follow the on-screen wizard to finish the installation.

3. Cloud SDK requires Python, and all the dependencies are bundled with the installer.

So you can use default options at every step of the installation wizard unless you have a specific requirement to change installation components or location etc. For example, I already installed Python on my system, so I uncheck the “Bundled Python” checkbox.

4. Installation finished!

5. By simply following on-screen instructions, a login screen will launch using the default browser. 

Once logged in, the shell will ask you to select the default project and region to use with gcloud CLI. Once ready, you can run gcloud commands from Windows Command Prompt.

Click Allow.

At the command prompt, type 1, and enter:

Now you are successfully open your Google Cloud IoT Core project inside your Windows command prompt:

And this window will appear in your web browser:

 

How to Enable Google Cloud IoT Core Node.js Client on Windows?

Here are the steps to enable Google Cloud IoT Core Node.js Client on Windows:

1. Git clone this Node.js endpoint for Google Cloud IoT Core repository:

2. Changed directory to ..\nodejs-iot\samples\mqtt_example, and run:

to install all the required packages.

3. Run the following command to connect a virtual device to Cloud IoT Core using the MQTT bridge, and send 50 messages:

The output shows that the sample device is publishing messages to the telemetry topic. Fifty messages are published.

How to Empower Your IoT Apps with apilayer’s Geo API and Run them on Windows?

According to Market Insight Reports, geolocation is one of the most compelling and fast-growing Internet of Things (IoT) applications. The anticipated market size for “Geo IoT” is expected to reach $74 billion by the end of 2025 from its current value of $40 billion.

In this section, we will demonstrate a basic tutorial to add position or Geographic coordinate system API to your IoT app. We will use positionstack API, one of the powerful products from apilayer.

The positionstack API was built to offer a straightforward and reliable solution for forward and reverse geocoding, covering more than 2 billion places and addresses worldwide. 

positionstack features include batch geocoding, multi-language support, embeddable map URLs, and more. API results can be delivered in JSON, XML, or geocode-specific GeoJSON. Average API response times range between 10ms and 100ms depending on the size of your request.

Let’s consider a scenario where your IoT device or apps want to send real-time messages about its position.

Here is the Node.js script to perform the reverse geocoding using positionstack:

Save the above script as a .js file, and run it on your Windows command prompt:

You will get the following responses:

Congratulations, now you know all the complete steps to successfully run Google Cloud IoT and apilayer’s API locally from your Windows system!

Are You Ready to Empower Your IoT Devices and Systems with Powerful Geo APIs?

As you can see in our API documentation, there are many accurate forward & reverse batch geocoding REST API endpoints provided by positionstack REST API which can be connected to any Cloud platform and any programming language you work with. 

In this article, we show you a comprehensive demo of how you can set up the Google Cloud IoT Core and positionstack API on Windows environments. 

Take advantage of the free tier on positionstack and we strongly recommend you to upgrade your subscription plan if you need more powerful features (HTTPS Encryption, Extended Rate Limit, JSON, XML & GeoJSON, Embeddable Maps, and, and many more!) or contact us for a custom solution. We can’t wait to see what you build with our REST API!

Head over to positionstack and start empowering your IoT devices and systems with precise and rich forward & reverse geolocation data.

Related posts
APICurrency

Exchange Rate API Integration in E-Commerce App in 2024

APICurrency

Building a Real-Time Currency Converter in Java Using Currencylayer API

API

10 Best Stocks APIs For Developers

API

Top 10 Flight Search APIs in 2024

Leave a Reply

Your email address will not be published. Required fields are marked *