Push dev work to master #2
|
@ -71,8 +71,6 @@ function onWifiWrite (data, offset, withoutResponse, callback) {
|
||||||
result = bleno.Characteristic.RESULT_UNLIKELY_ERROR
|
result = bleno.Characteristic.RESULT_UNLIKELY_ERROR
|
||||||
return callback(result)
|
return callback(result)
|
||||||
}
|
}
|
||||||
console.log(hash)
|
|
||||||
console.log(plaintext)
|
|
||||||
return wifi.setNetwork(ssid, plaintext, hash, (err, data) => {
|
return wifi.setNetwork(ssid, plaintext, hash, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.error('Error configuring wifi', err)
|
log.error('Error configuring wifi', err)
|
||||||
|
|
|
@ -57,13 +57,18 @@ class Wifi {
|
||||||
* @param {string} data Contents of the config file
|
* @param {string} data Contents of the config file
|
||||||
*/
|
*/
|
||||||
_readConfigCb (err, data) {
|
_readConfigCb (err, data) {
|
||||||
|
let parsed
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
return _cb(err)
|
return _cb(err)
|
||||||
}
|
}
|
||||||
console.dir(data)
|
|
||||||
|
parsed = this._parseConfig(data)
|
||||||
|
console.dir(parsed)
|
||||||
|
console.log(data)
|
||||||
console.log(data.search(networkPattern))
|
console.log(data.search(networkPattern))
|
||||||
console.log(_entry)
|
console.log(_entry)
|
||||||
|
|
||||||
if (data.search(networkPattern) === -1) {
|
if (data.search(networkPattern) === -1) {
|
||||||
data += `\n${_entry}`
|
data += `\n${_entry}`
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,8 +122,28 @@ class Wifi {
|
||||||
//this._callback(null, { ssid : ssid, pwd : pwd.length })
|
//this._callback(null, { ssid : ssid, pwd : pwd.length })
|
||||||
_cb = () => {}
|
_cb = () => {}
|
||||||
}
|
}
|
||||||
_parseConfig () {
|
_parseConfig (str) {
|
||||||
|
const networks = []
|
||||||
|
const lines = str.split('\n')
|
||||||
|
let network = {}
|
||||||
|
for (let line of lines) {
|
||||||
|
if (line.indexOf('network={') !== -1) {
|
||||||
|
network = {}
|
||||||
|
network.raw = line
|
||||||
|
} else if (line.indexOf('ssid=') !== -1) {
|
||||||
|
network.ssid = line.replace('ssid=', '').trim().replace(quoteRe, '')
|
||||||
|
if (network.raw) {
|
||||||
|
network.raw += '\n' + line
|
||||||
|
}
|
||||||
|
} else if (line.indexOf('}') !== -1) {
|
||||||
|
network.raw += '\n' + line
|
||||||
|
networks.push(network)
|
||||||
|
network = {}
|
||||||
|
} else if (network.ssid) {
|
||||||
|
network.raw += '\n' + line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return networks
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create sanitized wpa_supplicant.conf stanza for
|
* Create sanitized wpa_supplicant.conf stanza for
|
||||||
|
|
Loading…
Reference in New Issue