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.
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.
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.
Click on Launch button to open Cloudant NoSQL DB dashboard.
Click on Create Database to create a new database. Enter weather-db and click Create.
The newly created database is now visible on Cloudant dashboard.
Switch back to Bluemix dashboard and click the URL on top to open Node-RED instance of your IoT application.
Click on Go to your Node-RED flow editor to open Node-RED editor.
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.
Double click flow name (sheet name), enter WeatherDBStorageFlow and click Ok.
From input section drag and drop ibmiot node.
At this point, your flow should look as follows.
Double click ibmiot node to set properties as shown in the figure below.
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.
From storage section drag and drop cloudant node.
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.
Connect ibmiot and cloudant nodes.
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.
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.
Click on any of the documents to see details.