-
Provision an IOT Platform service in Bluemix
-
Add a device based on a new or existing device type
-
Write down the generated token from this device and store into a file called device.json
{
"org": "You-Org-D",
"id": "Your-Device-Id",
"type": "Your-Device-Type",
"auth-method": "token",
"auth-token": "Your-Device-Token"
}
- Create a node.js application with the following code
var iotf = require("ibmiotf");
var config = require("./device.json");
var deviceClient = new iotf.IotfDevice(config);
//setting the log level to debug. By default == 'warn'
deviceClient.log.setLevel('debug');
deviceClient.connect();
deviceClient.on('connect', function () {
var i = 0;
console.log("connected");
setInterval(function function_name() {
i++;
deviceClient.publish('myevt', 'json', '{"value":' + i + '}', 2);
}, 2000);
});
- Run your application. You should see the following output:
- Go to the Dashboard on IOT Platform on Bluemix. You should see the following result:
-
Provision a Node-RED service from the Bluemix catalog
-
Import the Node-RED flow nodered-mqtt-flow.json
-
You should see the following flow
- Create a message payload as follows:
- Configure the MQTT Broker node:
The topic should be: iot-2/evt/myevt/fmt/json
The server should be: YOUR-ORG-ID.messaging.internetofthings.ibmcloud.com
The port should be: 8883
for TLS
The client id should: d:<your-org-id>:<your-device-type>:<your-device>
- Click on Inject node to simulate an event.
For additional resources pay close attention to the following: