I am trying to follow the IBM Bluemix course on Coursera.
- My steup: A raspberry pi as a device (client) which is connected as a registered client to Watson IoT Platform. It's emitting a continuous stream of random numbers per second.
I have deployed my custom Nodejs app (code that is available on Coursera) on IBM Bluemix.
var express = require('express'); var app = express(); var Client = require('ibmiotf'); var appConfig; var serverPort = process.env.VCAP_APP_PORT || 3000; var serverHost = process.env.VCAP_APP_HOST || 'localhost'; if (process.env.VCAP_SERVICES) { var env = JSON.parse(process.env.VCAP_SERVICES); appConfig = { 'org' : env["iotf-service"][0].credentials.org, 'id' : 'dna-nodeserver', 'auth-key' : env["iotf-service"][0].credentials.apiKey, 'auth-token' : env["iotf-service"][0].credentials.apiToken } } else { appConfig = require('./application.json'); } var responseString = 'Hello Coursera'; var appClient = new Client.IotfApplication(appConfig); app.get('/', function(req, res) { res.send(responseString); }); var server = app.listen(serverPort, serverHost, function() { var host = server.address().address; var port = server.address().port; console.log('Listening at http://%s:%s', host, port); appClient.connect(); appClient.on('connect', function() { appClient.subscribeToDeviceEvents('raspberrypi'); }); appClient.on("error", function (err) { console.log("Error : "+err); }); appClient.on('deviceEvent', function(deviceType, deviceId, eventType, format, payload) { responseString = "Device Event from :: "+deviceType+" : "+deviceId+" of event "+eventType+" with payload : "+payload; console.log("Device Event from :: "+deviceType+" : "+deviceId+" of event "+eventType+" with payload : "+payload); }); });
The problem that I am facing is shown is the screenshot below:
Also, since I am receiving continuous events from the raspberry pi... the webpage (served by res.send(responseString)) should show the changes automatically ...without the need for me to manually refresh the page. But this does not seem to happen.
Any help would be appreciated. Thanks!