Getting started with Watson IoT Platform using NodeRED

In case you are using the same Node-RED application for both device and application, create a separate sheet in the Node-RED editor for the application to distinguish the application flow from the device flow.

As shown, it creates 2 rules based on the temperature value. Temperature value equal to or below 30 flows through route 1 and temperatures above flows through route 2.

// Array of pseudo random relative humidities

One can install Node-RED locally on the laptop or any devices like Raspberry Pi to send sensor readings to Watson IoT Platform. Refer to the recipe,Connecting Raspberry Pi as a Device to Watson IoT Platform using Node-REDto use Node-RED on a Raspberry Pi to connect to Watson IoT Platform and send sensor data. Similarly follow the steps present inthis tutorialto install Node-RED locally on your laptop and add Watson IoT and IBM IoT App nodes.

We are trying to develop server application (Node.js) that will monitor the temperature and send Green, Red command to Raspberry Pi. We are referring your tutorial for this. We have all the credentials for registered device. After creating full flow till 6th step there is an error in debug console: Error: [BaseClient:disconnect] Client is not connected. IBM IoT input node gets disconnected when the IBM IoT output node gets connected & vise-versa. Please help us to get out of it

How to configure the Watson IoT Output node to send device events to Watson IoT Platform.

node to view the payload in the debug panel. The complete flow should look like the following,

Extend your hands-on experience with visualization and analytics on Watson IoT Platform:

Once the deploy operation is successful, open the Node-RED application (refresh if its opened already) to see the

In this recipe, we will simulate a temperature device using the Watson IoT Node that will send the temperature readings to Watson IoT platform every 1 second. An application will subscribe to these temperature events and trigger a shut down command when the temperature crosses 30 degree Celsius.

Watson IoT Node A pair of nodes for connecting your device or gateway to the IBM Watson Internet of Things Platform. A device or gateway can use these nodes to send events and receive commands from the application.

In order to connect the Node-RED application to IBM Watson IoT Platform to receive device events and send commands, we need to generate the API key and token first. This can be achieved by carrying out the steps mentioned in this section Steps to generate API Key in Watson IoT Platform.

Helps monitor specific status and data of a given device, from a list of multiple devices, using various visualization options with a click of a button

How to configure the IBM IoT App In node to receive the device events.

node as shown below to output the commands into the debug panel,

Now if i select authehication: API KEY

Tagsapplication,bluemix,cloud,Device,ibm watson iot platform,ibmiotf,IoT,iotf,node,Node-RED,node.js,watson,watson iot

Real-time data analytics in Watson IoT Platform

msg.payload=JSON.stringify(data:Shutdown);

On your devices Node-RED instance, add an

. And connect it to the second output ofclassify node. Paste the below code to send the command to the device when the temperature rises above 30 degrees.

Note: If you are aUserusing theUnited Kingdom Regionin your Bluemix environment, then please make use of the steps mentioned in the IoT RecipeDeploy Internet of Things Platform Starter service on Bluemixto deploy the setup. Alternatively, you can also try using theDeploy to Bluemixbutton, to deploy the setup under yourUnited Kingdom Region, provided your Jazzhub account is validated.Users of US South Region can ignore this step.

How to configure the Watson IoT Input node to receive the commands from the application

In this step we will use the switch node to analyze the temperature and classify it as safe or unsafe.

Temperature (payload) within safe limits

How to configure the IBM IoT App In node to receive the device events.

Parallelly, you can also access the Node-RED editor directly by accessing the following URL

This recipe will help you to connect your Devices, Gateways and Applications to Watson IoT Platform using NodeRED.

In this step, we have successfully configured the IBM IoT App In Node to receive the temperature reading from the Watson IoT Platform.

Carry out the steps present in this recipeto register your device(s) in IBM Watson Internet of Things Platform. Once complete, you will be presented with the device credentials as shown below. Make a note of them as you will need them in the following steps.

var temp1 = [15,17,18.5,20,21.5,23,24,22.2,19,32];

