Julio César Rodríguez Domínguez
NodeBotsMx Foounder
@_JuraseC

La comunidad de NodebotsMx

http://www.meetup.com/es-ES/NodeBotsMX/
La comunidad de NodebotsMx













Pero... ¿qué es un nodebot?


Nodebot




Nodebot
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Create a standard `led` component instance
var led = new five.Led(13);
// "blink" the led in 500ms
// on-off phase periods
led.blink(500);
});

1. $ npm install johnny-five
2. Cargar StandardFirmata en Arduino
$ node index.js
index.js

Ejemplos !

Sensor de pulsos

serialPort.open(function (error) {
if ( error ) console.log('failed to open: '+error);
else {
serialPort.on('data', function(data) {
if( data != "\n" && data.substring(0,1) == 'S'){
console.log('data received: ' + data)
app.io.broadcast('data', {
data: data.substring(1)
})
}
else console.log('>>>>>>>>>>>>> ', data)
});
}
});

Vending Machine

stream.on('follow', function ( user ) {
var user = user.source.screen_name;
if (follower.toLowerCase() == user.toLowerCase())
{
//Se activa el servo, por dos segundos
console.log('tenga buen hombre su regalo!')
servo.ccw();
sleep.sleep(2);
servo.stop();
}
})

Vending Machine
var five = require('johnny-five'),
sleep = require('sleep'),
express = require('express.io'),
path = require('path'),
app = express(),
board,
userFollowingUs;
app.http().io();
app.use( express.static( path.join( __dirname, 'public' ) ) )
var board = new five.Board({port: 'COM11'});
board.on("ready", function() {
var servo = new five.Servo({
pin: 10,
type: "continuous"
});
var Twit = require('twit')
var T = new Twit({
consumer_key: key,
consumer_secret: secret,
access_token: accessToken,
access_token_secret: accessTokenSecret,
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
})
var stream = T.stream( 'user' )
stream.on('follow', function ( user ) {
console.log( user )
if ( userFollowingUs.toLowerCase() == user.source.screen_name.toLowerCase() ){
//Se activa el servo, por dos segundos
console.log('tenga buen hombre su regalo!')
servo.ccw();
sleep.sleep(2);
servo.stop();
}
})
app.io.route('click', function( request ) {
console.log( '=> User: ', request.data.user )
userFollowingUs = request.data.user
//led.color( request.data.color )
})
app.set('port', process.env.PORT || 3000)
var server = app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + server.address().port)
})
})
var button = document.getElementById('button');
io = io.connect();
button.onclick = function(){
user = document.getElementById('input').value
label = document.getElementById('label');
label.innerHTML = user + " gracias por seguirnos!";
/* Emitimos el evento click, para notificar al servidor. */
io.emit('click', { user: user });
}
cliente
servidor

Gracias!
@_JuraseC
http://www.meetup.com/es-ES/NodeBotsMX/
https://www.facebook.com/NodeBotsMX
@nodebotsmx
Flisol 2016 - FES Acatlán
By Julio César
Flisol 2016 - FES Acatlán
- 1,437