Skip to content

Instantly share code, notes, and snippets.

@error454
Created October 8, 2012 04:01
Show Gist options
  • Save error454/3850656 to your computer and use it in GitHub Desktop.
Save error454/3850656 to your computer and use it in GitHub Desktop.
on{X} Disable/Enable WiFI when leaving/entering home
var home = {
name : "home",
latitude : "0",
longitude : "0",
location : "Home"
};
function createRegion(location, enterFunction, exitFunction){
var region = device.regions.createRegion({
latitude: parseFloat(location.latitude, 10),
longitude: parseFloat(location.longitude, 10),
name: location.name,
radius: 500
});
region.on("enter", enterFunction);
region.on("exit", exitFunction);
device.regions.startMonitoring(region);
return region;
}
function DisableWifi() {
console.log("Disabling wifi");
device.network.wifiEnabled = false;
}
function EnableWifi() {
console.log("Enabling wifi");
device.network.wifiEnabled = true;
}
device.regions.stopMonitoringAll();
createRegion(home, EnableWifi, DisableWifi);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment