├── keywords.txt ├── .gitignore ├── examples └── ifttt_webhook_demo │ └── ifttt_webhook_demo.ino ├── src ├── IFTTTWebhook.h └── IFTTTWebhook.cpp ├── LICENSE └── README.md /keywords.txt: -------------------------------------------------------------------------------- 1 | IFTTTWebhook KEYWORD1 2 | trigger KEYWORD2 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /examples/ifttt_webhook_demo/ifttt_webhook_demo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "IFTTTWebhook.h" 3 | 4 | #define WIFI_SSID "your SSID here" 5 | #define WIFI_PASSWORD "your password here" 6 | 7 | #define IFTTT_API_KEY "your key here" 8 | #define IFTTT_EVENT_NAME "your event name here" 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | Serial.println("RUNNING"); 13 | 14 | WiFi.mode(WIFI_STA); 15 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 16 | 17 | IFTTTWebhook wh(IFTTT_API_KEY, IFTTT_EVENT_NAME); 18 | wh.trigger(); 19 | wh.trigger("1"); 20 | wh.trigger("1", "2"); 21 | wh.trigger("1", "2", "3"); 22 | } 23 | 24 | void loop() { 25 | } 26 | -------------------------------------------------------------------------------- /src/IFTTTWebhook.h: -------------------------------------------------------------------------------- 1 | /* 2 | IFTTTWebhook.h 3 | Created by John Romkey - https://romkey.com/ 4 | March 24, 2018 5 | */ 6 | #ifndef IFTTT_H 7 | #define IFTTT_H 8 | 9 | #define DEFAULT_IFTTT_FINGERPRINT "C0:5D:08:5E:E1:3E:E0:66:F3:79:27:1A:CA:1F:FC:09:24:11:61:62" 10 | 11 | class IFTTTWebhook { 12 | public: 13 | IFTTTWebhook(const char* api_key, const char* event_name); 14 | IFTTTWebhook(const char* api_key, const char* event_name, const char* ifttt_fingerprint); 15 | 16 | int trigger(const char* value1, const char* value2, const char* value3); 17 | int trigger(const char* value1, const char* value2); 18 | int trigger(const char* value1); 19 | int trigger(); 20 | 21 | private: 22 | const char* _api_key; 23 | const char* _event_name; 24 | const char* _ifttt_fingerprint; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 John Romkey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IFTTTWebHook ESP8266/ESP32 library 2 | 3 | __I no longer have time to maintain this library and am withdrawing it. I'll leave the repo around archived. Please don't use this library.__ 4 | 5 | This is a small library that calls [IFTTT](https://ifttt.com) web 6 | hooks from your ESP8266 or ESP32 Arduino project. 7 | 8 | [IFTTT webhooks](https://ifttt.com/maker_webhooks) allow you to trigger IFTTT actions from your project. You might trigger an action because a button has been pushed, a temperature threshold has been passed, or just because you feel like it. You can pass up to three values with the trigger. 9 | 10 | An action can be any IFTTT action: 11 | - send an email or text message 12 | - turn on a light 13 | - add values to a Google Sheet 14 | - call a webhook on another service 15 | 16 | ## Usage 17 | 18 | 1. If you haven't already, add the library to your Arduino project. Either: 19 | - use "Manage Libraries" under the Sketch menu, locate `IFTTTWebhook` and install it 20 | or 21 | - download https://github.com/romkey/IFTTTWebhook/archive/master.zip and install it using "Add Zip" under the Sketch menu 22 | 23 | 2. Include the library in your project: 24 | ``` 25 | #include 26 | ``` 27 | 28 | 3. You'll need an IFTTT account, an IFTTT API key for that an account and a webhook event name. 29 | 30 | Once you're logged into IFTTT you can get your API key by going to https://ifttt.com/maker_webhooks and clicking the `Documentation` button. 31 | 32 | Instantiate an `IFTTTWebhook` object using your API key and the event name: 33 | 34 | ``` 35 | IFTTTWeb webhook(YOUR_IFTTT_API_KEY, YOUR_IFTTT_EVENT_NAME); 36 | ``` 37 | 38 | When you want to trigger the webhook, call the `trigger` method with zero to three `char*` to be passed as values: 39 | ``` 40 | webhook.trigger(); 41 | webhook.trigger("value1"); 42 | webhook.trigger("value1", "value2"); 43 | webhook.trigger("value1", "value2", "value3"); 44 | ``` 45 | 46 | You can trigger using the same webhook object as many times as you want. 47 | -------------------------------------------------------------------------------- /src/IFTTTWebhook.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | IFTTTWebhook.cpp 3 | Created by John Romkey - https://romkey.com/ 4 | March 24, 2018 5 | */ 6 | 7 | #ifndef ESP32 8 | #include 9 | #include 10 | #endif 11 | 12 | #ifdef ESP32 13 | #include 14 | #include 15 | #endif 16 | 17 | #include "IFTTTWebhook.h" 18 | 19 | IFTTTWebhook::IFTTTWebhook(const char* api_key, const char* event_name) : IFTTTWebhook::IFTTTWebhook(api_key, event_name, DEFAULT_IFTTT_FINGERPRINT) { 20 | } 21 | 22 | IFTTTWebhook::IFTTTWebhook(const char* api_key, const char* event_name, const char* ifttt_fingerprint) { 23 | _api_key = api_key; 24 | _event_name = event_name; 25 | _ifttt_fingerprint = ifttt_fingerprint; 26 | } 27 | 28 | int IFTTTWebhook::trigger() { 29 | return IFTTTWebhook::trigger(NULL, NULL, NULL); 30 | } 31 | 32 | int IFTTTWebhook::trigger(const char* value1) { 33 | return IFTTTWebhook::trigger(value1, NULL, NULL); 34 | } 35 | 36 | int IFTTTWebhook::trigger(const char* value1, const char* value2) { 37 | return IFTTTWebhook::trigger(value1, value2, NULL); 38 | } 39 | 40 | #ifdef ESP32 41 | const char* _ifttt_root_certificate = \ 42 | "-----BEGIN CERTIFICATE-----\n" \ 43 | "MIIE0DCCA7igAwIBAgIBBzANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCVVMx" \ 44 | "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoT" \ 45 | "EUdvRGFkZHkuY29tLCBJbmMuMTEwLwYDVQQDEyhHbyBEYWRkeSBSb290IENlcnRp" \ 46 | "ZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTExMDUwMzA3MDAwMFoXDTMxMDUwMzA3" \ 47 | "MDAwMFowgbQxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6b25hMRMwEQYDVQQH" \ 48 | "EwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjEtMCsGA1UE" \ 49 | "CxMkaHR0cDovL2NlcnRzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkvMTMwMQYDVQQD" \ 50 | "EypHbyBEYWRkeSBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5IC0gRzIwggEi" \ 51 | "MA0G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DZ2HKocyQetawi" \ 66 | "DsoXiWJYRBuriSUBAA/NxBti21G00w9RKpv0vHP8ds42pM3Z2Czqrpv1KrKQ0U11" \ 67 | "GIo/ikGQI31bS/6kA1ibRrLDYGCD+H1QQc7CoZDDu+8CL9IVVO5EFdkKrqeKM+2x" \ 68 | "LXY2JtwE65/3YR8V3Idv7kaWKK2hJn0KCacuBKONvPi8BDAB" \ 69 | "-----END CERTIFICATE-----\n"; 70 | #endif 71 | 72 | int IFTTTWebhook::trigger(const char* value1, const char* value2, const char* value3) { 73 | HTTPClient http; 74 | const char* ifttt_base = "https://maker.ifttt.com/trigger"; 75 | 76 | int url_length = strlen(ifttt_base) + strlen("/") + strlen(_event_name) + strlen("/with/key/") + strlen(_api_key) + strlen("?") + (strlen("&valuex=")*3); 77 | url_length += (value1 ? strlen(value1) : 0) + (value2 ? strlen(value2) : 0) + (value3 ? strlen(value3) : 0); 78 | url_length += 5; 79 | char ifttt_url[url_length]; 80 | 81 | #ifdef IFTTT_WEBHOOK_DEBUG 82 | Serial.print("URL length: "); 83 | Serial.println(url_length); 84 | #endif 85 | 86 | snprintf(ifttt_url, url_length, "%s/%s/with/key/%s", ifttt_base, _event_name, _api_key); 87 | if(value1 || value2 || value3) { 88 | strcat(ifttt_url, "?"); 89 | } 90 | 91 | if(value1) { 92 | strcat(ifttt_url, "value1=\""); 93 | strcat(ifttt_url, value1); 94 | strcat(ifttt_url, "\""); 95 | if(value2 || value3) { 96 | strcat(ifttt_url, "&"); 97 | } 98 | } 99 | 100 | if(value2) { 101 | strcat(ifttt_url, "value2=\""); 102 | strcat(ifttt_url, value2); 103 | strcat(ifttt_url, "\""); 104 | if(value3) { 105 | strcat(ifttt_url, "&"); 106 | } 107 | } 108 | 109 | if(value3) { 110 | strcat(ifttt_url, "value3=\""); 111 | strcat(ifttt_url, value3); 112 | strcat(ifttt_url, "\""); 113 | } 114 | 115 | #ifdef IFTTT_WEBHOOK_DEBUG 116 | Serial.println(ifttt_url); 117 | #endif 118 | 119 | #ifdef ESP32 120 | // certificate: openssl s_client -showcerts -connect maker.ifttt.com:443 < /dev/null 121 | http.begin(ifttt_url, _ifttt_root_certificate); 122 | #else 123 | // fingerprint: openssl s_client -connect maker.ifttt.com:443 < /dev/null 2>/dev/null | openssl x509 -fingerprint -noout | cut -d'=' -f2 124 | http.begin(ifttt_url, _ifttt_fingerprint); 125 | #endif 126 | int httpCode = http.GET(); 127 | 128 | #ifdef IFTTT_WEBHOOK_DEBUG 129 | if (httpCode > 0) { 130 | Serial.printf("[HTTP] GET... code: %d\n", httpCode); 131 | 132 | if(httpCode == HTTP_CODE_OK) { 133 | Serial.println(http.getString()); 134 | } 135 | } else { 136 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 137 | } 138 | #endif 139 | 140 | http.end(); 141 | 142 | return httpCode != HTTP_CODE_OK; 143 | } 144 | --------------------------------------------------------------------------------