UDOO Quad is a maker SBC board from UDOO. It has a built-in Arduino microcontroller and can run Linux on the SBC. On the web, most of the Google IoT Core samples have been focused using Mongoose OS and I have written a post on "Journey into Google Cloud IoT Core with ESP8266 and Mongoose OS". Recently, Google releases code samples which make the initial handshaking with Cloud IoTCore simpler. For UDOO, the tedious part is to get all supporting tools to work with a particular version of Linux Distribution.
UDOO supports a few Linux distributions (Ubuntu, Debian and others). I have installed Ubuntu and the current version supported by UDOO is 14.04 LTS. For this demo, I wanted to work on Python 3.5 and I have compiled the Python from source. This is step may not be necessary if you use the version that is installed (Python 3.4).
The idea for this project is to read the temperature and humidity reading from UDOO Arduino side, transfer the data to Linux side and forward the data to Google IoTCore. The data is streaming into BigQuery and finally displayed on Google Data Studio. The following are the stages:
The source code for the above is available at GitHub. It also contains a simple Arduino sketch t read data from DHT11.
To execute the code at the shell, the following command is used. Replace the data in the [] with your project id and registry id.
Here is the live link which shows hourly average temperature and humidity.
UDOO supports a few Linux distributions (Ubuntu, Debian and others). I have installed Ubuntu and the current version supported by UDOO is 14.04 LTS. For this demo, I wanted to work on Python 3.5 and I have compiled the Python from source. This is step may not be necessary if you use the version that is installed (Python 3.4).
The idea for this project is to read the temperature and humidity reading from UDOO Arduino side, transfer the data to Linux side and forward the data to Google IoTCore. The data is streaming into BigQuery and finally displayed on Google Data Studio. The following are the stages:
- UDOO Arduino to read from DHT11
- Transfer the data to UDOO Linux core via serial.
- A python script reads the data and put it into Cloud MQTT.
- Cloud IoTCore reads the data and pushes it to Pub/Sub.
- Pub/Sub triggers a Cloud Function that appends the data to BigQuery.
- Data Studio displayed the data on the chart.
Data Flow from UDOO to Google Cloud |
Components Setup
Setting up UDOO to access Google Cloud Platform (GCP)
Setting up IoTCore, Cloud Functions and BigQuery
There are a couple of steps involved in this setup. Firstly for the IoTCore, setting up Google IotCore by following the instructions. IoTCore will create 2 Pub/Sub topics, one for Telemetry Data and the other for State.
Create and configure the Cloud Function to be triggered by the telemetry data topics. The Cloud Function will insert the data into Big Query.
Next, create a Big Query dataset IoTDemo01 and within the dataset, create a table weather. The schema for the table is as shown. For the Big Query schema, normally I will create the column attributes as String. The reason is to prevent failure when inserting and this can be cleanup later or transform using the Big Query SQL.The source code for the above is available at GitHub. It also contains a simple Arduino sketch t read data from DHT11.
To execute the code at the shell, the following command is used. Replace the data in the [] with your project id and registry id.
python3 cloudiot_mqtt.py --project_id [project id] --registry_id [registry id]
--device_id udoo_quad_01 --private_key_file ./key/ec_private.pem --algorithm ES256
--cloud_region asia-east1 --ca_certs ./key/roots.pem
Presenting the Data in Google Data Studio
Finally, after making sure that the data are correctly inserting into Big Query, the final stage is to display the data on a Dashboard. Google Data Studio is a very powerful tool which has a connector that can directly connect to Big Query.Here is the live link which shows hourly average temperature and humidity.
Concluding Thoughts
UDOO Quad is quite a powerful SBC. Technically, installed with Ubuntu, it is capable to connect to GCP directly and insert the data into Big Query using Cloud SDK. The advantage of using Cloud IoTCore is the ability to manage all the devices using a single dashboard. The sending of data back to the devices using Cloud IoTCore will be another feature which will be described in future post
Comments
Post a Comment