2 - Building An IoT Analytics Pipeline On Google Cloud
2 - Building An IoT Analytics Pipeline On Google Cloud
2 - Building An IoT Analytics Pipeline On Google Cloud
Overview
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.
The service connects IoT devices that use the standard Message Queue
Telemetry Transport (MQTT) protocol to other Google Cloud data services.
Cloud IoT Core has two main components:
In this lab, you will dive into Google Cloud's IoT services and complete the
following tasks:
Connect and manage MQTT-based devices using Cloud IoT Core (using
simulated devices)
Ingest a stream of information from Cloud IoT Core using Cloud Pub/Sub.
Prerequisites
BigQuery
Cloud Pub/Sub
Dataflow
IoT
If you want to get up to speed in any of the above services, check out the
following Qwiklabs:
2. Scroll down in the list of enabled APIs, and confirm that these APIs are
enabled:
o Cloud IoT API
o Cloud Pub/Sub API
o Dataflow API
If one or more API is not enabled, click the ENABLE APIS AND
SERVICES button at the top. Search for the APIs by name and
enable each API for your current project.
In an IoT solution built with Cloud IoT Core, device telemetry data is forwarded to
a Cloud Pub/Sub topic.
iotlab
4. Then click CREATE TOPIC.
Test Completed Task
[email protected]
7. From the Select a role menu, give the new member
the Pub/Sub > Pub/Sub Publisher role.
8. Click Save.
Test Completed Task
5. Name the dataset iotlabdataset, leave all the other fields the way they
are, and click Create dataset.
6. You should see your newly created dataset under your project:
2. Click CREATE BUCKET.
6. Click CREATE.
A new streaming job is started. You can now see a visual representation of the
data pipeline.
exit
7. Start another SSH session on the iot-device-simulator VM instance
and execute the following command to activate the virtual environment.
source venv/bin/activate
8. Initialize the gcloud SDK.
gcloud init
If you get the error message "Command not found," you might have forgotten to
exit your previous SSH session and start a new one.
If you are asked "Are you sure you want to authenticate with your personal
account? Do you want to continue (Y/n)?" enter Y.
9. Click on the URL shown to open a new browser window that displays a
verification code.
10. Copy the verification code and paste it in response to the "Enter
verification code:" prompt, then press Enter.
11. In response to "Pick cloud project to use," pick you lab project.
12. Enter this command to make sure that the components of the SDK
are up to date:
export PROJECT_ID=
Your completed command will look like this: export PROJECT_ID=qwiklabs-
gcp-d2e509fed105b3ed
2. You must choose a region for your IoT registry. At this time, these regions
are supported:
us-central1
europe-west1
asia-east1
Choose the region that is closest to you. To set an environment variable
containing your preferred region, enter this command followed by the region
name:
export MY_REGION=
Your completed command will look like this: export MY_REGION=us-central1.
cd $HOME/training-data-analyst/quests/iotlab/
openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem \
-nodes -out rsa_cert.pem -subj "/CN=unused"
This openssl command creates an RSA cryptographic keypair and writes it to a
file called rsa_private.pem.
cd $HOME/training-data-analyst/quests/iotlab/
wget https://pki.google.com/roots.pem
2. Enter this command to run the first simulated device:
python cloudiot_mqtt_example_json.py \
--project_id=$PROJECT_ID \
--cloud_region=$MY_REGION \
--registry_id=iotlab-registry \
--device_id=temp-sensor-buenos-aires \
--private_key_file=rsa_private.pem \
--message_type=event \
--algorithm=RS256 > buenos-aires-log.txt 2>&1 &
It will continue to run in the background.
python cloudiot_mqtt_example_json.py \
--project_id=$PROJECT_ID \
--cloud_region=$MY_REGION \
--registry_id=iotlab-registry \
--device_id=temp-sensor-istanbul \
--private_key_file=rsa_private.pem \
--message_type=event \
--algorithm=RS256
Telemetry data will flow from the simulated devices through Cloud IoT Core to
your Cloud Pub/Sub topic. In turn, your Dataflow job will read messages from
your Pub/Sub topic and write their contents to your BigQuery table.
Cloud IoT Core supports two protocols for device connection and communication:
TCP
HTTP
SMTP
IP
MQTT
Submit
When you create a device within a registry, you define the device as a Cloud IoT Core resource.
True
False