Push dev work to master #2
|
@ -8,7 +8,7 @@ Object representing a fake onoff Gpio class
|
|||
|
||||
### onoffsim.Gpio(no, dir, additional) ⇒ <code>object</code>
|
||||
Gpio() -
|
||||
Create's a Gpio class in the case of running on a dev machine
|
||||
Returns a Gpio class in the case of running on a dev machine
|
||||
|
||||
**Kind**: static method of [<code>onoffsim</code>](#onoffsim)
|
||||
**Returns**: <code>object</code> - Fake Gpio object
|
||||
|
|
|
@ -12,7 +12,6 @@ const onoffsim = {
|
|||
* @returns {object} Fake Gpio object
|
||||
*/
|
||||
Gpio : function (no, dir = 'in', additional = 'none') {
|
||||
//
|
||||
return {
|
||||
no : no,
|
||||
dir : dir,
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
<a name="Wifi"></a>
|
||||
|
||||
## Wifi
|
||||
Class representing the wifi features
|
||||
|
||||
**Kind**: global class
|
||||
|
||||
* [Wifi](#Wifi)
|
||||
* [.list(callback)](#Wifi+list)
|
||||
* [._readConfigCb(err, data)](#Wifi+_readConfigCb)
|
||||
* [._writeConfigCb(err)](#Wifi+_writeConfigCb)
|
||||
* [._reconfigureCb(err, stdout, stderr)](#Wifi+_reconfigureCb)
|
||||
* [._refreshCb(err, stdout, stderr)](#Wifi+_refreshCb)
|
||||
* [.setNetwork(ssid, pwd, callback)](#Wifi+setNetwork)
|
||||
* [.getNetwork(callback)](#Wifi+getNetwork)
|
||||
|
||||
<a name="Wifi+list"></a>
|
||||
|
||||
### wifi.list(callback)
|
||||
Wifi.list() -
|
||||
List available wifi access points
|
||||
|
||||
**Kind**: instance method of [<code>Wifi</code>](#Wifi)
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| callback | <code>function</code> | Function which gets invoked after list is returned |
|
||||
|
||||
<a name="Wifi+_readConfigCb"></a>
|
||||
|
||||
### wifi._readConfigCb(err, data)
|
||||
Wifi._readConfigCb() -
|
||||
(internal function) Invoked after config file is read,
|
||||
then invokes file write on the config file
|
||||
|
||||
**Kind**: instance method of [<code>Wifi</code>](#Wifi)
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| err | <code>object</code> | (optional) Error object only present if problem reading config file |
|
||||
| data | <code>string</code> | Contents of the config file |
|
||||
|
||||
<a name="Wifi+_writeConfigCb"></a>
|
||||
|
||||
### wifi._writeConfigCb(err)
|
||||
Wifi._writeConfigCb() -
|
||||
(internal function) Invoked after config file is written,
|
||||
then executes reconfiguration command
|
||||
|
||||
**Kind**: instance method of [<code>Wifi</code>](#Wifi)
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| err | <code>object</code> | (optional) Error object only present if problem writing config file |
|
||||
|
||||
<a name="Wifi+_reconfigureCb"></a>
|
||||
|
||||
### wifi._reconfigureCb(err, stdout, stderr)
|
||||
Wifi._reconfigureCb() -
|
||||
(internal function) Invoked after reconfiguration command is complete
|
||||
|
||||
**Kind**: instance method of [<code>Wifi</code>](#Wifi)
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| err | <code>object</code> | (optional) Error object only present if configuration command fails |
|
||||
| stdout | <code>string</code> | Standard output from reconfiguration command |
|
||||
| stderr | <code>string</code> | Error output from command if fails |
|
||||
|
||||
<a name="Wifi+_refreshCb"></a>
|
||||
|
||||
### wifi._refreshCb(err, stdout, stderr)
|
||||
Wifi._refreshCb() -
|
||||
(internal function) Invoked after wifi refresh command is complete
|
||||
|
||||
**Kind**: instance method of [<code>Wifi</code>](#Wifi)
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| err | <code>object</code> | (optional) Error object only present if refresh command fails |
|
||||
| stdout | <code>string</code> | Standard output from refresh command |
|
||||
| stderr | <code>string</code> | Error output from command if fails |
|
||||
|
||||
<a name="Wifi+setNetwork"></a>
|
||||
|
||||
### wifi.setNetwork(ssid, pwd, callback)
|
||||
Wifi.setNetwork() -
|
||||
Function which initializes the processes for adding a wifi access point authentication
|
||||
|
||||
**Kind**: instance method of [<code>Wifi</code>](#Wifi)
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| ssid | <code>string</code> | SSID of network to configure |
|
||||
| pwd | <code>string</code> | Password of access point, plaintext |
|
||||
| callback | <code>function</code> | Function invoked after process is complete, or fails |
|
||||
|
||||
<a name="Wifi+getNetwork"></a>
|
||||
|
||||
### wifi.getNetwork(callback)
|
||||
Wifi.getNetwork() -
|
||||
Executes command which gets the currently connected network
|
||||
|
||||
**Kind**: instance method of [<code>Wifi</code>](#Wifi)
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| callback | <code>function</code> | Function which is invoked after command is completed |
|
||||
|
|
@ -12,12 +12,19 @@ const iwgetid = '/sbin/iwgetid'
|
|||
const exec = require('child_process').exec
|
||||
const fs = require('fs')
|
||||
|
||||
class wifi {
|
||||
/** Class representing the wifi features */
|
||||
class Wifi {
|
||||
constructor () {
|
||||
this._callback = () => {}
|
||||
this._entry = null
|
||||
this._ssid = null
|
||||
}
|
||||
/**
|
||||
* Wifi.list() -
|
||||
* List available wifi access points
|
||||
*
|
||||
* @param {function} callback Function which gets invoked after list is returned
|
||||
*/
|
||||
list (callback) {
|
||||
exec(iwlist, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
|
@ -37,6 +44,14 @@ class wifi {
|
|||
return callback(null, output)
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Wifi._readConfigCb() -
|
||||
* (internal function) Invoked after config file is read,
|
||||
* then invokes file write on the config file
|
||||
*
|
||||
* @param {object} err (optional) Error object only present if problem reading config file
|
||||
* @param {string} data Contents of the config file
|
||||
*/
|
||||
_readConfigCb (err, data) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
@ -50,6 +65,13 @@ class wifi {
|
|||
this._entry = null
|
||||
fs.writeFile(filePath, data, 'utf8', this._writeConfigCb)
|
||||
}
|
||||
/**
|
||||
* Wifi._writeConfigCb() -
|
||||
* (internal function) Invoked after config file is written,
|
||||
* then executes reconfiguration command
|
||||
*
|
||||
* @param {object} err (optional) Error object only present if problem writing config file
|
||||
*/
|
||||
_writeConfigCb (err) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
@ -57,6 +79,14 @@ class wifi {
|
|||
}
|
||||
exec(reconfigure, this._reconfigureCb)
|
||||
}
|
||||
/**
|
||||
* Wifi._reconfigureCb() -
|
||||
* (internal function) Invoked after reconfiguration command is complete
|
||||
*
|
||||
* @param {object} err (optional) Error object only present if configuration command fails
|
||||
* @param {string} stdout Standard output from reconfiguration command
|
||||
* @param {string} stderr Error output from command if fails
|
||||
*/
|
||||
_reconfigureCb (err, stdout, stderr) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
@ -65,6 +95,14 @@ class wifi {
|
|||
console.log('Wifi reconfigured')
|
||||
exec(refresh, this._refreshCb)
|
||||
}
|
||||
/**
|
||||
* Wifi._refreshCb() -
|
||||
* (internal function) Invoked after wifi refresh command is complete
|
||||
*
|
||||
* @param {object} err (optional) Error object only present if refresh command fails
|
||||
* @param {string} stdout Standard output from refresh command
|
||||
* @param {string} stderr Error output from command if fails
|
||||
*/
|
||||
_refreshCb (err, stdout, stderr) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
|
@ -74,12 +112,26 @@ class wifi {
|
|||
//this._callback(null, { ssid : ssid, pwd : pwd.length })
|
||||
this._callback = () => {}
|
||||
}
|
||||
/**
|
||||
* Wifi.setNetwork() -
|
||||
* 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 {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
|
||||
fs.readFile(filePath, 'utf8', this._readConfigCb)
|
||||
}
|
||||
/**
|
||||
* Wifi.getNetwork() -
|
||||
* Executes command which gets the currently connected network
|
||||
*
|
||||
* @param {function} callback Function which is invoked after command is completed
|
||||
*/
|
||||
getNetwork (callback) {
|
||||
exec(iwgetid, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
|
@ -90,4 +142,4 @@ class wifi {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = new wifi()
|
||||
module.exports = new Wifi()
|
Loading…
Reference in New Issue