Skip to main content

How do I connect my BB-400 to Azure?

Cloud computing is the process by which information can be sent over the Internet using a variety of different "pay-as-you-go" services. The BB-400 has a number of cloud services integrated, and this FAQ will explore one of these options: Azure. For more information regarding the other cloud services please refer to the FAQ What Cloud services are available on the BB-400?

Create Azure account

In this section we will explain how to set up a free Azure account, if you would like to buy an Azure account then create an account using the following link: https://azure.microsoft.com/en-gb/pricing/purchase-options/pay-as-you-go/.

Go to the Azure website https://azure.microsoft.com/ and click on Start for free.

Enter your details, you will have to undergo the verification process by phone and card, and then verify your account by email.

Once you have created and verified your account the initial screen will look like as follows:

Azure portal home screen showing service icons, recent resources, and Create a resource button

Setup IoT Hub

In the search bar at the top of the Azure portal, type IoT Hub and click on the result. We will add a new IoT Hub and fill in the following details and click save: Azure IoT Hub directory page with Add button to create a new IoT Hub

Azure IoT Hub creation form with Subscription, Resource Group, Region, and IoT Hub Name fields

Then your IoT Hub is ready to be deployed:

Azure deployment overview showing BB-400-IoT-Hub resource with Created status and deployment details

You will need to use your access keys in the next section. They can be found by going to Shared access policies and clicking on iothubowner:

Azure IoT Hub shared access policies page with iothubowner selected, showing connection string and primary key

Create IoT device

Now we will add our BB-400 to the IoT Hub. Click on the IoT Hub you have just created and scroll down to ioT devices. We will click on New to add our device:

Azure IoT Hub IoT devices page with BB-400-IoT-Hub selected and New button highlighted to add a device

Fill in the details and click save:

Azure Create a device form with Device ID BB-400-00c0, symmetric key authentication, and auto-generate keys enabled

you will now be able to see your device on your IoT Hub:

Azure IoT Hub device list showing BB-400-00c0 with Enabled status and SAS authentication type

Your device will also come with access keys, and they can be found by clicking on your device:

Azure IoT device detail page for BB-400-00c0 showing primary key, secondary key, and connection strings

Connect your device to Azure using Node-RED

Now we are ready to connect our device to Azure using Node-RED. We firstly need to install the Azure IoT Hub nodes and there are 2 ways in which to do this, via command line or manually.

Command Line

The first way is to navigate to the Node-RED directory within your BB-400 terminal:

$ cd node-red-data

type the following command to install the nodes:

$ npm install node-red-contrib-azure-iot-hub

and finally, you will need to restart the Node-RED app so the installed nodes will load up on Node-RED:

$ node-red-restart

Manually install nodes

The other method is to add the nodes using Manage Palette within the Node-RED application.

Click on Manage palette:

BB-400 Node-RED editor with hamburger menu open and Manage palette option highlighted

select the Install tab, type in "node-red-contrib-azure-iot-hub" and click on Install:

Node-RED Palette Install tab with node-red-contrib-azure-iot-hub search result and install button

Once installed, you will see the Azure IoT nodes Node-RED palette cloud section with Azure IoT Hub, Hub Registry, Hub Receiver, and Hub Device Twin nodes on the left hand side of your workspace.

Send BB-400's IO status to Azure

We will firstly drag a websockets input node Node-RED WebSocket input node onto our workspace to send the IO status. Double click on the node and configure it as follows:

Node-RED WebSocket input node config: Type set to Connect to, URL ws://localhost:8989, named WS READ IO Lines

Next, add a function node Node-RED function node to the workspace, connect it to the WebSockets input node and configure it to set up Azure credentials and to send the BB-400's IO data as follows:

Node-RED function node code setting Azure credentials with deviceId, key, protocol, and IO data payload

The device ID is the one you assigned when create your device on the IoT Hub:

Azure IoT Hub device list with BB-400-00c0 Device ID highlighted, showing Enabled status

The "Key" which has been blanked out in the above example, refers to the primary key of your device and can be found by going to your IoT Hub, clicking on shared access policies and then clicking on your device.

Next drag a Azure IoT Hub node and configure it as follows:

Your host name can be found by going to your IoT Hub and clicking on Overview:

Azure IoT Hub overview page with hostname BB-400-IoT-Hub.azure-devices.net highlighted

Finally drag a debug node Node-RED debug node and connect it to the Azure IoT Hub node. The full node configuration to send IO status to Azure looks as follows:

Node-RED flow: WS READ IO Lines, Azure Credentials function, Azure IoT Hub (Sent message), and AzureOutput debug

Click deploy and you should see the IO status being sent to Azure. The Azure node will also have a "Sent message" notification underneath it, as you can see in the image above, if everything has been connected properly.

The debug output looks as follows:

Node-RED debug panel showing AzureOutput with Message sent confirmation from Azure IoT Hub node

Receive the BB-400's IO status from Azure

We will use a Azure IoT Hub Receiver node to receive the IO status messages sent from the BB-400. Configure the node as follows:

Azure IoT Hub Receiver node configuration with connectionString set to BB-400-IoT-Hub endpoint

The connection string refers to your IoT Hub's primary key and can be found here:

Azure IoT Hub shared access policies page with iothubowner selected, showing connection string and primary key

Next drag a json node Node-RED JSON node onto the workspace and connect it to the Azure IoT Hub Receiver node. Finally add a debug node and connect it to the json node and click on deploy.

If everything is connected successfully, the full flow should look like below, including underneath the IoT Hub Receiver node the message "Received",

Node-RED flow: Azure IoT Hub Receiver (Received status), JSON node, and WS SET Outputs (connected status)

you should also see the BB-400's IO status being received by Azure in the debug messages section:

Node-RED debug output showing BB-400 IO status with inputs and outputs arrays received from Azure

This FAQ has allowed you to successfully connect your BB-400 to Azure using Node-RED, you have sent your device's IO status to the cloud, and the cloud has been able to receive the messages.