Original code (tested and works but gets repeat triggers):
#include <ESP8266Webhook.h>
#include <ESP8266WiFi.h>
#define wakePin 16
#define _SSID "xxxxssid" // Your WiFi SSID
#define _PASSWORD "xxxxpw" // Your WiFi Password
#define KEY "xxxxwhkey" // Webhooks Key
#define EVENT "xxxxevent" // Webhooks Event Name
Webhook webhook(KEY, EVENT); // Create an object.
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(1000);
// Connect to WiFi
Serial.println();
Serial.println();
Serial.print("Connecting to: ");
Serial.println(_SSID);
WiFi.begin(_SSID, _PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
digitalWrite(LED_BUILTIN, HIGH);
//================================================================//
//================================================================//
// Trigger without any value and get response.
int response = webhook.trigger();
if(response == 200)
Serial.println("OK");
else
Serial.println("Failed");
ESP.deepSleep(wakePin);
}
void loop() {
// Nothing
}
EZButton code:
#include <ezButton.h>
#include <ESP8266Webhook.h>
#include <ESP8266WiFi.h>
#define _SSID "xxxxssid" // Your WiFi SSID
#define _PASSWORD "xxxxpw" // Your WiFi Password
#define KEY "xxxxwhk" // Webhooks Key
#define EVENT "xxxxevent" // Webhooks Event Name
Webhook webhook(KEY, EVENT); // Create an object.
ezButton button(16); // create ezButton object that attach to pin 16;
void setup() {
Serial.begin(9600);
button.setDebounceTime(20000); // set debounce time to 20 seconds
}
void loop() {
button.loop(); // MUST call the loop() function first
if(button.isPressed()) {
Serial.println("The button has been pressed for 20 seconds");
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(1000);
// Connect to WiFi
Serial.println();
Serial.println();
Serial.print("Connecting to: ");
Serial.println(_SSID);
WiFi.begin(_SSID, _PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
digitalWrite(LED_BUILTIN, HIGH);
//================================================================//
//================================================================//
// Trigger without any value and get response.
int response = webhook.trigger();
if(response == 200)
Serial.println("OK");
else
Serial.println("Failed");
}
}
Buttondebouncer code:
#include <Arduino.h>
#include <ButtonDebouncer.h>
#include <ESP8266Webhook.h>
#include <ESP8266WiFi.h>
#define BUTTON_PIN 16
#define CUSTOM_DEBOUNCE_DELAY 20000
// Time the library waits for a second (or more) clicks
// Set to 0 to disable double clicks but get a faster response
#define CUSTOM_REPEAT_DELAY 0
#define _SSID "xxxxssid" // Your WiFi SSID
#define _PASSWORD "xxxxpw" // Your WiFi Password
#define KEY "xxxxwhk" // Webhooks Key
#define EVENT "xxxxevent" // Webhooks Event Name
Webhook webhook(KEY, EVENT); // Create an object.
ButtonDebouncer * button;
void setup() {
Serial.begin(9600);
Serial.println();
Serial.println();
button = new ButtonDebouncer(BUTTON_PIN, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH | BUTTON_SET_PULLUP, CUSTOM_DEBOUNCE_DELAY, CUSTOM_REPEAT_DELAY);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(1000);
}
void loop() {
if (unsigned int event = button->loop()) {
if (event == EVENT_RELEASED) {
Serial.print("Count : "); Serial.print(button->getEventCount());
Serial.print(" Length: "); Serial.print(button->getEventLength());
Serial.println();
}
// Connect to WiFi
Serial.println();
Serial.println();
Serial.print("Connecting to: ");
Serial.println(_SSID);
WiFi.begin(_SSID, _PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
digitalWrite(LED_BUILTIN, HIGH);
//================================================================//
//================================================================//
// Trigger without any value and get response.
int response = webhook.trigger();
if(response == 200)
Serial.println("OK");
else
Serial.println("Failed");
}
}