Push dev work to master #2
|
@ -80,8 +80,19 @@ function onWifiWrite (data, offset, withoutResponse, callback) {
|
||||||
|
|
||||||
function onWifiRead (offset, callback) {
|
function onWifiRead (offset, callback) {
|
||||||
const result = bleno.Characteristic.RESULT_SUCCESS
|
const result = bleno.Characteristic.RESULT_SUCCESS
|
||||||
const data = new Buffer(JSON.stringify(currentWifi))
|
const wifiRes = {}
|
||||||
callback(result, data.slice(offset, data.length))
|
let data
|
||||||
|
wifi.list((err, list) => {
|
||||||
|
if (err) {
|
||||||
|
result = bleno.Characteristic.RESULT_UNLIKELY_ERROR
|
||||||
|
return callback(result)
|
||||||
|
}
|
||||||
|
wifiRes.available = list
|
||||||
|
wifiRes.current = currentWifi
|
||||||
|
log.info('Discovered available APs', { found : list.length })
|
||||||
|
data = new Buffer(JSON.stringify(wifiRes))
|
||||||
|
callback(result, data.slice(offset, data.length))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMac () {
|
function getMac () {
|
||||||
|
@ -162,6 +173,14 @@ class BLE {
|
||||||
bleno.on('disconnect', clientAddress => {
|
bleno.on('disconnect', clientAddress => {
|
||||||
log.info('disconnect', { clientAddress : clientAddress })
|
log.info('disconnect', { clientAddress : clientAddress })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
wifi.getNetwork((err, ssid) => {
|
||||||
|
if (err) {
|
||||||
|
return log.error('wifi.getNetwork', err)
|
||||||
|
}
|
||||||
|
currentWifi = ssid
|
||||||
|
log.info('wifi.getNetwork', {ssid : ssid})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
_onWrite (data, offset, withoutResponse, callback) {
|
_onWrite (data, offset, withoutResponse, callback) {
|
||||||
let result = {}
|
let result = {}
|
||||||
|
|
|
@ -142,13 +142,12 @@ class Wifi {
|
||||||
* Function which initializes the processes for adding a wifi access point authentication
|
* Function which initializes the processes for adding a wifi access point authentication
|
||||||
*
|
*
|
||||||
* @param {string} ssid SSID of network to configure
|
* @param {string} ssid SSID of network to configure
|
||||||
* @param {string} pwd Password of access point, plaintext
|
* @param {string} pwd Password of access point, plaintext to be masked
|
||||||
* @param {string} hash Password/SSID of access point, securely hashed
|
* @param {string} hash Password/SSID of access point, securely hashed
|
||||||
* @param {function} callback Function invoked after process is complete, or fails
|
* @param {function} callback Function invoked after process is complete, or fails
|
||||||
*/
|
*/
|
||||||
setNetwork (ssid, pwd, hash, callback) {
|
setNetwork (ssid, pwd, hash, callback) {
|
||||||
let masked = pwd.split('').map(char => { return '*' }).join('')
|
let masked = pwd.split('').map(char => { return char !== '"' ? '*' : '"' }).join('')
|
||||||
console.log(pwd + ' vs. ' + masked)
|
|
||||||
_entry = `network={\n\tssid="${ssid}"\n\t#psk=${masked}\n\tpsk=${hash}\n}\n`
|
_entry = `network={\n\tssid="${ssid}"\n\t#psk=${masked}\n\tpsk=${hash}\n}\n`
|
||||||
_cb = callback
|
_cb = callback
|
||||||
_ssid = ssid
|
_ssid = ssid
|
||||||
|
@ -160,11 +159,13 @@ class Wifi {
|
||||||
* @param {function} callback Function which is invoked after command is completed
|
* @param {function} callback Function which is invoked after command is completed
|
||||||
*/
|
*/
|
||||||
getNetwork (callback) {
|
getNetwork (callback) {
|
||||||
|
let output
|
||||||
exec(iwgetid, (err, stdout, stderr) => {
|
exec(iwgetid, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
callback(null, stdout)
|
output = stdout.split('ESSID:')[1].replace(quoteRe, '').trim()
|
||||||
|
callback(null, output)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue