Push dev work to master #2
|
@ -22,6 +22,7 @@ const bleno = require('bleno')
|
|||
|
||||
|
||||
let currentWifi = 'disconnected'
|
||||
let currentAddr = null
|
||||
let getState
|
||||
|
||||
const chars = []
|
||||
|
@ -78,6 +79,7 @@ function onWifiWrite (data, offset, withoutResponse, callback) {
|
|||
return callback(result)
|
||||
}
|
||||
currentWifi = ssid
|
||||
currentAddr = getIp()
|
||||
log.info(`Connected to AP`, { ssid : ssid })
|
||||
result = bleno.Characteristic.RESULT_SUCCESS
|
||||
return callback(result)
|
||||
|
@ -96,6 +98,7 @@ function onWifiRead (offset, callback) {
|
|||
}
|
||||
wifiRes.available = list
|
||||
wifiRes.current = currentWifi
|
||||
wifiRes.ip = currentAddr
|
||||
log.info('Discovered available APs', { found : list.length })
|
||||
data = new Buffer(JSON.stringify(wifiRes))
|
||||
callback(result, data.slice(offset, data.length))
|
||||
|
@ -133,6 +136,23 @@ function spoofMac () {
|
|||
return MACTMP
|
||||
}
|
||||
|
||||
function getIp () {
|
||||
let addr = null
|
||||
let ipv4
|
||||
const ifaces = os.networkInterfaces()
|
||||
if (ifaces && ifaces.wlan0) {
|
||||
ipv4 = ifaces.wlan0.filter(iface => {
|
||||
if (iface.family === 'IPv4') {
|
||||
return iface
|
||||
}
|
||||
})
|
||||
if (ipv4.length === 1) {
|
||||
addr = ipv4.address
|
||||
}
|
||||
}
|
||||
return addr
|
||||
}
|
||||
|
||||
|
||||
function capitalize (s) {
|
||||
return s[0].toUpperCase() + s.slice(1)
|
||||
|
@ -186,6 +206,7 @@ class BLE {
|
|||
return log.error('wifi.getNetwork', err)
|
||||
}
|
||||
currentWifi = ssid
|
||||
currentAddr = getIp()
|
||||
log.info('wifi.getNetwork', {ssid : ssid})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue