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