node to the function node as shown below to print the extracted temperature value in the debug panel.

Create a simple flow to start receiving the device events

// Array of pseudo random temperatures

Open the Bluemix Dashboard and click on the Application service that you have currently deployed (using theCreate Toolchainbutton), if you have already moved away from it. You should see the Watson IoT Platform listed under the Binded Services. Click on the WIoTP service and choose the click on Launch button to launch the WIoTP Dashboard.

Also, note that in order to use the IBM IoT App out node, you need to generate the API key from the Watson IoT Platform. This will connect the Node-RED to Watson IoT Platform as an application instead of device. (An application can subscribe to events from multiple devices and send commands to control the devices). The Step 3 this recipe shows how you can generate the API key from the dashboard.

Go to your devices Node-RED application, Drag and drop

At this step, we have successfully created the Watson IoT service and registered your device(s) in it.

Note:You might be prompted to provide SSH Keys to Push the changes made to the package.json file (or any other edits to the Application)

The Node-RED editor has the default set of nodes and in the scope of this Recipe, you would needWatson IoT Node(s), as well.

Include Watson IoT Nodes into Node-RED

IBM IoT App Node A pair of nodes for connecting your application to Watson IoT Platform. An application can use these nodes to receive device events and send commands back to the device.

Connect the 1st route (safe temperature route) of the switch node to this new template node as shown below,

return payload:msg.payload.d.temperature;

With events now being sent to Watson IoT, the next step is to create an application in Bluemix to receive the events.

How to configure the Watson IoT Input node to receive the commands from the application

In this step, we saw how to receive a command on the device, which is sent by the application.

Click deploy to deploy the flow and it sends the command to the device whenever the temperature crosses the threshold.

So in your case, it seems you want to connect the device to Watson IoT Platform, in which case use the Watson IoT Out node as shown in step4

node from the input, double-click and configure the interval time as 1 second,

In this step, We have successfully created a Node-RED application in Bluemix and added a Watson IoT Node in it.

Vehicle telematics analytics using Watson IoT Platform Cloud Analytics

The flow should look like the following now,

node and connect the output of both template nodes to it as shown below,

Hello , the attribute of myibmiot are input TypeDevice IdandName,but not have KPI KeyAuthenticationOutput Type etc.How to solve it ?thanks!

In this step, we will configure the Watson IoT Out Node to send a temperature reading every second to Watson IoT Platform.

Node-RED contains the following Watson IoT nodes that helps you to connect your devices, gateways and applications toWatson IoT Platformand create IoT solutions quickly.

DeviceList card to monitor data from multiple devices

var humidity1 = [50,55,61,68,65,60,53,49,45,47];

node from the output pane. Configure it with the same api keys and device Id. Set the

node, double click and add the following message to format the output message,

IBM IoT App Node A pair of nodes for connecting your application to Watson IoT Platform. An application can use these nodes to receive device events and send commands back to the device.

This completes the device flow. In the next step, we will create an application flow to receive the event and process it.

As a next step, go through the recipeConnecting a Sense HAT to Watson IoT using Node-REDto connect your Sense Hat to Watson IoT Platform.

Watson IoT Node A pair of nodes for connecting your device or gateway to the IBM Watson Internet of Things Platform. A device or gateway can use these nodes to send events and receive commands from the application.

Recipes are community-created content. They are neither monitored nor endorsed by IBM. If you find inappropriate content, please useReport Abuseto let us know. For more information on community content, please refer to ourTerms of Use.

In this recipe, you will learn the following,

In this step, we will send a shutdown command back to the device when the temperature is beyond the threshold.

node, double-click the node and paste the following code. This code creates a random temperature between 15 to 32 degrees. You can write your own code in the function area to change the temperature values or pull the data from the connected sensor,

node. Configure the node to connect as a Device, using the credentials you added previously and set to receive all commands. For example,

The final task is to create the flow on the device to handle the commands sent to it.

