Google IoT Core Node-RED Connection Node Follow
Overview
The Google IoT Core Connection node provides a connection to a configured instance of the Google IoT Core for device data collection in the Google Cloud. When configured correctly, the node will upload any incoming messages to the Google Cloud.
This article assume setting up a project within Google Cloud has been completed. For information regarding the set up of gateways within Google Cloud, please see the example at the end of this article. Knowledge of the following articles is recommended before proceeding.
- MobiusFlow Architecture
- Node-RED Flows
- Mobius Core node-RED Nodes
- Mobius Cloud Format & Store and Forward Nodes
Node Properties
The Google IoT Core Connection node uses 5 properties to configure the node to connect the Google Cloud. These are shown below and explained in the following sections.
Project ID
The 'Project ID' property is found by clicking the project name outlined in red in the window below.
The Project ID can be found next to the project name. In the window below, the 'Project ID' is 'cobalt-nomad-252415' outlined in red.
Cloud Region
The property allows for the selection of the region of operation. The three options are us-central1, europe-west1, and asia-east1. This should be selected depending on which country the Mobius gateway is located.
Registry ID
The Registry ID can be found by selecting the active registry within IoT Core. The Registry ID is then presented to the user as outlined in red below.
Gateway ID
The 'Gateway ID' can be found by selecting the gateway set up within IoT Core. The Gateway ID is then presented to the user-outlined in red below.
Private Key File
The 'Private Key File' property must contain the name of the local file stored on the Mobius gateway containing the RSA private key which is paired to the public key used within IoT Core. This will most likely be called 'rsa_private.pem'. For more information about acquiring these key pairs and setting them up to work this Mobius, please see the example within this article.
Connection Status
Connected
If configured correctly, the Google IoT Core Connection node connects to the device within the Google Cloud. The node will show connected status as seen below.
When connection is made, the node will output a message containing the storeFwdControl (msg.storeFwdControl) property. The property will be set to true causing any connected Store and Forward nodes to enter forwarding mode. A typical setup with a Store and Forward node is shown in the diagram below. For more information on the Store and Forward node Mobius Cloud Format & Store and Forward Nodes.
Disconnected
If the node loses connection, a message will be outputted with the storeFwdControl parameter set to 'False'. This will send the Mobius Store and Forward node into store mode until such a time connection is reestablished.
Example
Setting up Google IoT Core - Instructions
This example assumes you have already set up a project within Google Cloud. On the Google Cloud home page open the main menu shown in red below. Then navigate to IoT Core shown in orange below.
Creating Registry
Once at the Google IoT Core home, a registry can be created by pressing the button outlined in red below.
The registry creation wizard prompts the user to enter a Registry ID. For the purposes of this example, the Registry ID has been set to 'exampleRegistryA' shown in red below. The wizard will also prompt the user to create a new telemetry topic. This is created using the drop-down box shown in orange below. The window following the window below shows the telemetry topic creation process. The create button, marked in green, can then be pressed to confirm the creation of the new registry.
Within the topic creation window, any name can be given to the new topic. The name given in this example is 'exampleTopic' shown in red below. The create button can then be pressed, shown in orange, to confirm the creation of the new topic.
Creating Gateway
Within the newly created registry, a new gateway object can be created. This can be created by navigating to gateways within the menu, shown in red below, and then clicking on 'create a gateway' outlined in orange below.
Within the gateway creation wizard, the Gateway ID must be added. In this example, the name 'exampleMobiusGatewayA' has been used, shown in red below. The remainder of the fields can be left to the default values and then the create button, outlined in orange, can be pressed.
Generating Keys
Once the gateway has been created, an RSA private/public key pair must be generated to securely link Mobius and IoT Core. Within the Google Cloud Platform, a shell can be opened by pressing the button outlined in red.
Once the shell is open, the following commands can be run in order to generate both public and private keys.
openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem
The commands being run within the shell are shown below.
These commands have generated the files rsa_private.pem and rsa_public.pem containing the private and public keys respectively. The public key must be copied into the gateway set up within IoT Core. To obtain the public key, use the following command to view the file containing it.
nano rsa_public.pem
The contents of this file should be copied to the clipboard. Ctrl + X can then be used to close the file within the shell. Please note, the entire file contents must be copied including the begin and end of key markers. The selection is shown in the window above.
Within the shell options, the download file option should be selected to download the file containing the private key. This option is outlined in red below.
Within the download file menu, the filename 'rsa_private.pem' should be entered as shown in red below. The download button, shown in orange, will download the file to the user's local machine.
Within the created gateway in IoT core, the 'Add public key' button, outlined in red below, should be selected.
The menu prompts the user to add the public. This key was copied earlier so it can simply be pasted into this field. An example public key is shown within the field, outlined in red, below. All other options can be left as the default values and the 'Add' button can be pressed. This is shown in orange.
The gateway has now been set up with the appropriate public key to be used with Mobius.
Setting up Mobius
Within Mobius, the HTTP(s) menu of the Administration tab should be navigated to. The administration tab is outlined in red below. A file containing the private key must be uploaded to the Mobius gateway. This is achieved by pressing the upload button, outlined green, and navigating to where the file was previously saved. Once selected, the apply button can be pressed. This is outlined in white in the window below.
The following flow has been generated for the purposes of this example. The flow uses several nodes without explanation. The articles containing more information on the function and configuration of these nodes are listed below.
- Set Resource - See Mobius Core
- Mobius Flow Inject - See Mobius Core
- Mobius Cloud Format - See Mobius Cloud Format & Store and Forward Nodes
- Store and Forward - See Mobius Cloud Format & Store and Forward Nodes
The Google IoT Core Connection node is configured for use with the properties found in the previous sections of this example. Please note, the 'Private Key File' property of the Google IoT Core Connection node has been set to 'rsa_private.pem' to match the name of the file containing the private key previously uploaded. The node shows the connected status to show it has successfully connected to the device within Google Cloud. For more information on how to obtain the credentials to configure this node, please the Node Properties section of this article.
The two inject nodes, labeled 15 and 16, inject messages to the Set Resource node which changes the temperature resource (URI - 000001/020/0034/0001/40) of the Temperature/Humidity sensor to 15 or 16 degrees respectively. The inject nodes are set to inject data every few seconds, simulating a sensor with a constantly changing reading.
The Mobius Flow Inject node is subscribed to changes to the Temperature/Humidity sensor so it sends a message whenever the temperature reading changes. The message then passes through the Mobius Cloud Format node. These nodes prepare the data to be uploaded into the Google Cloud.
Finally, the data is relayed by the Store and Forward node to the Google IoT Core Connection node ready for upload. The output is fed back into the Store and Forward to automatically stop the Store and Forward node forwarding if connection to the Google Cloud is lost, see Connection status section within with article for more details.
Operation
The flow is deployed and the inject nodes begin sending continuous data to simulate a constantly changing temperature reading. This uploads a continuous temperature data stream to the Google Cloud.
To view the incoming data, the following procedure can be followed. Within the main Google Cloud menu, shown in the red box below, select the Pub/Sub menu shown in orange below.
On the Pub/Sub menu, select subscriptions shown in red. When on the subscriptions page, create a new subscription by pressing the 'Create Subscription' button outlined in orange.
On the create subscription wizard, the user is prompted to fill in several fields. The subscription ID should be given a relevant name. Below this is outlined in red using the name 'exampleSubA'.
The topic name, shown in orange, should match the name of the topic created when the gateway object was created in IoT core. In this example, the topic name was 'exampleTopic'. The field must include the prefix projects/<project-id>/topics. This means the full string in this instance including the prefix is projects/cobalt-nomad-252415/topics/exampleTopic.
Under the delivery type option, ensure 'Pull' is selected. This is outlined in blue below.
The remaining fields can be configured for the desired results. In this example, they are left as the default values. The create button can then be pressed to confirm the creation of the subscription. This is shown in green below.
Having created the new subscription, re-navigate to the topics menu outlined in red. Select the topic created when the gateway was initially created. In this example, the topic name is 'exampleTopic'. This is outlined in orange below.
Within the selected topic, the 'View Messages' button can be pressed to view the incoming messages. This is shown in red below.
Within the messages window, the subscription previously created must be selected. In this example, the subscription created is called 'exampleSubA'. This is what is selected from the list, shown in red below.
Having selected the subscription, the user is prompted to pull the data. When the pull button, shown in red, is pressed, the data from the gateway will be pulled into the topic. The incoming messages can be seen in the list, shown below in orange.
This shows information has been successfully transferred from Mobius into Google Cloud.
Comments
0 comments
Please sign in to leave a comment.