Skip to main content

How do I connect my BB-400 to Amazon Web Services?

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 several cloud services integrated, and this FAQ will explore one of these options: Amazon Web Services (AWS). For more information regarding the other cloud services please refer to the FAQ: What cloud services are available on the BB-400? NB: This FAQ was written using a BB-400 running Debian GNU/Linux 10 (Buster) and assumes a basic understanding of Node-Red.

What is Amazon Web Services (AWS)?

AWS is a cloud service provided by Amazon. AWS includes an IoT (Internet of Things) Core that allows you to connect your devices to AWS, and also an MQTT client connection to connect Node-Red to AWS. As Node-Red is already set up on the BB-400 by default, AWS is a great method in which to connect your device to the cloud.

Please find at the download link below the Node-Red example flows created for AWS throughout this FAQ:

Downloads
AWS Flow Example

Create your AWS account

First, we need to create an AWS account by going to https://aws.amazon.com and click on “Sign In”:

AWS homepage with Sign In and Create an AWS Account buttons in the top navigation

Click on “Create a new AWS account”:

AWS sign-up page with fields for root user email address and account name, and a Verify email address button

Fill in your details:

AWS sign-up contact information form with fields for name, phone number, country, and address AWS sign-up billing information form with fields for credit card number, expiration date, and cardholder name

Select a support plan:

AWS sign-up support plan selection page

You have set up your AWS account !

AWS congratulations page confirming successful account creation with a Go to the AWS Management Console button

Once registered, login as Root user:

AWS sign-in page with Root user option selected and email address field

You will be presented with the AWS Management console:

AWS Management Console home page showing Cost and usage widget and Applications panel

Register a device

Having created an AWS account, we are ready to register a device. Search for IoT Core in the search bar, then click on “IoT Core”:

AWS Console search results for IoT Core, showing the IoT Core service highlighted under Services

On the side panel click on “Manage” → All devices → “Things” → “Create Things”.

AWS IoT Core Things page under Manage > All devices, with the Create things button visible

Click on “Create a single thing” (AWS defines a device as a “thing”) and follow the steps provided. We will name our “thing” as the last 4 digits of the MAC address of our BB-400 and click next. Select the “No shadow” option for now:

AWS IoT Create things page with Create single thing option selected

The next page is about certificates, click on “Auto-generate a new certificate option”. You will be presented with another window asking you to attach policies:

AWS IoT Attach policies to certificate page at Step 3, showing an empty policies list and Create policy button

Click on Create policy. A policy provides specified permissions to your device. Give your policy a name. Ensure that in the policy effect select: “Allow”, in the Policy action box type: “*”, and Policy resource type: “*”

AWS IoT Create policy page with Policy effect set to Allow, and Policy action and resource both set to wildcard

Going back to the previous Tab, click on “Create things”. You will be presented with a window pop-up to download certificates and keys.

AWS IoT download certificates and keys dialog with links for device certificate, public key, private key, and Root CA files

Download the Device certificate, Public key file, Private key file & Root CA files into a known folder as you will need this later on in Node-Red. Next, click “Done”. You have successfully created your first Thing!

Setup Node-Red to send BB-400’s IO status to AWS.

Now we’ll set up our Node-Red instances so that we can connect to AWS, to send and receive data.

First, we will use an inject node Node-RED inject node to send data. Double-click to configure it as follows:

Node-RED edit inject node dialog named Query BB-400 IO State, with msg.payload set to timestamp and msg.topic set to string

Next, we will use an HTTP Request node Node-RED http request node to send and return a response. Configure it as follows:

Node-RED edit http request node dialog with GET method, URL set to http://127.0.0.1:9000/io, and return type UTF-8 string

Now we will configure the MQTT output node Node-RED mqtt out node to send data to AWS. Double-clicking on the node gives us options for the server name and topic.

On this menu leave the server name blank (we will add it to the next menu), “Qos” and “Retain” values should also be left as blank. Give it a topic name and then click on the pencil next to the server name for further configuration.

NB: The TCP port number is always set to 8883.

Node-RED edit mqtt out node dialog with topic set to Send Data to AWS and server set to Add new mqtt-broker

 

Node-RED edit mqtt-broker node named awsIOT with AWS IoT endpoint as server, port 8883, TLS enabled, and MQTT V3.1.1 protocol

Give the node a name. The Server can be found by navigating to “settings” on the side panel on AWS at the bottom.

 

AWS IoT Core Settings page showing the Device data endpoint URL with a green arrow highlighting the endpoint address

 

Copy the “Endpoint” and paste it as the server in Node-Red. Set the port number to “8883”, keep the client ID blank, and enable TLS connection. Click on the pencil to upload the certificates. Upload the device certificate, private key, and CA certificate that you downloaded earlier from AWS. Click “update” and the node is ready to connect to AWS.

Node-RED TLS configuration dialog with uploaded device certificate, private key, and AmazonRootCA1.pem CA certificate

Finally, add a “debug node”. Node-RED debug node Give it a name and click “done”.

Node-RED edit debug node dialog named BB-400 IO State, outputting msg.payload to debug window

Connect each of the now configured nodes as shown below. The flow is ready to be deployed and you should be connected to AWS.

