diff --git a/index.js b/index.js index 6c1f975..a92753e 100644 --- a/index.js +++ b/index.js @@ -120,8 +120,9 @@ function rDelay (req, res, next) { } function rFrame (req, res, next) { - intval.frame(cb=()=>{ - log.info('happened') + log.info('/frame', { method : req.method }) + intval.frame(true, 0, () => { + log.info('frame stopped') }) res.send({}) return next() diff --git a/lib/blootstrap/index.js b/lib/blootstrap/index.js index 1e2c40f..b4003a4 100644 --- a/lib/blootstrap/index.js +++ b/lib/blootstrap/index.js @@ -11,31 +11,28 @@ function capitalize (s) { class Blootstrap { constructor () { this._onData = () => {} - try { - ipc.connectTo('blootstrap_ble', () => { - ipc.of.blootstrap_ble.on('connect', () => { - log.info('connect', `Connected to the blootstrap_ble service`) + ipc.config.maxRetries = 0 + ipc.connectTo('blootstrap_ble', () => { + ipc.of.blootstrap_ble.on('connect', () => { + log.info('connect', `Connected to the blootstrap_ble service`) - }) - ipc.of.blootstrap_ble.on('data', data => { - const str = data.toString() - log.info('data', str) - this._onData(str) - }) - ipc.of.blootstrap_ble.on('disconnect', () => { - log.info('disconnect', `Disconnected from the blootstrap_ble service`) - }) - ipc.of.blootstrap_ble.on('error', (err) => { - if (err.code === 'EACCES') { - log.warn('ble', `Cannot access ipc`) - } else { - log.error('ble', { error : err }) - } - }) }) - } catch (e) { - log.error('connectTo', { error : e }) - } + ipc.of.blootstrap_ble.on('data', data => { + const str = data.toString() + log.info('data', str) + this._onData(str) + }) + ipc.of.blootstrap_ble.on('disconnect', () => { + log.info('disconnect', `Disconnected from the blootstrap_ble service`) + }) + ipc.of.blootstrap_ble.on('error', (err) => { + if (err.code === 'EACCES') { + log.warn('ble', `Cannot access ipc`) + } else { + log.error('ble', { error : err }) + } + }) + }) } /** * Binds functions to events that are triggered by BLE messages diff --git a/lib/wifi/index.js b/lib/wifi/index.js index 2f236d2..b07d74a 100644 --- a/lib/wifi/index.js +++ b/lib/wifi/index.js @@ -13,12 +13,14 @@ const log = require('../log')('wifi') const exec = require('child_process').exec const fs = require('fs') +let _entry = null +let _ssid = null +let _cb = null + /** Class representing the wifi features */ class Wifi { constructor () { - this._callback = () => {} - this._entry = null - this._ssid = null + } /** * List available wifi access points @@ -54,14 +56,14 @@ class Wifi { _readConfigCb (err, data) { if (err) { console.error(err) - return this._callback(err) + return _cb(err) } if (data.search(networkPattern) === -1) { - data += `\n${this._entry}` + data += `\n${_entry}` } else { - data = data.replace(networkPattern, this._entry) + data = data.replace(networkPattern, _entry) } - this._entry = null + _entry = null fs.writeFile(filePath, data, 'utf8', this._writeConfigCb) } /** @@ -73,7 +75,7 @@ class Wifi { _writeConfigCb (err) { if (err) { console.error(err) - return this._callback(err) + return _cb(err) } exec(reconfigure, this._reconfigureCb) } @@ -87,7 +89,7 @@ class Wifi { _reconfigureCb (err, stdout, stderr) { if (err) { console.error(err) - return this._callback(err) + return _cb(err) } console.log('Wifi reconfigured') exec(refresh, this._refreshCb) @@ -102,11 +104,11 @@ class Wifi { _refreshCb (err, stdout, stderr) { if (err) { console.error(err) - return this._callback(err) + return _cb(err) } console.log('Wifi refreshed') //this._callback(null, { ssid : ssid, pwd : pwd.length }) - this._callback = () => {} + _cb = () => {} } /** * Function which initializes the processes for adding a wifi access point authentication @@ -116,9 +118,9 @@ class Wifi { * @param {function} callback Function invoked after process is complete, or fails */ setNetwork (ssid, pwd, callback) { - this._entry = `network={\n\tssid="${ssid}"\n\tpsk="${pwd}"\n}\n` - this._callback = callback - this._ssid = ssid + _entry = `network={\n\tssid="${ssid}"\n\tpsk="${pwd}"\n}\n` + _cb = callback + _ssid = ssid fs.readFile(filePath, 'utf8', this._readConfigCb) } /**