Created
March 25, 2016 19:15
-
-
Save mobyjames/416f1486b9c4bc6ced5a to your computer and use it in GitHub Desktop.
Doorbell Messenger
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
#include <SPI.h> | |
#include <ESP8266WiFi.h> | |
#include <Temboo.h> | |
#define TEMBOO_ACCOUNT "YOUR_TEMBOO_ACCOUNT_NAME" | |
#define TEMBOO_APP_KEY_NAME "YOUR_TEMBOO_APP_KEY_NAME" | |
#define TEMBOO_APP_KEY "YOUR_TEMBOO_APP_KEY" | |
#define TEMBOO_CHOREO_NAME "YOUR_CHOREO_PROFILE_NAME" | |
#define WIFI_SSID "YOUR_WIFI_SSID" | |
#define WPA_PASSWORD "YOUR_WIFI_PASSWORD" | |
WiFiClient client; | |
int last = -1; | |
int inputPin = 2; | |
int flashPin = 0; | |
int outputPin = 4; | |
// prototypes | |
void sendSMS(); | |
void flash(int times); | |
void setup() { | |
// Init pins | |
pinMode(inputPin, INPUT); | |
pinMode(outputPin, OUTPUT); | |
pinMode(flashPin, OUTPUT); | |
// Init serial output | |
Serial.begin(9600); | |
delay(4000); | |
while(!Serial); | |
// Init Wifi | |
int wifiStatus = WL_IDLE_STATUS; | |
while(wifiStatus != WL_CONNECTED) { | |
Serial.print("WiFi:"); | |
wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD); | |
if (wifiStatus == WL_CONNECTED) { | |
Serial.println("OK"); | |
flash(3); | |
} else { | |
Serial.println("FAIL"); | |
flash(1); | |
} | |
delay(5000); | |
} | |
Serial.println("Setup complete.\n"); | |
} | |
void loop() { | |
int value = digitalRead(inputPin); | |
if (value != last) { | |
last = value; | |
if (value == LOW) { | |
Serial.println("Triggered!"); | |
digitalWrite(outputPin, HIGH); | |
delay(100); | |
digitalWrite(outputPin, LOW); | |
runSendSMS(); | |
} else { | |
Serial.println("Idle"); | |
digitalWrite(outputPin, LOW); | |
} | |
} | |
delay(100); | |
} | |
void runSendSMS() { | |
TembooChoreo SendSMSChoreo(client); | |
// Set Temboo account credentials | |
SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT); | |
SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); | |
SendSMSChoreo.setAppKey(TEMBOO_APP_KEY); | |
// Set profile to use for execution | |
SendSMSChoreo.setProfile(YOUR_CHOREO_PROFILE_NAME); | |
// Identify the Choreo to run | |
SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS"); | |
// Run the Choreo | |
unsigned int returnCode = SendSMSChoreo.run(); | |
// Read and print the error message | |
while (SendSMSChoreo.available()) { | |
char c = SendSMSChoreo.read(); | |
Serial.print(c); | |
} | |
Serial.println(); | |
SendSMSChoreo.close(); | |
} | |
void flash(int times) { | |
while(times-- > 0) { | |
digitalWrite(flashPin, HIGH); | |
delay(300); | |
digitalWrite(flashPin, LOW); | |
delay(300); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment