Using Fledge with IoT Core on Google Cloud
Contributed by Google employees.
Fledge (previously known as FogLAMP) is an open-source framework contributed by Dianomic for getting data from sensors into data stores. Fledge provides a bridge between sensors that communicate using the South service to Google Cloud as a data store using the North service.
To see an architecture diagram that illustrates the use of Fledge in the context of Google Cloud IoT Core, see the Fledge documentation. That architecture diagram shows HTTPS traffic to a cloud platform; for IoT Core, message traffic can also use the MQTT protocol.
For this tutorial, we use a Raspberry Pi to host the Fledge service.
Set up your Raspberry Pi with the Raspbian Buster image
This tutorial requires that you use the Debian Buster version of the Raspberry Pi software because it uses packages built for that version of Linux.
Download a Raspbian Buster image from the Raspbian downloads page.
Extract the image that you downloaded, which creates a file with a name that ends in
.img
.For example, if you download the full version of Raspbian, the file is named
2019-09-26-raspbian-buster-full.img
.Create the SD card image for your Raspberry Pi using a disk image utility.
Raspberry Pi recommends that you use balenaEtcher.
Flash your Raspberry Pi using the disk image that you created.
For information about flashing your Raspberry Pi, see the detailed instructions in the Raspberry Pi installation documentation.
Set up access to the Raspberry Pi.
- If you intend to access the Raspberry Pi in headless mode, follow the instructions for setting up headless on the Raspberry Pi site.
- If you intend to access your Raspberry Pi locally, connect it to a keyboard, mouse, and display.
Do any final configuration of the Raspberry Pi—such as expanding the filesystem and setting the user password—with the raspi-config utility.
You perform subsequent steps on the Raspberry Pi itself either over SSH if you're working in headless mode or on the Raspberry Pi hardware if you're using the desktop UI.
Download the Fledge packages
Visit the installing Fledge section of the Fledge site and start from the pre-built packages linked in the instructions.
When you receive the email message containing the link to the Fledge packages, copy the link referencing v1.7 for ARM-based devices (Buster), the package for Raspberry Pi devices.
From your Raspberry Pi, use the following commands to download the Fledge packages to the file system and place them in a folder named
foglamp
in your user's home directory. Replace[LINK_FROM_EMAIL]
with the link that you copied in the previous step.mkdir $HOME/fledge cd $HOME/fledge wget [LINK_FROM_EMAIL] tar -xzvf fledge-1.8.0_armv7l_buster.tgz
The
fledge
folder in your user's home directory contains all the resources required for getting your Raspberry Pi up and running.
Install the Fledge service and Fledge GUI on your Raspberry Pi
The Fledge graphical user interface (GUI) makes it easier to configure and control Fledge from your Raspberry Pi.
Browse to the folder that you downloaded the Fledge packages to, and install the Fledge and Fledge GUI packages:
cd $HOME/fledge/fledge/1.8.0/buster/armv7l sudo apt -y install ./fledge-1.8.0-armv7l.deb sudo apt -y install ./fledge-gui-1.8.0.deb
Start the Fledge service and check its status:
export FLEDGE_ROOT=/usr/local/fledge $FLEDGE_ROOT/bin/fledge start $FLEDGE_ROOT/bin/fledge status
Open the Fledge GUI
To open the Fledge GUI, you use your web browser to go to the web server that started running on the Raspberry Pi when you installed the Fledge GUI.
To determine the IP address of your server, run the
ifconfig
command:ifconfig
The output looks similar to the following:
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.217 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::9f73:3b56:93c2:4ed4 prefixlen 64 scopeid 0x20<link> ether dc:a6:32:03:b7:cb txqueuelen 1000 (Ethernet) RX packets 426133 bytes 305815327 (291.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 274458 bytes 172317386 (164.3 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
In this example, the IP address is
192.168.1.217
.Use your web browser to go to the URL for the IP address from the previous step, such as this URL using the value from the previous example:
http://192.168.1.217
When you navigate to the web server, you see a dashboard similar to the following:
Install a Fledge South plugin for generating data
In this tutorial, you install a South plugin for generating and getting data and a North plugin for publishing data to Google Cloud.
One quick way to get some data is with the "randomwalk" plugin.
Install the
fledge-south-randomwalk
plugin:cd $HOME/fledge/fledge/1.8.0/buster/armv7l sudo apt install ./fledge-south-randomwalk-1.8.0-armv7l.deb
In the left pane of the Fledge GUI, click South, and then click the Add + button in the upper-right corner of the South Services window:
Select randomwalk in South Plugin list, give your plugin a name (for example,
random
), and click Next.Click Next again on the next screen, and then click Done.
In the left pane, click Assets & Readings.
You should see random data generated by the South plugin that you just configured.
Install the Fledge North plugin for IoT Core
Now that you have data being generated by the South plugin, you can publish that data to Google Cloud through the IoT Core device bridge.
Install the Fledge North plugin for Google Cloud IoT Core (GCP North plugin):
cd $HOME/fledge/fledge/1.8.0/buster/armv7l sudo apt install ./fledge-north-gcp-1.8.0-armv7l.deb
In the left pane of the Fledge GUI, click North, and then click the Create North Instance + button in the upper-right corner of the North Instances window:
Select the
GCP
plugin, give your instance a name (for example,GCP
), and click Next.
Create a registry
For information on creating registries and devices, see the IoT Core documentation.
Go to the IoT Core page in the Cloud Console.
At the top of the page, click Create registry.
Enter a registry ID (for example,
fledge
).Choose a region (for example,
us-central1
).Select an existing telemetry topic or create a new topic (for example,
projects/[YOUR_PROJECT_ID]/topics/fledge
).Click Create.
After the registry is created, the registry overview page opens.
Create and configure a device for communicating with IoT Core
In this section, you create a device that will be used to transmit data to IoT Core. Before you can register a device, you need to create a key pair used to authenticate the device.
Create an RSA public/private key pair:
cd $HOME/fledge openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048 openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem
Show the contents of the public key:
cat rsa_public.pem
In the left pane of the IoT Core page in the Cloud Console, click Devices.
At the top of the Devices page, click Create a device.
Enter a device ID (for example,
fledge
).Make sure the public key format matches the type of key that you created in the first step of this section (for example,
RS256
).Paste the contents of your public key in the Public key value field.
Click Create.
Configure the North plugin to communicate using your device
Copy the device private key and the root certificate for Google Cloud IoT core to the Fledge certificate store:
wget https://pki.goog/roots.pem cp roots.pem /usr/local/fledge/data/etc/certs/ cp rsa_private.pem /usr/local/fledge/data/etc/certs/
In the Fledge GUI, on the Review Configuration page, enter your Google Cloud project ID, the registry name that you used (
fledge
in the examples used in this tutorial), the device ID (fledge
), and the key name that was created (rsa_private
).Choose the JWT algorithm (RS256) and the data source (typically readings).
Click Next.
Ensure that the plugin is enabled on the following screen, and click Done.
Verify communication
Retun to the Fledge GUI dashboard.
The count of readings sent and received readings should be increasing.
Go to the IoT Core page for your device in the Cloud Console.
Verify that telemetry events are received from the device.
Congratulations! You have set up Fledge to publish data generated on the Raspberry Pi!
To see the telemetry messages, you can create a Pub/Sub subscription.
Create a Pub/Sub subscription to see telemetry messages
On the Cloud Iot Registry details page, click the channel entry in the Cloud Pub/Sub topics section.
Click Create subscription.
Enter the subscription details, such as the name for your subscription (for example,
fledge
), and click Create.
With the subscription created, you can see the messages published by Fledge
using the Google Cloud SDK. The following
command lists the messages published to the fledge
subscription:
gcloud pubsub subscriptions pull --limit 500 fledge
The output includes JSON data corresponding to the generated data, such as the following.
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────┬────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ DATA │ MESSAGE_ID │ ATTRIBUTES │ ACK_ID │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────────────┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ {"randomwalk" : [ {"ts":"2020-01-08 22:22:23.126610","randomwalk" : 100},{"ts":"2020-01-08 22:22:24.126691","randomwalk" : 100},{"ts":"2020-01-08 22:22:25.126676","randomwalk" : 100},{"ts":"2020-01-08 22:22:26.126688","randomwalk" : 99},{"ts":"2020-01-08 22:22:27.126671","randomwalk" : 98}]} │ 928125343880036 │ deviceId=fledge │ IT4wPkVTRFAGFixdRkhRNxkIaFEOT14jPzUgKEUXAQgUBXx9d0FPdV1ecGhRDRlyfWBzPFIRUgEUAnpYURgEYlxORAdzMhBwdWB3b1kXAgpNU35cXTPyztSQrLSyPANORcajjpomIZzZldlsZiQ9XxJLLD5-NSxFQV5AEkw-GURJUytDCypYEU4EIQ │
│ │ │ deviceNumId=2550637435869530 │ │
│ │ │ deviceRegistryId=fledge │ │
│ │ │ deviceRegistryLocation=us-central1 │ │
│ │ │ projectId=glassy-nectar-370 │ │
│ │ │ subFolder= │ │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────────────┴────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Cleaning up
Now that you've seen how the plugin works, you can delete the North instance to prevent data from continuing to be published:
- In the left pane of the Fledge GUI, click North. 1 Select your instance of the GCP plugin.
- Click Delete instance.
Next steps
Fledge provides a robust solution for getting data into Google Cloud using IoT Core. You can readily migrate the data from Pub/Sub to persistent data stores, including the following:
You can analyze the data using Google Cloud Analytics products.
You can evaluate other South plugins such as the SenseHat plugin, which transmits gyroscope, accelerometer, magnetometer, temperature, humidity, and barometric pressure.
You can look into the hardware partners for more robust and secure hardware solutions. The following reference hardware solutions are available from Nexcom:
You can look into advanced usage of the Fledge platform through features such as filters, notifications, and API access to device data with.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.