In this tutorial, learn how to create a Node-RED and Watson IoT Platform starter application that can be used to connect IoT devices and simulated IoT devices to the Watson IoT Platform. This combination of services will be assembled to work together, including a Node-RED Node.js web server, a Cloudant database to store the sensor data, and the IoT Platform service, so that you can easily connect IoT devices.
In this tutorial, you will learn how to:
- Create a Node-RED Starter Kit application running in the IBM Cloud
- Create an Internet of Things Platform service instance
- Connect the the Internet of Things Platform service instance to the Node-RED Cloud Foundry application
- Deploy the Node-RED Starter Cloud Foundry application
- Configure the Node-RED visual programming editor
- Open the Watson IoT Platform so that you can send data from IoT devices and device simulators
To complete this tutorial, you need an IBM Cloud account (IBM Cloud Lite, trial, or paid account).
You can complete this tutorial in less than 20 minutes.
- Create a Node-RED Starter application
- Create an Internet of Things Platform service
- Enable the Continuous Delivery feature
- Open the Node-RED visual programming editor
- Configure your Node-RED application
- Add extra nodes to your Node-RED palette
- Launch the Watson IoT platform
Step 1. Create a Node-RED Starter application
Follow these steps to create a Node-RED Starter application in the IBM Cloud.
Log in to IBM Cloud.
Click Catalog, and search for Node-RED.
Under Starter Kits, click the Node-RED App card.
Click on the Create tab.
Enter a unique name for your application. This name will be part of the application URL. Note: If the name is not unique, you will see an error message, and you must enter a different name before you can continue.
Click the Create button. This will create your application, but it is not yet deployed to IBM Cloud.
The Node-RED Starter application requires an instance of the Cloudant database service to store your application flow configuration. Select the region the service should be created in and what pricing plan it should use.
Note: You can only have one Cloudant instance using the Lite plan. If you have already got an instance, you will be able to select it from the Pricing plan select box. You can have more than one Node-RED Starter application using the same Cloudant service instance.
Step 2. Create an Internet of Things Platform service
The next step is to create an Internet of Things Platform service instance.
Click on the Create service button.
Scroll down in the list of services to the Internet of Things card.
Select the Internet of Things card and click on the Next button.
Select the Internet of Things Platform card and click on the Next button.
Click on the Deploy your app button to enable the Continuous Delivery feature for your application.
Step 3. Enable the Continuous Delivery feature
At this point, you have created the application and the resources it requires, but you have not deployed it anywhere to run. This step shows how to setup the Continuous Delivery feature that will deploy your application into the Cloud Foundry space of IBM Cloud.
You will need to create an IBM Cloud API key to allow the deployment process to access your resources. Click the New button to create the key. A message dialog will appear. You can accept the default values and click OK to confirm / close the dialog.
Increase the Memory allocation per instance slider to at least 128MB. If you do not increase the memory allocation, your Node-RED application might not have sufficient memory to run successfully.
The Node-RED Starter kit only supports deployment to the Cloud Foundry space of IBM Cloud. Select the region to deploy your application to. This should match the region you created your Cloudant instance in. Lite users might only be able to deploy to your default region.
Click Next to continue.
Configure the DevOps toolchain by selecting the region it should be created in – again, try to match the region you selected previously.
Click Create. This will take you back to the application details page.
After a few moments, the Deployment Automation section will refresh with the details of your newly created Delivery Pipeline. The Status field of the pipeline will eventually show In progress. That means your application is being built and deployed.
Click on the Status field In progress to see the full status of the Delivery Pipeline.
The Deploy stage will take a few minutes to complete. You can click on the View logs and history link to check its progress. Eventually the Deploy stage will go green to show it has passed. This means your Node-RED Starter application is now running.
Step 4. Open the Node-RED application
Now that you’ve deployed your Node-RED application, let’s open it up!
Back on the application details page, you should now see the App URL, Source and Deployment target fields filled in.
Click on the App URL to open up your Node-RED application in a new browser tab.
Step 5. Configure your Node-RED application
The first time you open your Node-RED app, you’ll need to configure it and set up security.
A new browser tab will open with the Node-RED start page.
On the initial screen, click Next to continue.
Secure your Node-RED editor by providing a username and password. If you need to change these at any point, you can either edit the values in the Cloudant database, or override them using environment variables. The documentation on nodered.org describes how to do this. Click Next to continue.
The final screen summarizes the options you’ve made and highlights the environment variables you can use to change the options in the future. Click Finish to proceed.
Node-RED will save your changes and then load the main application. From here you can click the Go to your Node-RED flow editor button to open the editor.
The Node-RED editor opens showing the default flow.
Step 6. Add extra nodes to your Node-RED palette
Node-RED provides the palette manager feature that allows you to install additional nodes directly from the browser-based editor. This is convenient for trying nodes out, but it can cause issues due to the limited memory of the default Node-RED starter application.
The recommended approach is to edit your application’s
package.json file to include the additional node modules and then redeploy the application.
This step shows how to do that in order to add the node-red-contrib-scx-ibmiotapp module to easily receive IoT data into your Node-RED flow.
On your application’s details page, click Source url. This will take you to a git repository where you can edit the application source code from your browser.
Scroll down the list of files and click on package.json. This file lists the module dependencies of your application.
Click the Edit button
Add the following entry to the
Note: Do not forget the comma (
,) at the end of the line to separate it from the next entry.
Add a Commit message (2) and click Commit changes (3)
At this point, the Continuous Delivery pipeline will automatically run to build and deploy that change into your application. If you view the Delivery Pipeline you can watch its progress. The Build section shows you the last commit made and the Deploy section shows the progress of redeploying the application.
Once the Deploy stage completes, your application will have restarted and now have the
Note: if you have a Lite account, you are limited to 256Mb total memory for your running applications. The default behavior of the pipeline is to start a second instance of the application before moving the URL over and deleting the old instance. This minimizes the downtime during a deploy, but it does require twice the memory. If you created your application with 256Mb of memory originally, then you will need to stop the application before the pipeline runs. To do this, click on the Deployment Target link on your application details page. This opens the Cloud Foundry application details page. From that page select the Stop option under the Actions menu.
Step 7. Launch the Watson IoT platform
Now that you’ve configured the services and setup the Node-RED Visual Programming Editor, you can launch the Watson IoT Platform.
Return to the IBM Cloud Application Details page.
In the Connections card, click your iotplatform service.
In subheader of the service, click the Alias of … link.
The Internet of Things service landing page opens. From the Manage page, click the Launch (17) button.
The Watson IoT Platform service opens in a new browser tab. You can now create an IoT device.
Congratulations! You have now created a Node-RED and Watson Internet of Things Platform Starter application that is hosted in the IBM Cloud. You have also learned how to edit the application source code and automatically deploy changes.