This sample application is included as a component in a set of Getting Started guides that step through the basics of developing a ready-for-production, end-to-end IoT prototype system with Watson IoT Platform.
Developers who are new to working with Watson IoT Platform can use the step-by-step processes in the Getting Started guides to develop and deploy a solution that demonstrates one or more Watson IoT Platform features.
For more information about the getting started guides, see the Watson IoT Platform documentation.
In this lesson, you would be able to simulate multiple conveyor belt devices using Node-RED available on the Bluemix. This flow itself could be deployed using single button deployment or manually. The application contains flows to
- Create multiple devices
- Delete the devices
- Simulate event publishing concurrently
Bluemix account in US South / United Kingdom region with
a. Bluemix Space created
b. More than 512 MB RAM
c. More than 1 GB disk quota
d. More than 2 services available
Note that Steps 6 is only needed in case previous lessons have not been carried out
- Download and install the Cloud-foundry CLI.
- Clone the app to your local environment from your terminal using the following command:
- cd into this newly created directory.
- From the command line, set your API endpoint by running the cf api command. Replace the API-ENDPOINT value with the API endpoint for your region.:
$ cf api API-ENDPOINT
Region | API Endpoint |
---|---|
US South | https://api.ng.bluemix.net |
United Kingdom | https://api.eu-gb.bluemix.net |
$ cf login
- Create the Cloudant service in Bluemix
$ cf create-service cloudantNoSQLDB Lite lesson4-simulate-cloudantNoSQLDB
- This step is only needed in case you don't want to use the previous IoT service. The below given command would create an IoT service with the name
lesson4-simulate-iotf-service
. In case you want to create the service with a different name, provide the other name in place oflesson4-simulate-iotf-service
$ cf create-service iotf-service iotf-service-free lesson4-simulate-iotf-service
- Run the cf push command to push the application into Bluemix: Give your application a unique name.
$ cf push APPNAME
You now have your own instance of the app running on the Bluemix.
Although this step is non mandatory, its a good practice to secure your flow.
- Secure your editor so that only authorised users can access it.
- To secure the flow go to the Bluemix dashboard and select the application which you just deployed.
- Click on Runtime and select the Environment variables tab.
- Add the following user-defined environment variables in
a. NODE_RED_USERNAME
b. NODE_RED_PASSWORD
and provide your values. - Save the flow
Note that in case you secure your flow and plan to use ReST call to create / delete or simulate the multiple devices, you need to add the username and password in Basic Authentication.
You can directly click the inject node or make a ReST call.
For any of the ReST calls, you can either use cURL or the ReST client add-on plugin available in Mozilla.
To register multiple devices, either
- Click on the inject node (labelled as "Register 5 iot-conveyor-belt devices" in the Node-RED flow) or
- Make an HTTP POST request to the URL https://URL.mybluemix.net/rest/devices with the following JSON payload keeping 'Content-Type' and 'Accept' as 'application/json'
{
"numberDevices":5,
"typeId":"iot-conveyor-belt",
"authToken":"mypassword",
"chunkSize":5,
"deviceName":"belt"
}
In the above payload, 'authToken', 'chunkSize' and 'typeId' are optional and if the 'chunkSize' is not provided, it defaults to 500.
The 'chunksize' has to be less than and should be a factor of numberDevices (this restriction would be removed shortly). Similarly, if typeId is not provided, it defaults to "devices". All the devices are created with a name starting from the value given against deviceName (in this case, its 'belt') and appended with a number.
To delete devices, either
- Click on the inject node (labelled as "Delete 5 devices" in the Node-RED flow) or
- Make an HTTP POST (not DELETE) request to https://URL.mybluemix.net/rest/deleteDevices and pass the following JSON message.
{
"numberDevices":5,
"deviceType":"iot-conveyor-belt",
"deviceName": "belt"
}
To simulate the flow, either
- Click on the inject node (labelled as "Simulate 5 devices" in the Node-RED flow) or
- Make an HTTP POST request to https://URL.mybluemix.net/rest/runtest and pass the following JSON message
{
"numberDevices":5,
"numberEvents":10,
"timeInterval":1000,
"deviceType":"iot-conveyor-belt",
"deviceName":"belt"
}
This web application includes code to track deployments to IBM Bluemix and other Cloud Foundry platforms. The following information is sent to a Deployment Tracker service on each deployment:
- Application Name (
application_name
) - Space ID (
space_id
) - Application Version (
application_version
) - Application URIs (`application_uris)``
This data is collected from the VCAP_APPLICATION
environment variable in IBM Bluemix and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix to measure the usefulness of our examples, so that we can continuously improve the content we offer to you. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.
Deployment tracking can be disabled by removing the require("cf-deployment-tracker-client").track(); line from 'bluemix-settings.js' file.
IBM Bluemix
IBM Bluemix Documentation
IBM Bluemix Developers Community
IBM Watson Internet of Things
IBM Watson IoT Platform
IBM Watson IoT Platform Developers Community