Created
          February 28, 2019 00:02 
        
      - 
      
 - 
        
Save rodvan/503b6cd1cb4d74b1d70eea15a8b2f4b5 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
rodvan created this gist
Feb 28, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ var mqtt = require('mqtt') //var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO var LEDA = new Gpio(3, 'out'); //use GPIO pin 4, and specify that it is output var LEDB = new Gpio(4, 'out'); //use GPIO pin 4, and specify that it is output const say = require('say') function esperando() { // stuff you want to happen right away console.log('Prendiendo foco y esperando 2 segundos'); } var options = { port: 1883, //host: mqtt_config.noclass_url, host: "192.168.5.10", // The CA list will be used to determine if server is authorized protocol: 'mqtt' } var client = mqtt.connect(options) // SUSCRIBIR A ACTIVIDADES PARA REGISTRARLAS client.on('connect', function () { console.log('Conectado a MQTT con exito.') client.subscribe('#') }) client.on('message', function (topic, message) { msg = message.toString() if(topic === "/cocoa/caseta/rfid/a") { if(msg === "abrir") { console.log("Aqui suena ruido y se prende foco de la A") say.speak("Welcome A", 'Samantha', 1) LEDA.writeSync(1); //set pin state to 1 (turn LED on) setTimeout(esperando, 2000); LEDA.writeSync(0); //set pin state to 0 (turn LED off) // prender foco } } else if(topic === "/cocoa/caseta/rfid/b") { if(msg === "abrir") { console.log("Aqui suena ruido y se prende foco de la B") say.speak("Welcome B", 'Samantha', 1) LEDB.writeSync(1); //set pin state to 1 (turn LED on) setTimeout(esperando, 2000); LEDB.writeSync(0); //set pin state to 0 (turn LED off) } } }) client.on('error', function(err) { console.log(err); });