Last active
September 14, 2018 03:54
-
-
Save jschr/99cc87ee79ff976222869ac9d138a922 to your computer and use it in GitHub Desktop.
Kill resin-wifi-connect on failed attempt.
This file contains hidden or 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
import { spawn } from 'child-process-promise'; | |
import readline from 'readline'; | |
export default function wifiConnect(ssid) { | |
const promise = spawn('wifi-connect', [`--portal-ssid=${ssid}`]); | |
const childProcess = promise.childProcess; | |
readline | |
.createInterface({ | |
input: childProcess.stderr, | |
terminal: false, | |
}) | |
.on('line', line => { | |
// Kill wifi-connect when we fail to connect to the network to restart | |
// the connect loop so we can display on-screen feedback to the user. | |
// This is a workaround for https://github.com/resin-io/resin-wifi-connect/issues/224. | |
if (/Connection to access point not activated/i.test(line)) { | |
// Resolves the promise and stops wifi-connect. | |
childProcess.kill('SIGTERM'); | |
} | |
}); | |
return promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This module will launch
resin-wifi-connect
and kill the process when an unsuccessful attempt is made.resin-wifi-connect
will exit normally with a successful connection.Once the promise resolves you can ping an external service (ie. google.com) to check whether a connection was successful or failed — at which point you can surface an error message and restart
wifi-connect
.The feedback loop for the user is fairly delayed but it's better than no feedback at all.