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: Amazon Web Services. For more information regarding the other cloud services please refer to the FAQ What Cloud services are available on the BB-400?

In this FAQ we will explain how to create a Amazon Web Services (AWS) account, and how to setup your BB-400 Node-RED instance to send the IO status to AWS, as well as showing how AWS can send data to the BB-400.

What is AWS?

AWS is a cloud service provided by Amazon. AWS includes a IoT Core that allows you to connect your devices to AWS, and also 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.

Create your AWS account

The first step is to create your AWS account. Go to https://aws.amazon.com/ and click on "Create a Free Account".

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-initial-page.png

Fill in your details,

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-create-account.png

select a support plan

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-select-plan.png

and wait for activation.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-welcome.png

Once registered. and logged in, you will be presented with the AWS Management Console.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-welcome-page.png

Register a device

Now that we have created our AWS account we are ready to register our device. We will document the steps required to register a device below, but feel free to refer to the AWS IoT Register Device guide instead.

Click on "Connect an IoT device"

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-connect-a-device-button.png

and then "Create a single thing", AWS defines devices as a "thing".

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-create-a-single-thing.png

The next step is to Register a thing, by providing a name, type and group

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-add-device-to-registry.png

and click on the "One-click certificate creation", recommended option.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-download-connection-kit.png

Here we can see that a few files have been created: a certificate for the device, a public key and a private key. Please note that if you do not already have a root CA, you will need to download one to connect your device to AWS. Please follow the steps provided to download a root CA.

Next, click on Activate and proceed to "Attach a policy." A policy provides specified permissions to your device. Give your policy a name and ensure that in the Action box you type "iot:*" and check the "allow" Effect box.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-policy.png

Next we need to attach the policy to the certificate to provide permissions to the device.

On IoT navigate to Manage, click on your thing, go to Security and click on your certificate.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-certificate.png

Clicking on the three dots on the certificate will bring up a drop-down menu, we want to click on the Attach policy option.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-attach-policy.png

Next we need to attach our certificate to our thing.

Again, click on the drop-down menu, but instead click on Attach thing and select your device.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-attach-thing.png

Now we have finished setting up our AWS account, and configuring our device with the correct certificate, keys and policy.

Setup Node-RED to send BB-400's IO status to AWS

Now we will setup our Node-RED instance so that we can connect to AWS, and send and receive data.

Firstly, we will use a WebSocket input node http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-websocket-input-node.png to send the IO status, and configure it as follows:

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-websocket-input-node-configuration.png

The Type should be changed to "Connect to", and the URL should be set to "ws://localhost:8989/" where 8989 is the port number of the WebSocket port.

Next we will use a json node http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-fred-json-node.png to convert the string to a object, and connect this to the WebSocket input node.

Now we will configure the mqtt output node http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-amazon-mqtt-node.png to send data to AWS.

Double clicking on the node gives us options for server name and topic.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-mqtt-node.png

Leave the server name, QoS and Retain values blank, type in a topic name and then click on the pencil next to the server name for further configuration.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-mqtt-server-config.png

The server name can be found by going to IoT Core -> Manage, clicking on your thing and going to Interact. The HTTPS REST API Endpoint is the server name.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-mqtt-node-server-name-rest-api-endpoint.png

Set the Port number to 8883, keep the Client ID blank and then click on the pencil for the next step, which is to upload the certificates.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-mqtt-node-configuration.png

Upload the device certificate, private key and CA certificate.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-mqtt-node-upload-certificate.png

Click update and the node is ready to connect to AWS.

Finally, add a debug node http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/Node-REDapp-watson-debug-node.png and connect it to the json node.

Now the flow is ready to be deployed and you should be connected to AWS. Below is the flow that we have just created.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-send-node-flow.png

See events being sent from BB-400's Node-RED on AWS

Navigate to IoT Core and click on Test. The MQTT client will connect to the device. Enter in the Subscription topic, which should be the same as the topic name you gave the MQTT node in Node-RED.

Click on Subscribe to topic and you should see the IO status events being sent to the MQTT client.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-mqtt-demo1-output-from-node-red.png

Send message from AWS to Node-RED

You can also setup a flow to recieve events from AWS. We will an mqtt input node instead and set it up with the same settings as before. We will use a json node, a debug node and a websocket output node.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-websocket-output-node.png

Going back to AWS MQTT client, change the message to set the outputs to off:

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-outputs-1.png

Clicking on deploy should set all the outputs to off.

Below is the flow to send a message to set the outputs off, from AWS to the BB-400.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-do-i-connect-the-bb-400-to-amazon-web-services-receive-node-flow.png

Export flows

Below is the Node-RED flow that we have created in this FAQ. You can copy the flow and paste it into your Node-RED instance. Remember to update your nodes accordingly and upload your certificates.

[
    {"id":"10650605.d6c23a","type":"tab","label":"Flow 1","disabled":false,"info":""},
    {"id":"9e555a1d.863c78","type":"mqtt out","z":"10650605.d6c23a","name":"Send To Amazon","topic":"Demo1","qos":"","retain":"","broker":"df38e4e8.898eb8","x":555,"y":153,"wires":[]},
    {"id":"6cb435ea.70f85c","type":"debug","z":"10650605.d6c23a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":534,"y":63,"wires":[]},
    {"id":"393bcdf.fbb7832","type":"mqtt in","z":"10650605.d6c23a","name":"Receive","topic":"Demo1","qos":"0","datatype":"auto","broker":"df38e4e8.898eb8","x":118,"y":297,"wires":[["f3f4eab5.229438"]]},
    {"id":"7b930bce.471ec4","type":"debug","z":"10650605.d6c23a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":488,"y":268,"wires":[]},
    {"id":"b6c1680e.8baa18","type":"websocket out","z":"10650605.d6c23a","name":"WS SET Outputs","server":"","client":"372ea2b0.b035ee","x":510,"y":350,"wires":[]},
    {"id":"fc7b4070.b9c1b","type":"websocket in","z":"10650605.d6c23a","name":"WS READ IO Lines","server":"","client":"6f6cf88.4fb6008","x":130,"y":121,"wires":[["b4b4a8f6.001628"]]},
    {"id":"b4b4a8f6.001628","type":"json","z":"10650605.d6c23a","name":"","property":"payload","action":"","pretty":false,"x":323,"y":124,"wires":[["6cb435ea.70f85c","9e555a1d.863c78"]]},
    {"id":"f3f4eab5.229438","type":"json","z":"10650605.d6c23a","name":"","property":"payload","action":"","pretty":false,"x":288,"y":297,"wires":[["b6c1680e.8baa18","7b930bce.471ec4"]]},
    {"id":"df38e4e8.898eb8","type":"mqtt-broker","z":"","name":"Send Data","broker":"acd8ikn1p1odq-ats.iot.us-west-2.amazonaws.com","port":"8883","tls":"e0a89ed.804846","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},
    {"id":"372ea2b0.b035ee","type":"websocket-client","z":"","path":"ws://localhost:8989","tls":"","wholemsg":"false"},{"id":"6f6cf88.4fb6008","type":"websocket-client","z":"","path":"ws://localhost:8989/","tls":"","wholemsg":"false"},{"id":"e0a89ed.804846","type":"tls-config","z":"","name":"bb400","cert":"","key":"","ca":"","certname":"ADD-certificate.pem.crt","keyname":"ADD-private.pem.key","caname":"ADD-root-CA.crt","servername":"","verifyservercert":true}
] 

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.