Last active
December 8, 2017 05:06
-
-
Save mkamakura/38b657afdbb1f68a24e43034655bf10b to your computer and use it in GitHub Desktop.
Connect Starbucks Wifi automatically.
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
// * install | |
// npm install -g node-wifi net-ping | |
// * usage | |
// node connect_starbucks_wifi.js | |
const ping = require('net-ping') | |
const wifi = require('node-wifi') | |
setInterval(connection, 5000) | |
function connection() { | |
const session = ping.createSession() | |
session.pingHost('8.8.8.8', (err, target) => { | |
if (err) { | |
console.error(target, ':', err.toString()) | |
console.log('start: try to connect startbucks wifi') | |
connectStarbucksWifi() | |
} else { | |
console.log('connected:', new Date().toLocaleString('ja')) | |
} | |
}) | |
} | |
function connectStarbucksWifi() { | |
wifi.init({ | |
iface: null | |
}) | |
const STARBUCKS_SSID = 'at_STARBUCKS_Wi2' | |
wifi.scan().then(networks => { | |
if (networks.find(network => network.ssid === STARBUCKS_SSID)) { | |
wifi.connect({ ssid: STARBUCKS_SSID }) | |
.then(() => console.log('connected:', STARBUCKS_SSID)) | |
.catch(err => console.error()) | |
} else { | |
console.error('cannot find:', STARBUCKS_SSID) | |
} | |
}).catch(err => console.error(err)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment