Skip to content

Instantly share code, notes, and snippets.

@andysheen
Last active January 13, 2020 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andysheen/449cde01040ba39ccbe6e58b590b6d64 to your computer and use it in GitHub Desktop.
Save andysheen/449cde01040ba39ccbe6e58b590b6d64 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
// Change these to the WiFi credentials
#define WLAN_SSID "WIFINAME"
#define WLAN_PASS "PASSWORD"
#define BUTTON 4
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(WLAN_SSID, WLAN_PASS);
Serial.println("");
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(10);
}
Serial.println("");
Serial.println("Connected!");
pinMode(BUTTON, INPUT_PULLUP);
}
void loop() {
// Read button
int buttonValue = digitalRead(BUTTON);
if (buttonValue == LOW) {
Serial.println("Button pressed! Sending request to IFTTT...");
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// Change the below address to the one from your IFTTT account.
http.begin("http://maker.ifttt.com/trigger/button_pressed/with/key/yourKeyhere");
int httpCode = http.GET();
Serial.print("HTTP code: ");
Serial.println(httpCode);
if (httpCode == HTTP_CODE_OK) {
Serial.println("Request sent!");
}
delay(2000);
http.end();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment