IFTTTWebhook
IFTTTWebhook copied to clipboard
Example Needs ESP32 support
trafficstars
The single example in this library has include #include <ESP8266Wifi.h>which obviously wont run for the ESP32
We can either include a IFDEF or create two separate files for ESP8266 and ESP32 which I think is a cleaner approach.
I dont know yet how pull requests work, but i think that i how i would make a copy of your code and send you an update. I dont know how that works, but Here are the code changes I did to enable the example to work..
- I switched the include to the one for ESP32 which is #include <WiFi.h>
- The second is which needs to be considered is that the code tries to connect to wifi and immediately makes a web request to IFTTT, which is probably not how it should be handled. The time to negotiate with the Wifi router is significant and no requests should be made to do anything with Wifi unless it is connected. We need to add the following section in setup function
WiFi.mode(WIFI_STA);
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(WIFI_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
Here is how my complete code looks like
#include <WiFi.h>
#include "IFTTTWebhook.h"
#define WIFI_SSID "Wifi SSID Here"
#define WIFI_PASSWORD "wifi password here"
#define IFTTT_API_KEY "IFTTT maker webhook key"
#define IFTTT_EVENT_NAME "webhook event name"
void setup() {
Serial.begin(115200);
Serial.println("RUNNING");
WiFi.mode(WIFI_STA);
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(WIFI_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
IFTTTWebhook wh(IFTTT_API_KEY, IFTTT_EVENT_NAME);
wh.trigger();
wh.trigger("1");
wh.trigger("1", "2");
wh.trigger("1", "2", "3");
}
void loop() {
}
Thanks for making my life so much easier by creating this library.
Rupin