You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • It turns out IFTTT have a Maker Channel now, which means you can trigger loads of random stuff (tweeting, emails, etc) to happen on the net really easily (thanks for letting me know @Ollie!).

    To use it:

    • Connect Espruino to an ESP8266 WiFi module
    • Go to IFTTT and make an account
    • Go to https://ifttt.com/maker, enable it, and copy your secret key.
    • Then copy the code at the bottom into the Web IDE, and paste your key into the IFTTTKEY variable. Also set up your WiFi access point name and password, and then write the code to Espruino.
    • Create a recipe, click this and choose Maker, then Receive a web request
    • Put button_pressed as the event name
    • Click that and choose whatever you want to happen
    • Make sure you click all the way through the options to enable your recipe
    • Press the button on your Espruino :)

    This code actually resets your ESP8266 and connects to the wireless network each time you press the button. It takes a bit longer, but it's much more reliable as the ESP8266 will start from the same state each time.

    Going back the other way (using Espruino as the that) is a bit more painful at the moment, because IFTTT expects to send a request to a web server that's available from the net. Does anyone have any good solutions to that?


    var APNAME = "...";
    var APKEY  = "...";
    var IFTTTEVENT = "button_pressed";
    var IFTTTKEY = "...";
    
    var working = false;
    var wifi;
    
    Serial2.setup(9600, { rx: A3, tx : A2 });
    
    function buttonPressed() {
      if (working) {
        console.log("Busy...");
        return;
      }
      working = true;
      console.log("Resetting ESP8266");
      wifi.reset(function(err) {
        if (err) {
          working = false;
          throw err;
        }
        console.log("Connecting to WiFi");
        wifi.connect(APNAME,APKEY, function(err) {
          if (err) {
            working = false;
            throw err;
          }
          console.log("Connected");
          // Now finally
          require("http").get("http://maker.ifttt.com/trigger/"+IFTTTEVENT+"/with/key/"+IFTTTKEY, function(res) {
            working = false;
            console.log("Response: ",res);
            var data = "";
            res.on('data', function(d) { data += d; });
            res.on('close', function(d) {
              console.log("--->"+data);
            });
          });
        });
      });
    }
    
    function onInit() {
      wifi = require("ESP8266WiFi").connect(Serial2, function(err) {
        if (err) throw err;
        console.log("ESP8266 connected");
      });
    }
    
    setWatch(buttonPressed, BTN, { debounce:100, repeat:true, edge:"rising" });
    
About

Avatar for Gordon @Gordon started