Developing a sensor subscriber

To see what sensor data is sent by Arduino Yún , we can create a simple program to subscribe a message on a specific channel. We already define the sensorroom channel as the sensor channel. Using the previous program from Chapter 1, Getting Started with AWS IoT, we can develop a program to subscribe the sensorroom channel and then listen to the incoming messages from AWS IoT. We use the Node.js application to communicate with AWS IoT.

Write the following scripts for the complete program:

var awsIot = require('aws-iot-device-sdk');

var device = awsIot.device({
keyPath: 'cert/private.key',
certPath: 'cert/cert.pem',
caPath: 'cert/root-CA.pem',
host: '<host-aws-iot-server>',
clientId: 'user-testing',
region: 'ap-southeast-'
});

device
.on('connect', function() {
console.log('connected');
device.subscribe('sensorroom');
});

device
.on('message', function(topic, payload) {
console.log('recv:', topic, payload.toString());
});

console.log('Sensor subscriber started.');

Save this program as the sensor-subscriber.js file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.63.95