JSLint - Ran JSLint on the samples and fixed reported syntax issues thereof. 20/141620/1
authorAkhil Kedia <akhil.kedia@samsung.com>
Tue, 1 Aug 2017 06:45:33 +0000 (15:45 +0900)
committerAkhil Kedia <akhil.kedia@samsung.com>
Tue, 1 Aug 2017 06:45:33 +0000 (15:45 +0900)
Change-Id: Ie6e211e5e75bb0ba9086724257dfdfa12568fc0d
Signed-off-by: Akhil Kedia <akhil.kedia@samsung.com>
samples/sample_batch.js
samples/sample_simple.js

index a2f6332c54d62c73eca380145a6e4481a5114597..0d3b01bd19f732871b011ba3d929ce6e038c3970 100644 (file)
  * 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);
     }
   }
index f568dc625bb608146302eb43fc5d3b93ddc92e81..4deb281d2acf22c5c266c9bcb32a6c77be483fb2 100644 (file)
  * 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);
 }