Created
February 17, 2014 21:28
-
-
Save monteslu/9059541 to your computer and use it in GitHub Desktop.
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
var SkynetSerialPort = require('skynet-serial').SerialPort; | |
var skynet = require('skynet'); | |
var firmata = require('firmata'); | |
var myId = '26ce1ac8-2133-4faa-bcb9-3548fec5f111'; | |
var sendId = '26ce1ac8-2133-4faa-bcb9-3548farduino'; | |
var token = '2bb7507b5a74494a8be233b068d8c1f'; | |
var msgCount = 0; | |
var token, serialPort, board, firm; | |
var pinState = 1; | |
var conn = skynet.createConnection({ | |
uuid: myId, | |
token: token | |
//protocol: "mqtt", | |
//qos: 0 // MQTT Quality of Service (0=no confirmation, 1=confirmation, 2=not supported) | |
}); | |
conn.on('notReady', function(data){ | |
console.log('UUID FAILED AUTHENTICATION!', data); | |
// Register device | |
conn.register({ | |
uuid: myId, | |
token: token, | |
type: 'serial' | |
}, function (data) { | |
console.log('registered', data); | |
conn.emit('ready', data); | |
}); | |
}); | |
conn.on('ready', function(data){ | |
console.log('UUID AUTHENTICATED!', data); | |
serialPort = new SkynetSerialPort(conn, sendId); | |
firm = new firmata.Board(serialPort, function (err, ok) { | |
if (err){ | |
console.log('could node connect to board' , err); | |
throw err; | |
} | |
console.log("board loaded", ok); | |
// board = new five.Board({io: firm}); | |
//board.on("ready", function() { | |
// Create an Led on pin 13 and strobe it on/off | |
// Optionally set the speed; defaults to 100ms | |
// (new five.Led(13)).strobe(); | |
// }); | |
togglePin(); | |
}); | |
}); | |
function togglePin(){ | |
console.log('toggling', pinState); | |
if(pinState){ | |
pinState = 0; | |
}else{ | |
pinState = 1; | |
} | |
firm.digitalWrite(13, pinState); | |
setTimeout(togglePin, 750); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment