-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from resin-io-projects/wifi-connect
include wifi-connect
- Loading branch information
Showing
23 changed files
with
604 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"directory": "src/public/bower_components", | ||
"storage": { | ||
"packages": ".bower-cache", | ||
"registry": ".bower-registry" | ||
}, | ||
"tmp": ".bower-tmp" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "resin-wifi-connect", | ||
"version": "0.0.0", | ||
"homepage": "https://github.com/pcarranzav/resin-wifi-connect", | ||
"authors": [ | ||
"Pablo Carranza Vélez <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"src/public/bower_components", | ||
"test", | ||
"tests" | ||
], | ||
"dependencies": { | ||
"bootstrap": "~3.3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Promise = require 'bluebird' | ||
fs = Promise.promisifyAll(require('fs')) | ||
express = require 'express' | ||
bodyParser = require 'body-parser' | ||
|
||
config = require './config' | ||
|
||
utils = require './utils' | ||
connman = require './connman' | ||
hotspot = require './hotspot' | ||
wifiScan = require './wifi-scan' | ||
|
||
app = express() | ||
|
||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded(extended: true)) | ||
app.use(express.static(__dirname + '/public')) | ||
|
||
ssids = [] | ||
|
||
app.get '/ssids', (req, res) -> | ||
res.json(ssids) | ||
|
||
app.post '/connect', (req, res) -> | ||
if not (req.body.ssid? and req.body.passphrase?) | ||
return res.sendStatus(400) | ||
|
||
console.log('Selected ' + req.body.ssid) | ||
|
||
res.send('OK') | ||
|
||
data = """ | ||
[service_home_ethernet] | ||
Type = ethernet | ||
Nameservers = 8.8.8.8,8.8.4.4 | ||
[service_home_wifi] | ||
Type = wifi | ||
Name = #{req.body.ssid} | ||
Passphrase = #{req.body.passphrase} | ||
Nameservers = 8.8.8.8,8.8.4.4 | ||
""" | ||
|
||
Promise.all [ | ||
utils.durableWriteFile(config.connmanConfig, data) | ||
hotspot.stop() | ||
] | ||
# XXX: make it so this delay isn't needed | ||
.delay(1000) | ||
.then -> | ||
connman.waitForConnection(15000) | ||
.then -> | ||
utils.durableWriteFile(config.persistentConfig, data) | ||
.then -> | ||
process.exit() | ||
.catch (e) -> | ||
hotspot.start() | ||
|
||
app.use (req, res) -> | ||
res.redirect('/') | ||
|
||
wifiScan.scanAsync() | ||
.then (results) -> | ||
ssids = results | ||
|
||
hotspot.start() | ||
|
||
app.listen(80) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = | ||
ssid: process.env.PORTAL_SSID or 'ResinAP' | ||
passphrase: process.env.PORTAL_PASSPHRASE | ||
iface: process.env.PORTAL_INTERFACE or 'wlan0' | ||
gateway: process.env.PORTAL_GATEWAY or '192.168.42.1' | ||
dhcpRange: process.env.PORTAL_DHCP_RANGE or '192.168.42.2,192.168.42.254' | ||
connmanConfig: process.env.PORTAL_CONNMAN_CONFIG or '/host/var/lib/connman/network.config' | ||
persistentConfig: process.env.PORTAL_PERSISTENT_CONFIG or '/data/network.config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Promise = require 'bluebird' | ||
DBus = require './dbus-promise' | ||
|
||
dbus = new DBus() | ||
|
||
bus = dbus.getBus('system') | ||
|
||
SERVICE = 'net.connman' | ||
WIFI_OBJECT = '/net/connman/technology/wifi' | ||
TECHNOLOGY_INTERFACE = 'net.connman.Technology' | ||
|
||
exports.waitForConnection = (timeout) -> | ||
console.log('Waiting for connman to connect..') | ||
|
||
bus.getInterfaceAsync(SERVICE, WIFI_OBJECT, TECHNOLOGY_INTERFACE) | ||
.then (wifi) -> | ||
new Promise (resolve, reject, onCancel) -> | ||
handler = (name, value) -> | ||
if name is 'Connected' and value is true | ||
wifi.removeListener('PropertyChanged', handler) | ||
resolve() | ||
|
||
# Listen for 'Connected' signals | ||
wifi.on('PropertyChanged', handler) | ||
|
||
# # But try to read in case we registered the event handler | ||
# # after is was already connected | ||
wifi.GetPropertiesAsync() | ||
.then ({ Connected }) -> | ||
if Connected | ||
wifi.removeListener('PropertyChanged', handler) | ||
resolve() | ||
|
||
setTimeout -> | ||
wifi.removeListener('PropertyChanged', handler) | ||
reject() | ||
, timeout |
Oops, something went wrong.