Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connects you Phhotoresistor to IFTTT
Add conditional for notification to email/text Need to break out of REST API literal to add global char pointers for event name and api keys string concatenation. I will correct soon
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* Simple test of the functionality of the photo resistor | ||
|
||
Connect the photoresistor one leg to pin 0, and pin to +5V | ||
Connect a resistor (around 10k is a good value, higher | ||
values gives higher readings) from pin 0 to GND. (see appendix of arduino notebook page 37 for schematics). | ||
|
||
---------------------------------------------------- | ||
|
||
PhotoR 10K | ||
+5 o---/\/\/--.--/\/\/---o GND | ||
| | ||
Pin 0 o----------- | ||
|
||
---------------------------------------------------- | ||
*/ | ||
|
||
|
||
|
||
#include "ESP8266WiFi.h" | ||
//#include "DHT.h" | ||
//#define Photo_Pin A0 // what digital pin we're connected to pin2 to D4 on esp board | ||
|
||
int PhotoR_Pin = A0; | ||
|
||
#define WEBSITE "maker.ifttt.com" | ||
|
||
|
||
const char * MY_SSID = <your_SSID>"; | ||
const char * MY_PWD = "<YOur_PAssword>"; | ||
|
||
const char * EventName = "<Your event name>"; | ||
const char * apiKey = "<Your AapiKey from IFTTT>"; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.print("Connecting to "+*MY_SSID); | ||
WiFi.begin(MY_SSID, MY_PWD); | ||
|
||
while (WiFi.status() != WL_CONNECTED) //not connected, ...waiting to connect | ||
{ | ||
delay(1000); | ||
Serial.print("."); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("Credentials accepted! Connected to wifi\n "); | ||
Serial.println(""); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
// Wait a few seconds between measurements. | ||
delay(2000); | ||
Serial.println ((String) EventName ); | ||
float PhotoR = analogRead(PhotoR_Pin); | ||
Serial.println(analogRead(PhotoR_Pin)); //Write the value of the photoresistor | ||
//to the serial monitor. | ||
|
||
|
||
WiFiClient client; | ||
|
||
if (client.connect(WEBSITE, 80)) | ||
{ | ||
Serial.println("WiFi Client connected "); | ||
|
||
|
||
client.print(String("POST ") + | ||
"/trigger/<your_eventname_explicit>/with/key/<your_API_KEY_explicit>?value1=" | ||
+ (String) PhotoR | ||
// + "&value2=" + (String) t | ||
// + "&value3=" + (String) f | ||
// + "&Value4=" + (String) hic | ||
// + "&Value5=" + (String) hif | ||
|
||
+ " HTTP/1.1\r\n" + | ||
"Host: " + WEBSITE + "\r\n" + | ||
// "Connection: close\r\n\r\n"); | ||
"Content-Type: application/x-www-form-urlencoded\r\n\r\n"); | ||
|
||
|
||
while(client.available()) | ||
{ | ||
String line = client.readStringUntil('\r'); | ||
Serial.print(line); | ||
} | ||
|
||
|
||
|
||
delay(20000); | ||
} //end client connect | ||
|
||
else Serial.print("couldnt connect to IFTTT\n"); //if client connect failed | ||
|
||
client.stop(); | ||
} | ||
|
||
|
||
|