Last active
August 29, 2015 14:09
-
-
Save ifavo/d3cc923dca4c94526f35 to your computer and use it in GitHub Desktop.
wifi
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 wlan; | |
var fs = require('fs'); | |
function log (txt) { | |
console.log(txt); | |
fs.appendFileSync('log.txt', '[' + new Date().getTime() + '] ' + txt + '\r\n'); | |
} | |
function showLog() { | |
console.log(fs.readFileSync('log.txt')); | |
} | |
function c() { | |
log('loading module'); | |
wlan = require("CC3000").connect(); | |
log("triggering connect"); | |
return wlan.connect( "<network id>", "<network password>", function (s) { | |
LED2.write(1); | |
log("connect callback"); | |
log(JSON.stringify(s)); | |
if ( s == "dhcp" ) { | |
LED3.write(1); | |
console.log(wlan.getIP()); | |
} | |
}); | |
} | |
function r() { | |
return wlan.reconnect(); | |
} | |
function d() { | |
return wlan.disconnect(); | |
} | |
log('start up...'); | |
[LED1,LED2,LED3].forEach(function(led){led.write(1);}); | |
setTimeout("[LED1,LED2,LED3].forEach(function(led){led.write(0);});", 1000); | |
setTimeout(c,2000); | |
showLog(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment