From: Akhil Kedia Date: Tue, 1 Aug 2017 06:45:33 +0000 (+0900) Subject: JSLint - Ran JSLint on the samples and fixed reported syntax issues thereof. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=491e3694df1e1b2d529f0e372b201786233548c8;p=platform%2Fupstream%2Fiotjs.git JSLint - Ran JSLint on the samples and fixed reported syntax issues thereof. Change-Id: Ie6e211e5e75bb0ba9086724257dfdfa12568fc0d Signed-off-by: Akhil Kedia --- diff --git a/samples/sample_batch.js b/samples/sample_batch.js index a2f6332..0d3b01b 100644 --- a/samples/sample_batch.js +++ b/samples/sample_batch.js @@ -13,39 +13,44 @@ * limitations under the License. */ -var https = require("https"); -var timers = require("timers"); -var fs = require("fs"); +var https = require('https'); +var timers = require('timers'); +var fs = require('fs'); var sendTemp = 0; var fileName = 'BatchData.txt'; function sendData(temperature, timeMillis) { - - var data = JSON.stringify({ data: { temp: temperature, onFire: false }, - sdid: '170e5221612b4bc38dce53fd4395174a', - ts: timeMillis, - type: 'message' }); + var data = JSON.stringify( + { + data: { + temp: temperature, + onFire: false, + }, + sdid: '170e5221612b4bc38dce53fd4395174a', + ts: timeMillis, + type: 'message', + }); var options = { - "method": "POST", - "hostname": "api.artik.cloud", - "path": "/v1.1/messages", - "headers": { - "content-type": "application/json", - "content-length": data.length, - "authorization": "Bearer 1718113118564ad495ad03f04116f379" - } + 'method': 'POST', + 'hostname': 'api.artik.cloud', + 'path': '/v1.1/messages', + 'headers': { + 'content-type': 'application/json', + 'content-length': data.length, + 'authorization': 'Bearer 1718113118564ad495ad03f04116f379', + }, }; - var req = https.request(options, function (res) { + var req = https.request(options, function(res) { var resBody = ''; - res.on("data", function (chunk) { + res.on('data', function(chunk) { resBody += chunk.toString(); }); - res.on("end", function () { - console.log('Request Ended. Server sent - '+ resBody); + res.on('end', function() { + console.log('Request Ended. Server sent - ' + resBody); }); }); @@ -57,8 +62,8 @@ function sendData(temperature, timeMillis) { function writeData() { sendTemp = sendTemp + 10; var timeStampMillis = Math.floor(new Date().valueOf()); - var data = new Buffer(sendTemp+','+timeStampMillis+'\n') - console.log('Writing to file : '+ data); + var data = new Buffer(sendTemp + ',' + timeStampMillis + '\n'); + console.log('Writing to file : ' + data); var fd = fs.openSync(fileName, 'a'); fs.writeSync(fd, data, 0, data.length); @@ -66,18 +71,18 @@ function writeData() { } function readData() { - console.log('Reading data from file.') + console.log('Reading data from file.'); var fileContents = fs.readFileSync(fileName); fs.unlinkSync(fileName); var array = fileContents.toString().split('\n'); - for (i in array) { + for (var i = 0; i < array.length; i++) { var parts = array[i].split(','); var temp = parts[0]; var timestamp = parts[1]; - if(temp) { - console.log('Currently sending temperature to cloud - '+temp - +' and timestamp as - '+ timestamp); + if (temp) { + console.log('Currently sending temperature to cloud - ' + temp + + ' and timestamp as - ' + timestamp); sendData(temp, timestamp); } } diff --git a/samples/sample_simple.js b/samples/sample_simple.js index f568dc6..4deb281 100644 --- a/samples/sample_simple.js +++ b/samples/sample_simple.js @@ -13,35 +13,40 @@ * limitations under the License. */ -var https = require("https"); -var timers = require("timers"); +var https = require('https'); +var timers = require('timers'); function sendData(temperature) { - - var data = JSON.stringify({ data: { temp: temperature, onFire: false }, - sdid: '170e5221612b4bc38dce53fd4395174a', - type: 'message' }); + var data = JSON.stringify( + { + data: { + temp: temperature, + onFire: false, + }, + sdid: '170e5221612b4bc38dce53fd4395174a', + type: 'message', + }); var options = { - "method": "POST", - "hostname": "api.artik.cloud", - "path": "/v1.1/messages", - "headers": { - "content-type": "application/json", - "content-length": data.length, - "authorization": "Bearer 1718113118564ad495ad03f04116f379" - } + 'method': 'POST', + 'hostname': 'api.artik.cloud', + 'path': '/v1.1/messages', + 'headers': { + 'content-type': 'application/json', + 'content-length': data.length, + 'authorization': 'Bearer 1718113118564ad495ad03f04116f379', + }, }; - var req = https.request(options, function (res) { + var req = https.request(options, function(res) { var resBody = ''; - res.on("data", function (chunk) { + res.on('data', function(chunk) { console.log('Received response from server'); resBody += chunk.toString(); console.log(resBody); }); - res.on("end", function () { + res.on('end', function() { console.log('Request Ended. Final data sent by the server - '); console.log(resBody); console.log('Waiting for next Interval\n'); @@ -56,7 +61,7 @@ var sendtemp = 0; function generateData() { sendtemp = sendtemp + 10; - console.log('Sending Temperature to Artik Cloud : '+ sendtemp); + console.log('Sending Temperature to Artik Cloud : ' + sendtemp); sendData(sendtemp); }