Node-RED flow with inject, http request, mqtt out, and debug nodes connected to query BB-400 IO state and send data to AWS

Sending BB-400 IO state from Node-Red to AWS

Navigate to IoT Core and click on “Test”. This can be done by navigating to the side pane → Test → MQTT test client.

AWS IoT MQTT test client page with Subscribe to a topic and Publish to a topic tabs

Enter in the “Subscribe to a topic”, the topic name you gave the MQTT out node in Node-Red. Click on “Subscribe” and you should see the IO status events being sent to the MQTT client after redeploying.

In Node-Red:

Node-RED debug output showing BB-400 IO state JSON with counts, inputs, and outputs arrays

In AWS MQTT test client:

AWS MQTT test client showing received BB-400 IO state data with counts, inputs, and outputs arrays on the Send Data to AWS topic

Send a message from AWS to Node-Red

You can also set up a flow to receive events from AWS.

 

We will use a “MQTT input node” Node-RED mqtt in node instead, and set it up with the same settings as before. Give it a Topic name. If you named your previous server, you should be able to click on this in the drop-down. We will use a debug node for the output.

Node-RED edit mqtt in node dialog with server set to awsIOT, subscribing to Cloud/data topic with QoS 1

Node-Red flow:

Node-RED flow with mqtt in node subscribed to Cloud/data connected to a Data from AWS debug node, showing connected status

Heading back to AWS MQTT client, click “Publish to a topic” → Enter the topic name you gave the MQTT in Node-Red. In the message payload, edit the message to your liking → click on “Publish”.

AWS IoT MQTT test client Publish to a topic tab with Cloud/data topic and Hello from AWS IoT console message payload

You should be able to see the message (“Hello from AWS IoT console”, in this case) in the debug message in Node-Red:

Node-RED debug output showing received message object with Hello from AWS IoT console on the Cloud/data topic

Sending serial data to the cloud.

The example below demonstrates using one of our ES-511 devices to send serial data to AWS. We’ll start by using an “inject node” to send a string and another to send an integer. Configure the nodes as follows:

String Inject Node:

Node-RED edit inject node dialog named Inject String with msg.payload set to the string ThisIsATest

Integer Inject Node:

Node-RED edit inject node dialog named Inject Integer with msg.payload set to timestamp

Next, we’ll use a “random” node Node-RED random node to generate an integer between 1 and 100. Configure it as follows:

Node-RED edit random node dialog named Random Integer, generating a whole number between 1 and 100

Configure the “TCP request” node as shown below. Ensure your ES device is set to RawTCP and has a physical loopback on the serial port. The “Server” is the IP address of your ES device.

Node-RED edit tcp request node dialog named Connect To ES with server 192.168.0.57 port 9001, returning string

Configuring a loopback test:

Serial loopback wiring diagram for RS-232 (TXD pin 2 to RXD pin 3) and RS-422/485 (TXD+/- to RXD+/-)

Please note for RS422/485 pins out may vary.

We’ll configure three debug nodes to monitor the sent string, sent integer, and received payload. Name them respectively.

Example of sent string debug node:

Node-RED edit debug node dialog named Sent String, outputting msg.payload to debug window

Now make a copy of the “MQTT Out node” used previously and integrate it into the flow as shown below:

Node-RED flow sending serial data via ES-511: inject nodes for string and integer, random node, TCP request to ES device, with debug and MQTT out to AWS

After triggering the inject nodes, the expected output is as follows:

Node-Red:

Node-RED debug output showing sent string ThisIsATest and received payload, plus sent integer 71 and received payload 71

AWS:

AWS MQTT test client showing received serial data messages: integer 71 and string ThisIsATest on the Send Data to AWS topic

Sending IO state to the cloud

In this example, we’re generating an ASCII command from within Node-Red, passing it to an ED device, and sending the ED’s response to the cloud. Configure the nodes as follows:

Inject Node:

NB: the repeat interval can be adjusted to your preference.

Node-RED edit inject node dialog named Send ASCII Command with msg.payload set to timestamp

Function Node:

Node-RED edit function node named Format ASCII Command with code setting msg.payload to the ASCII command @01

TCP Request Node:

Node-RED edit tcp request node dialog named Connect to ED with server 192.168.0.37 port 9500, returning string

Sent ASCII Debug Node:

Node-RED edit debug node dialog named Sent ASCII Command, outputting msg.payload to debug window

Received Hexadecimal Response debug node:

Node-RED edit debug node dialog named Received Hexadecimal Response, outputting msg.payload to debug window

Join the nodes as shown below:

Node-RED flow sending ASCII commands to an ED device: inject, function, TCP request to ED, with debug nodes and MQTT out to AWS

Examples of output expected after triggering the inject node:

Node-Red:

Node-RED debug output showing sent ASCII command @01 and received hexadecimal responses >00FE and >00FF from the ED device

AWS:

AWS MQTT test client showing received ED device hexadecimal IO state responses >00FF and >00FE on the Send Data to AWS topic

In this FAQ we have explained how to create an AWS account, connect your device to AWS, configure certificates and a policy, and finally how to setup Node-RED to send and receive the BB-400's IO status.