Skip to content

Instantly share code, notes, and snippets.

@jetbalsa
Created March 5, 2018 16:20
Show Gist options
  • Save jetbalsa/e358deae4505858305836ab380dd3fda to your computer and use it in GitHub Desktop.
Save jetbalsa/e358deae4505858305836ab380dd3fda to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <Ethernet.h>
// set PushButton pin number
const int buttonPin = 2;
// set LED pin numbers
const int LED1 = 8;
const int LED2 = 9;
// set LED pin 13
const int LEDP13 = 13;
//initialising led
int LED1Status = LOW;
int LED2Status = LOW;
int buttonState;
unsigned long timePress = 0;
unsigned long timePressLimit = 0;
int clicks = 0;
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "maker.ifttt.com"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(172,16,200,234);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// put your setup code here, to run once:
// initialize the LED pin as an output:
pinMode(buttonPin ,INPUT_PULLUP);
pinMode(3 ,OUTPUT);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Ethernet.begin(mac, ip);
}
Serial.begin(9600);
Serial.println("BOOT");
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
Ethernet.maintain();
if (buttonState == LOW){
delay(200);
Serial.println("Button Pressed");
if (clicks == 0) {
timePress = millis();
timePressLimit = timePress + 1000;
clicks = 1;
}
else if (clicks == 1 && millis() < timePressLimit){
Serial.println("Button Pressed twice");
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /trigger/doorbell-2x/with/key/XXX HTTP/1.1");
client.println("Host: maker.ifttt.com");
client.println("Connection: close");
client.println();
}
//set variables back to 0
timePress = 0;
timePressLimit = 0;
clicks = 0;
}
}
if (clicks == 1 && timePressLimit != 0 && millis() > timePressLimit){
Serial.println("Button Pressed Once");
timePress = 0;
timePressLimit = 0;
clicks = 0;
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /trigger/doorbell/with/key/XXX HTTP/1.1");
client.println("Host: maker.ifttt.com");
client.println("Connection: close");
client.println();
}
}
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
client.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment