Connecting ESP32 to the Outside World with IFTTT
Accompanying code for Arduino IDE, as shown in the video, below.
// ESP32 Code for testing IFTTT
// Sends a request to STATUSUPDATE (or whatever you define) applet which will trigger an e-mail being sent
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "*****"; //input your wifi name
const char* password = "*****"; //input your wifi passwords
// set up server name with trigger the event defined in the
IFTTT applet
const char* server_name = "https://maker.ifttt.com/trigger/EVENT_NAME_HERE/with/key/KEYHERE";
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
WiFi.begin(ssid,
password);
while (WiFi.status() !=
WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("Msg: Ready! Use 'http://");
Serial.print(WiFi.localIP());
Serial.println("' to connect");
}
void loop() {
delay(500);
Serial.println("Go...");
// wait for serial input to send out as part of http
request
while (Serial.available() == 0){}
String testStr = Serial.readString();
testStr.trim();
if (testStr != "Skip")
{
// check WiFi status
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http;
http.begin(server_name);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Define data to send with HTTP POST
request; in this case, whatever was input on the serial interface
String httpRequestData = "value1=" + testStr;
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
Serial.print("HTTP Response Code: ");
Serial.println(httpResponseCode);
}
} else
{
Serial.println("Skip");
}
}
// Sends a request to STATUSUPDATE (or whatever you define) applet which will trigger an e-mail being sent
#include <WiFi.h>
#include <HTTPClient.h>
const char* password = "*****"; //input your wifi passwords
const char* server_name = "https://maker.ifttt.com/trigger/EVENT_NAME_HERE/with/key/KEYHERE";
Serial.begin(115200);
delay(500);
Serial.println("");
while (Serial.available() == 0){}
String testStr = Serial.readString();
{
// check WiFi status
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http;
String httpRequestData = "value1=" + testStr;
int httpResponseCode = http.POST(httpRequestData);
} else
{
Serial.println("Skip");
}
Comments
Post a Comment