Webinar
Unifying Data from Vehicle to Cloud | Register Now →

Migrate Your Business from GCP IoT Core 01 | Create Deployment and Connect Devices

EMQX Cloud Team
Nov 22, 2022
Migrate Your Business from GCP IoT Core 01 | Create Deployment and Connect Devices

Google Cloud will discontinue its IoT Core service on August 16, 2023, leaving IIoT companies with the need to find an alternative.

Given that Google IoT Core is based on MQTT, the best alternative options for seamless migration undoubtedly are MQTT-based IoT messaging platforms or services. With its features of 100% compliant with MQTT 3.x/ 5.0, fully-managed MQTT service and deeply integrated with GCP, EMQX Cloud becomes one of the best choices for former IoT Core users.

In this series of articles, I will deliver a tutorial about the solution for migrating device connections from GCP IoT Core to EMQX Cloud with the same features equipped, and how to link with other cloud services to realize more business demands.

Let’s get started with the deployment creation of EMQX Cloud and devices connection.

EMQX Cloud Introduction

With the infrastructure provided by cloud providers, EMQX Cloud serves dozens of countries and regions, providing low-cost, secure, and reliable cloud services for 5G and Internet of Everything applications. On the one side, millions of devices are connected to the scalable broker hosted on the cloud service in regions. On the other side, data were bridged to various application services for further processing and storing.

MQTT Cloud

Create a cluster hosted on GCP

Assuming you have logged in to the EMQX Cloud Console, I will walk you through cluster deployment step by step. By the way, EMQX Cloud offers a 14-day free trial, with no credit card required. So feel free to explore all that you need.

  1. Choose a plan. Standard Plan is up to 10,000 connections, mainly for data collection and transfer between the device to device or device to the application. It only can be deployed in AWS at present. If you need to integrate with other cloud services in GCP, we recommend Professional Plan provides up to more than 100,000 connections.

    Choose a plan

  2. Choose a region. We recommend choosing the region the same as your other services deployed in GCP.

    Choose a region

  3. Then just click Next and wait for the deployment ready to use.

    Click Next

Connect address and connect port

To connect a device to EMQX Cloud is quite simple. In the deployment console, The most important connection information is displayed in the deployment overview.

connection information

  • Cluster status: status and running time.
  • Number of connections: current number of connections, and the maximum number of device connections supported.
  • Pub&Sub TPS: The peak value contains the total number of messages sent and received per second.
  • Deployment name: the name of the deployment, which can be modified by clicking the edit button on the right.
  • Connection address: IP address for MQTT connection
  • Connection port: 1883(mqtt), 8083(ws) are enabled by default, you can enable 8883(mqtts) and 8084(wss) through Configuring TLS/SSL

Verify device credentials

The device credentials rely on username and password authentication in EMQX Cloud.

  • Set username and password in console or upload a CSV file that contains all the authentication information to console.
  • The device uses a pair of username and password to sign in.

Verify device credentials

In addition to username and password authentication, EMQX supports external authentication, you can verify device via HTTP, importing authentication information from database, and JWT.

MQTT Authentication

In GCP IoT Core, the device uses a private key to sign a JSON Web Token. The token is passed to Cloud IoT Core as proof of the device's identity. Then the topic needs to be registed in Pub/Sub before using in communication.

Compared to GCP IoT Core, connect to EMQX Cloud is simpler. The following samples illustrate how to set up configuration updates on a device over MQTT in Python:

# python 3.8

import random
import time

from paho.mqtt import client as mqtt_client

broker = 'broker.emqx.io'
port = 1883
topic = "python/mqtt"
# generate client ID with pub prefix randomly
client_id = f'python-mqtt-{random.randint(0, 1000)}'
username = 'emqx'
password = '**********'


def connect_mqtt():
    def on_connect(client, userdata, flags, rc):
        if rc == 0:
            print("Connected to MQTT Broker!")
        else:
            print("Failed to connect, return code %d\n", rc)

    client = mqtt_client.Client(client_id)
    client.username_pw_set(username, password)
    client.on_connect = on_connect
    client.connect(broker, port)
    return client


def publish(client):
    msg_count = 0
    while True:
        time.sleep(1)
        msg = f"messages: {msg_count}"
        result = client.publish(topic, msg)
        # result: [0, 1]
        status = result[0]
        if status == 0:
            print(f"Send `{msg}` to topic `{topic}`")
        else:
            print(f"Failed to send message to topic {topic}")
        msg_count += 1


def run():
    client = connect_mqtt()
    client.loop_start()
    publish(client)


if __name__ == '__main__':
    run()

More samples are in client connection guide.

MQTT Client

Upcoming

In the following articles, we will explore some advanced features in EMQX Cloud to adapt your current connection solution, making your migration more seamless and business-non-affected.

  • Use TLS over MQTT

  • Use JSON Web Token to verify device credentials

  • Set up VPC and integrate data to GCP

Please stay tuned!

Try EMQX Cloud for Free
No credit card required
Get Started →

Related Posts