Paso 4: Programar al diablillo eléctrico
En el Electric Imp IDE pegue este código en el "Agente" y el "Dispositivo" reemplazar los *** inserte clave aquí *** con tu clave de fabricante de IFTTT del paso 3.
Agente:
#require "IFTTT.class.nut:1.0.0" device.on("on", function(feedCSV) { //take csv body in from device HttpGetWrapper("https://maker.ifttt.com/trigger/switch-pressed-on/with/key/***Insert Key Here***"); server.log("On trigger sent to IFTTT Maker"); }); device.on("off", function(feedCSV) { //take csv body in from device HttpGetWrapper("https://maker.ifttt.com/trigger/switch-pressed-off/with/key/***Insert Key Here***"); server.log("Off trigger sent to IFTTT Maker"); }); function HttpGetWrapper (url) { local request = http.get(url); local response = request.sendsync(); return response; }
Dispositivo de:
#require "Button.class.nut:1.1.0" button <- Button(hardware.pin1, DIGITAL_IN_PULLUP, Button.NORMALLY_HIGH, function(){ server.log("'All On' button pressed"); agent.send("on", "on, 0"); ;} ); button <- Button(hardware.pin2, DIGITAL_IN_PULLUP, Button.NORMALLY_HIGH, function(){ server.log("'All Off' button pressed"); agent.send("off", "off, 0"); ;} );