2.4. Sending sensor data from Node-Red BLE to Amazon DynamoDB

2.4.1. Introduction

In this tutorial we will write an application on the Gateway that will connect a Node-RED program to a DynamoDB instance.

2.4.2. Set up DynamoDB on AWS

  1. Navigate to https://aws.amazon.com/ to get started.
  2. If you don’t already have one, create a new AWS account.
  3. Log in to the Console. Creating a DynamoDB table

  1. Select the DynamoDB service.

  2. Verify that the Region selected in the upper right corner is the one in which you wish to create the database.


    Figure 2.1 The Region selection menu

  3. Click Create table to begin the wizard. Fill in the following values:

    • Table name: BLEScanning
    • Primary key: deviceID (String)
    • Add sort key: checked
    • Primary sort key: date (Number)


    If you modify these values, you will also need to modify the Node-Red Flow named Format PutItem

  4. Click Create to finish creating the table.


For more information about DynamoDB, see Amazon’s Getting Started with Amazon DynamoDB guide. Creating a Group

  1. In the upper left corner, open the Services menu. Select the IAM service.

  2. In the menu on the left, select Groups and then click the Create New Group button at the top.

  3. Give the group a relevant name, like DynamoDB-Readers. Click Next Step.

  4. Select the AmazonDynamoDBFullAccess policy. Click Next Step


    If your application requires more granular control of the permissions, you can create a new policy that only allows read/write access on the one DynamoDB instance. To enable this you’ll need the Amazon Resource Name (ARN) of the DynamoDB. For more information creating custom policies, see Amazon’s Creating a New Policy guide.

  5. Click Create Group. Creating a User

Follow the procedure in Amazon’s guide to create a new user.

Make sure you enable Programmatic access and add the user to the group you created earlier.

On the final page, make sure you copy or download the access key ID and secret key of the user.

2.4.3. Running Node-RED Connect

Rigado Vesta Gateways come pre-configured with Node-RED. The Gateway will start Node-RED when it boots. There are two ways to begin interacting with the Node-RED application:

  1. Connect the Gateway to Ethernet. Then, using a computer connected to the same network, open a web browser page to the Gateway’s unit serial number with the suffix .local (e.g. http://b014012917-00065.local).
  2. Run through the process to connect the Gateway to your local Wi-Fi network (see Setup Wi-Fi with the Wi-Fi configuration app). At the end of this process will be a page with a link to the Node-RED application. Click the link once the Gateway has finished rebooting. Import the flow

Once you’re looking at the Node-RED application, import the DynamoDB example flow by selecting it from the menu in the upper-right corner.


Figure 2.2 Importing the example flow.


Figure 2.3 The DynamoDB flow


Out of the box, the Gateway will run the “Rigado DevKit” flow, which is designed to connect to Nordic Thingy:52 devices and send their sensor data to AWS. If you aren’t using that flow, you can delete it from the settings menu.


Figure 2.4 With the “Rigado DevKit” flow selected, open the menu and hover over Flows. Click Delete to remove the flow.

To learn more about the DevKit, see Dev Kit: Sending Nordic Thingy data to Amazon Web Services. Configure BLEScanning

You will need to configure the flow with your AWS credentials. Double-click on the BLEScanning node. Then click the pencil to update/add the config:


Figure 2.5 Editing the BLEScanning node

Add credentials for the user you created with limited access to write into the DynamoDB service:


Figure 2.6 Adding AWS user credentials to the BLEScanning node

Close by clicking the Update and then the Done red buttons. Running the Flow

Click Deploy to run:


Figure 2.7 Deploying the flow

Watch the Debug tab on the right side for issues.

It may be useful to disconnect the “limit 1 msg/s” and “BLEScanning” nodes so you can separately debug them. Just click on the connecting wire and then press Delete. Replace the wire by dragging from the output handle of “limit 1 msg/s” to the input handle of “BLEScanning”.

It is also worth noting the delay node (“limit 1 msg/s”), here configured to rate-limit 1 message per second and dropping intermediate messages. Running this flow without this rate-limit will result in a very large throughput to Amazon DynamoDB. This will quickly consume any available throughput for trial accounts. It is not recommended to run this flow without the delay node. However, you may want to tailor the delay to optimize your application. See Amazon’s guide on Provisioned Throughput for more information.

2.4.4. Testing

Enable either of the debug output nodes to see the responses from putting an item into DynamoDB or the formatted BLE data received from a scan.

Log into AWS DynamoDB and check that new data is arriving in the Tables > Items view.


Figure 2.8 Items inserted into the table

For more precise debug information, connect to the Gateway and run the command cat /var/log/node-red/node-red.log. Alternately, you could “follow” the log file with the command tail -f /var/log/node-red/node-red.log.

If you need to restart Node-RED, you can do so by connecting to the Gateway and running the command /etc/init.d/node-red restart.

2.4.5. Scan only certain UUIDs

The Scan BLEs node has a config item for restricting to certain Service UUIDs. Double-click the Scan BLEs node to set this config. You can also see on the “info” tab that there are other properties that are returned, for example, if the advertisement is the iBeacon format.

Find a Service UUID of your target devices with the Rigado Toolbox App.

RigadoToolboxiTunesBadge RigadoToolboxAndroidBadge