Last active
December 28, 2015 20:29
-
-
Save z3a/7558122 to your computer and use it in GitHub Desktop.
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 mysql = require('mysql'); | |
var gpio = require("gpio"); | |
var moment = require('moment'); | |
var osc = require('node-osc'); | |
var _ = require('underscore'); | |
var pinNum = 17; | |
var fecha = moment('2013-11-06 11:20:35'); | |
var client = new osc.Client('192.168.2.4', 11234); | |
var connection = mysql.createConnection({ | |
host : 'localhost', | |
user : 'root', | |
database: 'muerte', | |
password : 'muerte123', | |
}); | |
connection.connect(); | |
var pin = gpio.export(pinNum, { | |
direction: "in", | |
ready: function() { | |
console.log("listo"); | |
} | |
}); | |
pin.on("change", function(val){ | |
//inserta un registro en la db | |
connection.query('insert into muerte set x=1', function(err, rows, fields) { | |
if (err){ | |
throw err; | |
} | |
console.log('Inserte un registro en la DB'); | |
//selecciona todos los registros | |
connection.query('select * from muerte', function(err, rows, fields){ | |
if (err) throw err | |
//recorre todos los registros entregados por la db | |
_(rows).each(function(item, index){ | |
console.log("Registro: ",item) //imprime cada registro | |
//en esta parte hay que crear un moment nuevo | |
//como no estoy seguro como salen los datos | |
//supongo que seria algo asi: | |
var fecha = new moment(item) //crea un nuevo moment | |
var s= fecha.get('second'); | |
var m= fecha.get('minute'); | |
var h= fecha.get('hour'); | |
var d= fecha.get('date'); | |
console.log('segundo ', s); | |
console.log('minuto ', m); | |
console.log('hora ', h); | |
console.log('dia ', d); | |
client.send(‘/segundos’, s); | |
client.send(‘/minutos’, m); | |
client.send(‘/horas’, h); | |
client.send(‘/dias’, d); | |
}) | |
}) | |
}); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment