Skip to content
This repository was archived by the owner on Aug 23, 2024. It is now read-only.

Commit c9ce2ed

Browse files
authored
Add files via upload
0 parents  commit c9ce2ed

File tree

7 files changed

+220
-0
lines changed

7 files changed

+220
-0
lines changed

ESP32Webhook.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
MIT License
3+
Copyright (c) 2023 Rupak Poddar
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18+
SOFTWARE.
19+
*/
20+
21+
#include "ESP32Webhook.h"
22+
23+
Webhook::Webhook(String api_key, String event_name) {
24+
_api_key = api_key;
25+
_event_name = event_name;
26+
}
27+
28+
int Webhook::trigger() {
29+
return Webhook::trigger("", "", "");
30+
}
31+
32+
int Webhook::trigger(String value_1) {
33+
return Webhook::trigger(value_1, "", "");
34+
}
35+
36+
int Webhook::trigger(String value_1, String value_2) {
37+
return Webhook::trigger(value_1, value_2, "");
38+
}
39+
40+
int Webhook::trigger(String value_1, String value_2, String value_3) {
41+
HTTPClient http;
42+
43+
http.begin("http://maker.ifttt.com/trigger/" +
44+
_event_name + "/with/key/" + _api_key +
45+
"?value1=" + urlEncode(value_1) + "&value2=" + urlEncode(value_2) + "&value3=" + urlEncode(value_3));
46+
47+
int httpCode = http.GET();
48+
49+
http.end();
50+
51+
return httpCode;
52+
}
53+
54+
String Webhook::urlEncode(String value) {
55+
String encodedString = "";
56+
57+
for(int i=0; i<value.length(); i++){
58+
if (value[i] == ' '){
59+
encodedString += '+';
60+
}
61+
else if (isAlphaNumeric(value[i])){
62+
encodedString += value[i];
63+
}
64+
else{
65+
encodedString += '%';
66+
encodedString += String(value[i], HEX);
67+
}
68+
}
69+
70+
return encodedString;
71+
}

ESP32Webhook.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2023 Rupak Poddar
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
#ifndef ESP32Webhook_h
26+
#define ESP32Webhook_h
27+
#include "Arduino.h"
28+
#if defined(ESP32)
29+
#include <HTTPClient.h>
30+
#else
31+
#error "Please select an ESP32 board for this sketch."
32+
#endif
33+
34+
class Webhook
35+
{
36+
public:
37+
Webhook(String api_key, String event_name);
38+
int trigger(String value_1, String value_2, String value_3);
39+
int trigger(String value_1, String value_2);
40+
int trigger(String value_1);
41+
int trigger();
42+
43+
private:
44+
String _api_key;
45+
String _event_name;
46+
String urlEncode(String value);
47+
};
48+
#endif

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Rupak Poddar
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.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ESP32Webhook
2+
IFTTT makes it a breeze to activate events via Webhook using this library with just a single line of code. Seamlessly compatible with IFTTT, this library ensures flawless performance.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <ESP32Webhook.h>
2+
#include <WiFi.h>
3+
4+
#define _SSID "ENTER HERE" // Your WiFi SSID
5+
#define _PASSWORD "ENTER HERE" // Your WiFi Password
6+
#define KEY "ENTER HERE" // Webhooks Key
7+
#define EVENT "ENTER HERE" // Webhooks Event Name
8+
9+
Webhook webhook(KEY, EVENT); // Create an object.
10+
11+
void setup() {
12+
Serial.begin(115200);
13+
// pinMode(LED_BUILTIN, OUTPUT);
14+
// digitalWrite(LED_BUILTIN, LOW);
15+
WiFi.mode(WIFI_STA);
16+
WiFi.disconnect();
17+
delay(1000);
18+
19+
// Connect to WiFi
20+
Serial.println();
21+
Serial.println();
22+
Serial.print("Connecting to: ");
23+
Serial.println(_SSID);
24+
WiFi.begin(_SSID, _PASSWORD);
25+
26+
while (WiFi.status() != WL_CONNECTED) {
27+
delay(500);
28+
Serial.print("-");
29+
}
30+
31+
Serial.println("");
32+
Serial.println("WiFi Connected");
33+
34+
// Print the IP address
35+
Serial.print("IP Address: ");
36+
Serial.print("http://");
37+
Serial.print(WiFi.localIP());
38+
Serial.println("/");
39+
// digitalWrite(LED_BUILTIN, HIGH);
40+
41+
//================================================================//
42+
//================================================================//
43+
44+
// Trigger with 3 values.
45+
webhook.trigger("value1","value2","value3");
46+
delay(5000);
47+
48+
// Trigger with 2 values.
49+
webhook.trigger("ABC","XYZ");
50+
delay(5000);
51+
52+
// Trigger with 1 value.
53+
int Num = 1234;
54+
webhook.trigger(String(Num));
55+
delay(5000);
56+
57+
// Trigger without any value and get response.
58+
int response = webhook.trigger();
59+
if(response == 200)
60+
Serial.println("OK");
61+
else
62+
Serial.println("Failed");
63+
}
64+
65+
void loop() {
66+
// Nothing
67+
}

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Webhook KEYWORD1
2+
trigger KEYWORD2

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ESP32 Webhook
2+
version=1.0.0
3+
author=Rupak Poddar
4+
maintainer=Rupak Poddar <poddarrupak2808@gmail.com>
5+
sentence=Leverage IFTTT and the ESP32 library to set off events via Webhook.
6+
paragraph=IFTTT makes it a breeze to activate events via Webhook using this library with just a single line of code. Seamlessly compatible with IFTTT, this library ensures flawless performance.
7+
category=Communication
8+
url=https://github.com/Rupakpoddar/ESP32Webhook
9+
architectures=esp32

0 commit comments

Comments
 (0)