Part 3 of this series on IBM® Internet of Things Foundation (IoTF) teaches you how to store events published by a device in Cloudant NoSQL database.

In this tutorial, you are going to create a Node-RED flow that will receive and store event data generated by the IoT application you developed in part 1 of this series.

CodifyThings-Getting-Started-IBM-Internet-Things-Bluemix-322

Learning Objectives

At the end of this tutorial you will be able to:

  • Create a new database in Cloudant NoSQL DB
  • Create a Node-RED flow to receive MQTT events
  • Use Node-RED flow to save events in the database

IBM IoTF Setup

Login to Bluemix, you will be redirected to the Dashboard.

Open your IoTF application (WeatherMonitoringSystem) that was developed in part 1. If you look at services included in your application, you will notice that Cloudant NoSQL DB was already added. All IoT applications created using the IoTF boilerplate by default include Cloudant NoSQL DB.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

First, you need to create a new database in Cloudant NoSQL DB that will be used to store data. Under Services, click on Cloudant NoDQL DB.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Click on Launch button to open Cloudant NoSQL DB dashboard.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Click on Create Database to create a new database. Enter weather-db and click Create.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

The newly created database is now visible on Cloudant dashboard.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Switch back to Bluemix dashboard and click the URL on top to open Node-RED instance of your IoT application.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Click on Go to your Node-RED flow editor to open Node-RED editor.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

By default there will be a flow in the editor, you can leave Sheet 1 as-is or delete it. Click on + from top-right to create a new flow sheet.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Double click flow name (sheet name), enter WeatherDBStorageFlow and click Ok.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

From input section drag and drop ibmiot node.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

At this point, your flow should look as follows.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Double click ibmiot node to set properties as shown in the figure below.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Change Authentication from Quickstart to Bluemix Service. Leave Input Type as Device Event. For Device Type, Device Id and Event select All (you can provide specific information as well). Set Format as json, since that is the format device is using to publish data. Click Ok.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

From storage section drag and drop cloudant node.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Double click the cloudant node to set properties as shown in the figure below. Since your IoT app already has a Cloudant NoSQL DB service added, so you do not need to manually enter credentials, simply select your Cloudant NoSQL DB service from the Service drop-down. Enter weather-db in Database field, this is the same name you used while creating a new database in Cloudant. Select insert from Operation. Click Ok.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Connect ibmiot and cloudant nodes.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Click Deploy to make data storage flow available.

Final Product

Make sure your Arduino is powered on and code from part 1 has been deployed. As soon as the code has been deployed, open serial monitor and you will start seeing data publish messages.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Launch Cloudant NoSQL DB dashboard and open your database (weather-db). The All Documents link will list all the JSON documents with humidity and temperature data that have been stored so far.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix

Click on any of the documents to see details.

CodifyThings - Getting Started with IBM Internet of Things Foundation (IoTF) and Bluemix