How do I connect my N4 Station to Google Cloud Platform (GCP)?

Quick-start guide to setting-up your N4 Station to push data to GCP using MQTT

GCP IoT Core and MQTT - Quick Overview and Clarification

If you just want to get started, please scroll down to the next section, but it might help to explain a little about GCP IoT Core's use of MQTT as it doesn't really follow the traditional architecture of MQTT. Instead, it really only uses the protocol as a way of communicating with "Devices" in the field to consume data in GCP for different cloud applications or to command "Devices" in the field from GCP applications - it doesn't really operate as an MQTT broker in the true sense where one device publishes and another device can subscribe to the same topic with the broker in the middle provding the link.

So what does it do?

  • It allows Niagara stations to push data or "telemetry" and device state to GCP by publishing to the following specific topics -
    • /devices/DEVICE-ID/events - this is for data/telemetry, e.g. temperatures, kWh etc.
    • /devices/DEVICE-ID/state - this is for device status monitoring in GCP, OK, Down etc.
  • It allows Niagara stations to receive data from GCP in order to receive commands, e.g. setpoint changes, resets, enable commands etc. by subscribing to the following topic -
    • /devices/DEVICE-ID/commands/#

GCP IoT Core uses its own "internal" Pub/Sub topics that perform different functions from the MQTT ones used to collect and distribute "Device" data - this can be confusing, so just be aware of the two different "realms" of topics that are used.

Hopefully that clarifies the basic principles and will help you to understand the following quick-start guides more easily.

Quick-start Guide - Publishing Data from Niagara to GCP

  1. Make sure you or your customer has a GCP account and has access rights to configure IoT Registries and Devices
  2. Log into your GCP Console and open burger menu top left, scroll down to "Big Data" section and select "IoT Core" option (Pin it for easy access while you are there too)

    GCP Console IoT Core Menu
  3. Click "Create Registry" button at top then fill out details as required - 
    1. Name the registry appropriately
    2. Set the region to your closest one, e.g. "europe-west1"
    3. Set an appropriate topic, e.g. MyNiagaraData - all telemetry messages from the Registry's Devices are aggregated to this topic, unless you start using subfolders - more on this later
    4. Click "Show advanced topics"
    5. You only need "MQTT" protocol (for this guide), uncheck HTTP
    6. Set "Cloud Logging" to debug - this will help later to check all is well with comms from N4 station
    7. You DO NOT need to configure "CA Certificate" but you may want to for added security (which is not covered in this guide)
    8. Click "Update" when you have something looking like below -

    GCP Console Add Reg
  4. Click on your new Registry in the main IoT Core menu

    GCP Console IoT Reg Menu
    1. Click on "Devices" in left side menu then click on "Create Device" button at top
    2. Name appropriately
    3. Click "Create" at bottom - we will come back here later to add the "Authentication" public key once created in N4 station

      GCP Console Create Device
  5. In N4 Workbench, connect to your station and -
    1. Add the abstractMQTTDriverNetwork under Config\Drivers
    2. Open the abstractMQTT palette and from "Devices" folder, drag a "GcpMqttDevice" to the above
    3. Set-up parameters as shown -

      N4 GcpMqttDeviceConfig
    4. When added, a public key file will be generated here -


      N4 Public Key File Location
    5. Copy this to a convenient location on your PC hard drive
    6. PLEASE NOTE - you can recreate this at a later date by un-hiding a hidden action slot under "Authentication" slot of your GCP device called "Generate Rsa Keys" then right-clicking on "Authentication" slot and selecting the action
  6. Back in GCP Console go back to the device under IoT Core, your new Registry, then click on the device you are currently working on -
    1. Click on "Authentication" tab
    2. Click on "Add public key" button
    3. Select "Upload" radio button then browse to where you saved the PEM file the GcpMqttDevice in N4 created then click "Add"
  7. Back in Workbench - right click your GcpMqttDevice and select action connect - check status goes to "OK" and Status Message says connected
  8. Add Points as required -
    1. The Topic needs to be in the format; /devices/your GCP device name here/events
      1. Please note - the text in the topic above NOT in bold is specifically what needs to be in the topic, it is not an example, this is how GCP is set up
    2. There is the option to add "subfolders" to additional topics in the GCP Registry set-up/edit view if you want certain messages to publish to topics other than the registry default, e.g. you could create an additional registry topic with a subfolder called "Alarms" and then add it to the end of the topic, i.e. -

      /devices/your GCP device name here/events/Alarms

    3. Check the points are publishing by clicking on your Registry in IoT Core top menu to view details then click on topic (you set in step 3b) under "Pubs/Subs", scroll down and click on "Messages", then select Create Subscription (or select one from the drop-down box if already set up) to associate with your registry topic, name and accept default and press "Pull" button - you should see your publishes coming in

GCP Console IoT Publish check

Quick-start Guide - Receiving Data From GCP to Niagara

  1. Assuming all the above steps have been made (except specific to MQTT publish points), add an MqttStringSubscribePoint to the device's points folder -
    1. Name - your choice
    2. Set Topic to /devices/your GCP device name here/commands/#
  2. Right-click on device and select Actions/Subscribe All
  3. Go to GCP Console IoT Core\Devices and select the device you're working on
  4. Select Send Command from top menu and set format to text, add test message then click Send Command
  5. You should see the message in the output of the subscribe point back in Workbench
  6. This is a simple way of checking the basic comms route is functioning - GCP can be configured to use commands in application coding to write to Niagara points for user interface or more sophisticated automation.

GCP Console IoT Subscribe check