Last active
October 15, 2015 20:29
-
-
Save yoshidaken1/7756ffed21a81f3f54b5 to your computer and use it in GitHub Desktop.
SORACOM Airのプラン(速度)を4つのスイッチ(Button)で変更するNode.jsスクリプト
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 Soracom = require('soracom'); | |
var soracom = new Soracom({ | |
apiKey: '...myApiKey', | |
operatorId: '...myOpId', | |
token: '...myToken' | |
}); | |
soracom.get('/operators/:operatorId', function(err, res, operator) { | |
console.log(res); | |
}); | |
var myImsi = '123456789012345'; | |
var raspi = require('raspi-io'); | |
var five = require("johnny-five"), | |
board = new five.Board({ | |
io: new raspi(), | |
repl: false | |
}); | |
board.on("ready", function() { | |
var btn_min = new five.Button('P1-7'); //s1.minimum用スイッチ | |
var btn_slow = new five.Button('P1-11');//s1.slow用スイッチ | |
var btn_std = new five.Button('P1-13'); //s1.standard用スイッチ | |
var btn_fast = new five.Button('P1-15');//s1.fast用スイッチ | |
var led = new five.Led('P1-18');//速度を点滅で表すLED | |
//スイッチが押された時に実行される | |
btn_min.on("down", function() { | |
console.log("min押された"); | |
led.blink(200); | |
soracom.post('/subscribers/:imsi/update_speed_class', | |
{ imsi: myImsi , speedClass: "s1.minimum"}, | |
function(err, res, body) { | |
console.log(res); | |
} | |
); | |
}); | |
btn_slow.on("down", function() { | |
console.log("slow押された"); | |
led.blink(100); | |
soracom.post('/subscribers/:imsi/update_speed_class', | |
{ imsi: myImsi , speedClass: "s1.slow"}, | |
function(err, res, body) { | |
console.log(res); | |
} | |
); | |
}); | |
btn_std.on("down", function() { | |
console.log("standard押された"); | |
led.blink(70); | |
soracom.post('/subscribers/:imsi/update_speed_class', | |
{ imsi: myImsi , speedClass: "s1.standard"}, | |
function(err, res, body) { | |
console.log(res); | |
} | |
); | |
}); | |
btn_fast.on("down", function() { | |
console.log("fast押された"); | |
led.blink(40); | |
soracom.post('/subscribers/:imsi/update_speed_class', | |
{ imsi: myImsi , speedClass: "s1.fast"}, | |
function(err, res, body) { | |
console.log(res); | |
} | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment