-
-
Save Frijol/0d2d7175f541dc215c23 to your computer and use it in GitHub Desktop.
Gets wifi on and keeps it alive on a Tessel
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
var wifi = require('wifi-cc3000'); | |
var wifiSettings = { | |
ssid: "technicallyWifi", | |
password: "scriptstick", | |
timeout: 40 | |
}; | |
var port = 8000; | |
var connected = false; | |
var debug = false; | |
function checkConnection () { | |
if (wifi.isConnected()) { | |
if (debug) { | |
console.log('Connected!'); | |
} | |
if (!connected) { | |
connected = true; | |
console.log('Executing.'); | |
} | |
} else { | |
if (debug) { | |
console.log('Connecting...'); | |
} | |
wifi.connect(wifiSettings, function (err, res) { | |
if(err & debug) { | |
console.log('Error connecting:', err); | |
} | |
checkConnection(); | |
}); | |
} | |
} | |
wifi.on('connect', function () { | |
if (debug) { | |
console.log('Connected.'); | |
} | |
checkConnection(); | |
}); | |
wifi.on('disconnect', function () { | |
if (debug) { | |
console.log('Disconnected.'); | |
} | |
if (connected) { | |
connected = false; | |
console.log('Execution stopped.'); | |
} | |
checkConnection(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment