At the time this course was created, IFTTT would not accept JSON objects in HTTP requests from the Tinkercad simulator. However, we can still pass JSON objects from a real ESP8266. If you are using real hardware to complete this course, then I recommend following along with this example. Otherwise, you are welcome to skip it or read it just to have the information.

Log in to IFTTT and click on “My Applets.” Find the applet you created for the previous lecture, which should have “my_reminder” as the maker Event.

Click the gear icon in the upper-right corner of the applet to edit it. Scroll down and click “Add ingredient” below “Body.” Select “Value1” and you should see it appear in the body.

Value1 is the name of a variable. Will will pass in a JSON object containing the key “Value1” and some value for it with our POST request from the ESP8266. IFTTT will read this value and copy it into the email body. This way, we can send different messages to ourselves from the ESP8266 using one IFTTT applet. Click “Save.”

To accomplish this, we need to include the “Content-Type” and “Content-Length” header fields in the POST request. We tell the server that we want to send data of type “application/json,” include the number of characters in our JSON object (“Content-Length”), and then write out our key-value pair in JSON notation in the body of the HTTP request (after the blank line). Here is what our POST request will look like

POST /trigger/my_reminder/with/key/<YOUR KEY> HTTP/1.1\r\n
Host: maker.ifttt.com\r\n
Content-Type: application/json\r\n
Content-Length: 27\r\n
Connection: close\r\n
\r\n
{“value1”:”You need bread”}\r\n

We just need to send this from our ESP8266. Open the Arduino code from the “Making Requests to IFTTT” lecture. Add a line to store the body of the HTTP request (note that we need to use the \” escape character in order to put double quotation marks in the JSON--otherwise, C thinks we’re trying to close the string). You’ll also need to modify the request string to include our new header fields and request body. The code in its entirety is copied below. You’ll need to change the SSID, WiFi password, and IFTTT key.

#include <ESP8266WiFi.h>

// WiFi config
const char ssid[] = "<YOUR SSID>";
const char password[] = "<YOUR WIFI PASSWORD>";

// IFTTT settings
const String ifttt_trigger = "my_reminder";
const String ifttt_key = "<IFTTT KEY>";

// HTTP POST body
const String body = "{\"value1\":\"You need bread\"}";

// Server, file, and port
const char hostname[] = "maker.ifttt.com";
const String uri = "/trigger/" + ifttt_trigger +
            "/with/key/" + ifttt_key;
const int port = 80;

// WiFi Client
WiFiClient client;

void setup() {

  // Init Serial
  Serial.begin(9600);
  delay(100);

  // Connect to WiFi
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED ) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  // Show we are connected
  Serial.println("Connected!");
}

void loop() {

  // Establish TCP connection
  Serial.print("Connecting to ");
  Serial.println(hostname);
  if ( !client.connect(hostname, port) ) {
    Serial.println("Connection failed");
  }

  // Send request
  String req = "POST " + uri + " HTTP/1.1\r\n" +
                "Host: " + hostname + "\r\n" +
                "Content-Type: application/json\r\n" +
                "Content-Length: " + body.length() + "\r\n" +
                "Connection: close\r\n" +
                "\r\n" +
                body + "\r\n";
  client.print(req);
  delay(500);

  // Print response
  while ( client.available() ) {
    String ln = client.readStringUntil('\r');
    Serial.print(ln);
  }

  // Close TCP connection
  client.stop();
  Serial.println();
  Serial.println("Connection closed");

  delay(60000);
}

Upload this to your ESP8266 board. Open a Serial monitor and make sure it connects to your WiFi. Once it does, it should begin sending you a reminder that you need bread once every minute.

You could do something like connect several buttons to your ESP8266 and each one sends you a different reminder message.