diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 0000000..2ad47c5 --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,8 @@ +env: + node: true + es6: true + +extends: google + +rules: + comma-dangle: [2, only-multiline] diff --git a/broker.js b/broker.js index 54f9545..a1774df 100644 --- a/broker.js +++ b/broker.js @@ -1,17 +1,17 @@ // Copyright 2017 DT42 // // This file is part of BerryNet. -// +// // BerryNet is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // BerryNet is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with BerryNet. If not, see . diff --git a/camera.js b/camera.js index e203378..2b9c519 100644 --- a/camera.js +++ b/camera.js @@ -1,17 +1,17 @@ // Copyright 2017 DT42 -// +// // This file is part of BerryNet. -// +// // BerryNet is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // BerryNet is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with BerryNet. If not, see . @@ -28,11 +28,12 @@ const client = mqtt.connect(broker); const topicActionLog = config.topicActionLog; const topicActionInference = config.topicActionInference; const topicEventCamera = config.topicEventCamera; -const topicNotifyEmail = config.topicNotifyEmail; -const camera_uri = config.ipcameraSnapshot; -const snapshot_file = '/tmp/snapshot.jpg'; -const camera_cmd = '/usr/bin/raspistill'; -const camera_args = ['-vf', '-hf', '-w', '1024', '-h', '768', '-o', snapshot_file]; +const cameraURI = config.ipcameraSnapshot; +const snapshotFile = '/tmp/snapshot.jpg'; +const cameraCmd = '/usr/bin/raspistill'; +const cameraArgs = ['-vf', '-hf', + '-w', '1024', '-h', '768', + '-o', snapshotFile]; function log(m) { client.publish(topicActionLog, m); @@ -51,8 +52,8 @@ client.on('message', (t, m) => { if (action == 'snapshot_picam') { // Take a snapshot from RPi3 camera. The snapshot will be displayed // on dashboard. - spawnsync(camera_cmd, camera_args); - fs.readFile(snapshot_file, function(err, data) { + spawnsync(cameraCmd, cameraArgs); + fs.readFile(snapshotFile, function(err, data) { if (err) { log('camera client: cannot get image.'); } else { @@ -64,13 +65,13 @@ client.on('message', (t, m) => { // Take a snapshot from IP camera. The snapshot will be sent to // configured email address. request.get( - {uri: camera_uri, encoding: null}, + {uri: cameraURI, encoding: null}, (e, res, body) => { if (!e && res.statusCode == 200) { - log('camera client: publishing image.') + log('camera client: publishing image.'); client.publish(topicActionInference, body); } else { - log('camera client: cannot get image.') + log('camera client: cannot get image.'); } } ); diff --git a/config.js b/config.js index 883a2b3..b4bf420 100644 --- a/config.js +++ b/config.js @@ -1,17 +1,17 @@ // Copyright 2017 DT42 -// +// // This file is part of BerryNet. -// +// // BerryNet is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // BerryNet is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with BerryNet. If not, see . @@ -19,7 +19,7 @@ const path = require('path'); -var config = {}; +let config = {}; // system configs config.projectDir = __dirname; @@ -27,7 +27,7 @@ config.inferenceEngine = 'detector'; // {classifier, detector} // gateway configs function padTopicBase(topic) { - return path.join(config.topicBase, topic) + return path.join(config.topicBase, topic); } config.snapshot = path.join( diff --git a/journal.js b/journal.js index 78c3ade..4d1882c 100644 --- a/journal.js +++ b/journal.js @@ -1,17 +1,17 @@ // Copyright 2017 DT42 -// +// // This file is part of BerryNet. -// +// // BerryNet is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // BerryNet is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with BerryNet. If not, see . @@ -27,7 +27,7 @@ const client = mqtt.connect(broker); const topicActionLog = config.topicActionLog; const topicNotifyEmail = config.topicNotifyEmail; const topicDashboardLog = config.topicDashboardLog; -const dashboard_pic_topic = config.topicDashboardSnapshot; +const topicDashboardSnapshot = config.topicDashboardSnapshot; const snapshot = config.snapshot; let logs = []; @@ -57,7 +57,7 @@ client.on('message', (t, m) => { if (t == topicNotifyEmail) { const filename = 'snapshot.jpg'; saveBufferToImage(m, snapshot); - client.publish(dashboard_pic_topic, filename); + client.publish(topicDashboardSnapshot, filename); return; } diff --git a/localimg.js b/localimg.js index 24b7c93..09e2b3d 100644 --- a/localimg.js +++ b/localimg.js @@ -1,17 +1,17 @@ // Copyright 2017 DT42 -// +// // This file is part of BerryNet. -// +// // BerryNet is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // BerryNet is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with BerryNet. If not, see . @@ -28,10 +28,8 @@ 'use strict'; -const mqtt = require('mqtt') -const request = require('request') -const spawnsync = require('child_process').spawnSync -const fs = require('fs') +const mqtt = require('mqtt'); +const fs = require('fs'); const config = require('./config'); const broker = config.brokerHost; diff --git a/package.json b/package.json index b12bd96..5179913 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,9 @@ "pino": "^2.13.0", "prompt": "^1.0.0", "request": "^2.79.0" + }, + "devDependencies": { + "eslint": "^3.19.0", + "eslint-config-google": "^0.7.1" } }