Skip to content

Commit f827dce

Browse files
committed
2 parents 865e876 + 23f5834 commit f827dce

File tree

3 files changed

+74
-39
lines changed

3 files changed

+74
-39
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# esp8266 Dash Like IoT Button using IFTTT
22

3+
[![first-timers-only](https://img.shields.io/badge/first--timers--only-friendly-blue.svg?style=flat-square)](http://www.firsttimersonly.com/)
4+
35
![Enclosure Assembly](http://garthvh.com/assets/img/esp8266/sparkfun_thing.jpg "Thing Enclosure")
46
[Customized Project Enclosure - Thingiverse](http://www.thingiverse.com/thing:981124)
57

68
An IoT Button using an Adafruit Huzzah or Sparkfun Thing, a push button and the IFTTT Maker Channel (or any other http endpoint). Posts JSON data to an IFTTT Maker Channel event when the button is pressed.
79

810
I soldered male pins on my Huzzah, and added female headers to my Sparkfun Thing. The thing did not come with any headers and male headers were included with the Huzzah.
911

10-
I was able to program both with my [FTDI Friend](https://www.adafruit.com/product/284), you will need to cut the default RTS jumper on the back of the FTDI Friend (used by the Huzzah) and connect the DTR jumper to program the thing. If you have both boards once cut it has been pretty easy to switch back and forth by soldering the jumpers as needed.
12+
I was able to program both with my [FTDI Friend](https://www.adafruit.com/product/284), you will need to cut the default RTS jumper on the back of the FTDI Friend (used by the Huzzah) and connect the DTR jumper to program the thing. Once cut it has been pretty easy to switch back and forth by soldering the jumpers as needed.
1113

1214
I still need to write some sleep code to be more efficient on battery use.
1315

@@ -57,15 +59,22 @@ At the top of the esp8266_iot_button.ino file are the configuration options for
5759
// Device Definitions //
5860
////////////////////////
5961
String DEVICE_TITLE = "IFTTT ESP8266 Dash Like Button";
62+
const char* AP_SSID = "ESP8266_IOT_BUTTON_SETUP";
6063
boolean POWER_SAVE = false;
61-
boolean RGB_LCD = false;
6264

6365
///////////////////////
6466
// IFTTT Definitions //
6567
///////////////////////
6668
const char* IFTTT_URL= "maker.ifttt.com";
6769
const char* IFTTT_KEY= "YOUR IFTTT_KEY";
6870
const char* IFTTT_EVENT = "YOUR_IFTTT_EVENT";
71+
const char* IFTTT_NOTIFICATION_EVENT = "YOUR_IFTTT_NOTIFICATION_EVENT";
72+
73+
## IFTTT Events
74+
75+
You will need to setup the IFTTT Maker Channel and two IFTTT recipes, one for the button event, and one for the notification that the webserver is up with WiFi SSID and IP address.
76+
77+
![IFTTT Recipes](http://garthvh.com/assets/img/esp8266/ifttt_recipes_screenshot.png "IFTTT Recipes")
6978

7079
## Enclosure
7180
Using this awesome [Parametric and Customizable Project Enclosure](http://www.thingiverse.com/thing:155001) I made customized enclosures that fit the parts I was using for my buttons.

esp8266_iot_button.ino

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ boolean RGB_LCD = true;
4141
const char* IFTTT_URL= "maker.ifttt.com";
4242
const char* IFTTT_KEY= "YOUR IFTTT_KEY";
4343
const char* IFTTT_EVENT = "YOUR_IFTTT_EVENT";
44+
const char* IFTTT_NOTIFICATION_EVENT = "YOUR_IFTTT_NOTIFICATION_EVENT";
4445

4546
/////////////////////
4647
// Pin Definitions //
@@ -94,7 +95,17 @@ void loop() {
9495
Serial.println(" times");
9596
if(BUTTON_COUNTER > 1)
9697
{
97-
triggerButtonEvent();
98+
// Turn off the Green LED while transmitting.
99+
digitalWrite(LED_GREEN, LOW);
100+
if(RGB_LCD == true){
101+
digitalWrite(LED_BLUE, HIGH);
102+
}
103+
triggerButtonEvent(IFTTT_EVENT);
104+
// After a successful send turn the light back to green
105+
if(RGB_LCD == true){
106+
digitalWrite(LED_BLUE, LOW);
107+
}
108+
digitalWrite(LED_GREEN, HIGH);
98109
}
99110
}
100111
}
@@ -122,14 +133,8 @@ void initHardware()
122133
//////////////////////
123134
// Button Functions //
124135
//////////////////////
125-
void triggerButtonEvent()
136+
void triggerButtonEvent(String eventName)
126137
{
127-
// Turn off the Green LED while transmitting.
128-
digitalWrite(LED_GREEN, LOW);
129-
if(RGB_LCD == true){
130-
digitalWrite(LED_BLUE, HIGH);
131-
}
132-
133138
// Define the WiFi Client
134139
WiFiClient client;
135140
// Set the http Port
@@ -141,12 +146,24 @@ void triggerButtonEvent()
141146
}
142147

143148
// We now create a URI for the request
144-
String url = "/trigger/" + String(IFTTT_EVENT) + "/with/key/" + String(IFTTT_KEY);
149+
String url = "/trigger/" + String(eventName) + "/with/key/" + String(IFTTT_KEY);
150+
151+
// Set some values for the JSON data depending on which event has been triggered
152+
IPAddress ip = WiFi.localIP();
153+
String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
154+
String value_1 = "";
155+
String value_2 = "";
156+
String value_3 = "";
157+
if(eventName == IFTTT_EVENT){
158+
value_1 = String(BUTTON_COUNTER -1);
159+
value_2 = ipStr;
160+
value_3 = String(WiFi.gatewayIP());
161+
}
162+
else if(eventName == IFTTT_NOTIFICATION_EVENT){
163+
value_1 = ipStr;
164+
value_2 = WiFi.SSID();
165+
}
145166

146-
// Set some values for the JSON data
147-
String value_1 = String(BUTTON_COUNTER -1);
148-
String value_2 = String(WiFi.localIP());
149-
String value_3 = String(WiFi.gatewayIP());
150167

151168
// Build JSON data string
152169
String data = "";
@@ -181,11 +198,6 @@ void triggerButtonEvent()
181198
client.println(data);
182199
Serial.println(data);
183200
}
184-
// After a successful send turn the light back to green
185-
if(RGB_LCD == true){
186-
digitalWrite(LED_BLUE, LOW);
187-
}
188-
digitalWrite(LED_GREEN, HIGH);
189201
}
190202

191203
// Debounce Button Presses
@@ -318,6 +330,7 @@ void startWebServer() {
318330
});
319331
}
320332
WEB_SERVER.begin();
333+
triggerButtonEvent(IFTTT_NOTIFICATION_EVENT);
321334
}
322335

323336
// Build the SSID list and setup a software access point for setup mode

esp8266_iot_button_thing.ino

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ ESP8266WebServer WEB_SERVER(80);
3333
/////////////////////////
3434
String DEVICE_TITLE = "IFTTT ESP8266 Dash Like Button";
3535
boolean POWER_SAVE = false;
36-
boolean RGB_LCD =false;
36+
boolean RGB_LCD = false;
3737

3838
///////////////////////
3939
// IFTTT Definitions //
4040
///////////////////////
4141
const char* IFTTT_URL= "maker.ifttt.com";
4242
const char* IFTTT_KEY= "YOUR IFTTT_KEY";
4343
const char* IFTTT_EVENT = "YOUR_IFTTT_EVENT";
44+
const char* IFTTT_NOTIFICATION_EVENT = "YOUR_IFTTT_NOTIFICATION_EVENT";
4445

4546
/////////////////////
4647
// Pin Definitions //
@@ -94,7 +95,17 @@ void loop() {
9495
Serial.println(" times");
9596
if(BUTTON_COUNTER > 1)
9697
{
97-
triggerButtonEvent();
98+
// Turn off the Green LED while transmitting.
99+
digitalWrite(LED_GREEN, LOW);
100+
if(RGB_LCD == true){
101+
digitalWrite(LED_BLUE, HIGH);
102+
}
103+
triggerButtonEvent(IFTTT_EVENT);
104+
// After a successful send turn the light back to green
105+
if(RGB_LCD == true){
106+
digitalWrite(LED_BLUE, LOW);
107+
}
108+
digitalWrite(LED_GREEN, HIGH);
98109
}
99110
}
100111
}
@@ -122,14 +133,8 @@ void initHardware()
122133
//////////////////////
123134
// Button Functions //
124135
//////////////////////
125-
void triggerButtonEvent()
136+
void triggerButtonEvent(String eventName)
126137
{
127-
// Turn off the Green LED while transmitting.
128-
digitalWrite(LED_GREEN, LOW);
129-
if(RGB_LCD == true){
130-
digitalWrite(LED_BLUE, HIGH);
131-
}
132-
133138
// Define the WiFi Client
134139
WiFiClient client;
135140
// Set the http Port
@@ -141,12 +146,24 @@ void triggerButtonEvent()
141146
}
142147

143148
// We now create a URI for the request
144-
String url = "/trigger/" + String(IFTTT_EVENT) + "/with/key/" + String(IFTTT_KEY);
149+
String url = "/trigger/" + String(eventName) + "/with/key/" + String(IFTTT_KEY);
150+
151+
// Set some values for the JSON data depending on which event has been triggered
152+
IPAddress ip = WiFi.localIP();
153+
String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
154+
String value_1 = "";
155+
String value_2 = "";
156+
String value_3 = "";
157+
if(eventName == IFTTT_EVENT){
158+
value_1 = String(BUTTON_COUNTER -1);
159+
value_2 = ipStr;
160+
value_3 = String(WiFi.gatewayIP());
161+
}
162+
else if(eventName == IFTTT_NOTIFICATION_EVENT){
163+
value_1 = ipStr;
164+
value_2 = WiFi.SSID();
165+
}
145166

146-
// Set some values for the JSON data
147-
String value_1 = String(BUTTON_COUNTER -1);
148-
String value_2 = String(WiFi.localIP());
149-
String value_3 = String(WiFi.gatewayIP());
150167

151168
// Build JSON data string
152169
String data = "";
@@ -181,11 +198,6 @@ void triggerButtonEvent()
181198
client.println(data);
182199
Serial.println(data);
183200
}
184-
// After a successful send turn the light back to green
185-
if(RGB_LCD == true){
186-
digitalWrite(LED_BLUE, LOW);
187-
}
188-
digitalWrite(LED_GREEN, HIGH);
189201
}
190202

191203
// Debounce Button Presses
@@ -318,6 +330,7 @@ void startWebServer() {
318330
});
319331
}
320332
WEB_SERVER.begin();
333+
triggerButtonEvent(IFTTT_NOTIFICATION_EVENT);
321334
}
322335

323336
// Build the SSID list and setup a software access point for setup mode

0 commit comments

Comments
 (0)