How to configure the IBM IoT App Out node to send commands back to the device when the readings cross the threshold.

Node-REDis a tool for wiring together the Internet of Things in new and interesting ways, including hardware devices, APIs, and online services. It is built on top of Node.js and takes advantage of the huge node module ecosystem to provide a tool that is capable of integrating many different systems. Its lightweight nature makes it ideal to run at the edge of the network as well, such as on the Raspberry Pi, and other hack-friendly platforms.

But when i register a device I have the following data:

In this section, we detail how to include the Watson IoT node into the Bluemix Node-RED environment so that one can use the Bluemix environment itself to simulate the device.

In Step 8, to receive commands on device, what should be the output selection in the debug node connected to the Watson IoT input node: message property or complete msg object?

How to configure the Watson IoT Output node to send device events to Watson IoT Platform.

Configuring Boards & Cards in the new Watson IoT Dashboard

IBM IoT out node seems to have changed.

Click on theCreate Toolchainbutton provided below, to quickly deploy the Watson IoT Platform Node-RED Bluemix starter app. Post successful deployment, you shall have both the above mentioned services, up & running on Bluemix along with a Cloudant NoSQL DB at your disposal.

Perform analytics on real-time data from IoT devices and gain diagnostic insights.

Yeah, do not use the application Id. Its required only when you configure it for scalable deployment. Since its already given, Please use a different API Key configuration for the input & output node. I mean the API Key & Token would be same, but create 2 configurations.

Below is the sample screenshot showcasing the code changes,

In this recipe, we learnt the following,

node for the abnormal temperature route, double click and add the following message to format the output message,

field to match the type you used to register your device with. Leave the

Access the Node-RED application by clicking on theView Appoption available, post deploying your application and then choosing the optionGo to you Node-RED flow editor, to access the editor.

Visualize Historian data in Watson IoT Platform

Click deploy and observe the temperature status in the debug panel as the device event is received.

in the top right corner of the Node-RED flow editor window to deploy this flow. This will start sending the temperature event to Watson IoT Platform every one second, also outputs the event in the debug panel.

Getting started with Watson IoT Platform using NodeRED

node, double click and paste the following code in the body to to extract the temperature value from the payload.

This will trigger the flow every 1 second, you can increase the time to a higher value as well.

Create the Boards & Cards in the Watson IoT platform to build custom dashboards for your IoT solutions.

Introduction NodeRED is a tool for wiring together the Internet of Things in new and interesting ways, including hardware devices, APIs, and online services. It is built on top of Node.js and takes advantage of the huge node module ecosystem to provide a tool that is capable of integrating many different systems. Its lightweight nature [hellip;]

Generate API Key and Token of Watson IoT Platform

What is demonstrated in this recipe?

The complete msg object will have other details like topic apart from the payload. the msg.payload will give you the exact payload (command) sent by the application.

Deploy the flow and observe the command whenever the temperature crosses 30 degrees.

In order to send events to the Watson IoT Platform, you must first register your device on the platform.

In this step, we saw how to send a command to the device when the threshold crosses a threshold.

node from the function pane and create rules as shown below.

In this step we have successfully analyzed the temperature data and classified them as safe or unsafe.

Showcases how to create rules and actions to monitor assets in real-time.

node-red-contrib-ibm-watson-iot:0.x

Connect the 2nd route(abnormal temperature route) of the switch node to this new template node.

file and click on Edit to add the following line and have the Watson IoT node installed.

Once the changes are Pushed through Commit operation, the Build & Deploy process gets initiated. You can choose to observe the log in the Delivery Pipeline option.

How to configure the IBM IoT App Out node to send commands back to the device when the readings cross the threshold.

You canskip this sectionin case if you have installed Node-RED on your laptop or on your IoT device.

10 comments onGetting started with Watson IoT Platform using NodeRED

var counter1 = context.get(counter1)0;

Helps to visualize the device data stored in Historical DB using Line Chart Card.

Leave a Comment