Here is the meat of this project.
http://www.instructables.com/id/Controlling-your-Christmas-lights-with-Text-Messag/?ALLSTEPS
Controlling your Christmas lights with Text Messages by VisionaryNutcases
The original code is for an Arduino YUN. The YUNs have built in ethernet and some code had to be changed to get it to work with my standard Uno with an ethernet shield.
Basically i had to strip out the Console.print and the Bridge.h commands, changing them to Serial.print . Also ,I had to shift the response string lookup digits a few places, because it was offset with the original YUN code. I just copied the RESPONSE from the serial monitor into Notepad, and counted the digits by using the right arrow key, taking note to count the spaces as well.
Here is the modified code that works on an Arduino Uno with an Ethernet shield. Dont forget to get your TembooAccount.h file from the temboo site.
Also, I had issues with the header code box not populating correctly while following the instructions. Try hitting refresh, switch between Arduino YUN and Arduino code using the box at the top of the temboo website.
You will need to edit the code below to include YOUR twilio auth code and ID. This code will turn a LED on digital pin7 if you send a text as “lights on” and turn the led off if you send “lights off”
/* Setup shield-specific #include statements */
/*Use the pic above, for the header setup, my WordPress software hides the code from this part in this post */
#include
#include
#include
#include
#include
#include
#include "TembooAccount.h" // Contains Temboo account information
#include
/*REPLACE THE FIRST 10 Lines with those shown in the pic above ^ */
byte ethernetMACAddress[] = ETHERNET_SHIELD_MAC;
EthernetClient client;
int numRuns = 1; // Execution count, so this doesn't run forever
int maxRuns = 5; // Maximum number of times the Choreo should be executed
int ledPin = 13; // Led for debug
int buzzerPin = 2; // buzzer's connected to pin 2
int lightsPin = 7; // The pin where your Xmas lights are connected to.
int timeToWait = 600000; //Delay between calls
String bodyMsgLast = "none"; // This variable holds the last text message read.
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected.
delay(4000);
while(!Serial);
Serial.print("DHCP:");
if (Ethernet.begin(ethernetMACAddress) == 0) {
Serial.println("FAIL");
while(true);
}
Serial.println("OK");
delay(5000);
Serial.println("Setup complete.\n");
//Set Outputs
pinMode(ledPin, OUTPUT);
pinMode(lightsPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
//Turn lights off on boot up
digitalWrite(lightsPin, HIGH);
delay(5000); //simulates a button press for 5 seconds
digitalWrite(lightsPin, LOW);
delay(1000);
//Bridge.begin();
//Console.begin();
}
void loop() {
if (numRuns <= maxRuns) {
Serial.println("Running GetLastMessageThatContains - Run #" + String(numRuns++));
TembooChoreo GetLastMessageThatContainsChoreo(client);
// Invoke the Temboo client
GetLastMessageThatContainsChoreo.begin();
// Set Temboo account credentials
GetLastMessageThatContainsChoreo.setAccountName(TEMBOO_ACCOUNT);
GetLastMessageThatContainsChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
GetLastMessageThatContainsChoreo.setAppKey(TEMBOO_APP_KEY);
// Set Choreo inputs
String AuthTokenValue = "6e0aecedb5461c4ccbc7f72535c7c569";
GetLastMessageThatContainsChoreo.addInput("AuthToken", AuthTokenValue);
String FilterValue = "lights";
GetLastMessageThatContainsChoreo.addInput("Filter", FilterValue);
String AccountSIDValue = "AC25eb0f996fbe268825f00405885f6fba";
GetLastMessageThatContainsChoreo.addInput("AccountSID", AccountSIDValue);
// Set Choreo inputs
GetLastMessageThatContainsChoreo.addInput("AuthToken", " PUT YOUR TWILIO AUTH TOKEN HERE "); //Twilio Authentication Token
GetLastMessageThatContainsChoreo.addInput("Filter", "ights"); // Filter for incoming messages holding this word
GetLastMessageThatContainsChoreo.addInput("AccountSID", " PUT YOUR TWILIO ACCOUNT ID HERE "); //Twilio account ID
GetLastMessageThatContainsChoreo.addInput("ResponseMode", "simple"); //Response Mode
// Identify the Choreo to run
GetLastMessageThatContainsChoreo.setChoreo("/Library/Twilio/SMSMessages/GetLastMessageThatContains");
// Run the Choreo; when results are available, print them to serial
GetLastMessageThatContainsChoreo.run();
String bodyMsg; // This contains the whole Message
while(GetLastMessageThatContainsChoreo.available()) {
char c = GetLastMessageThatContainsChoreo.read();
Serial.print(c);
bodyMsg += c; //The characters are being fed to the bodyMsg string
}
//Serial.println(bodyMsg+ "<-- is bodyMsg" );
if (bodyMsg != bodyMsgLast) { //Only runs if this message is different than the one stored.
if (bodyMsg.substring(33, 35) == "on") { //This only works if the 17th to 19 letters are "on"".
// This works if you're seinding the message "Lights on"
// Characters before Lights on are other info from Twilio
// Turn lights on
//digitalWrite(ledPin, HIGH); //turns on debug LED
digitalWrite(lightsPin, HIGH);
//delay(800);
//digitalWrite(lightsPin, LOW); //Simulated button press for less than a second
Serial.println("Lights are on");
//tone(buzzerPin, 2000, 3000); //beeps for 3 seconds
} else if (bodyMsg.substring (33, 36) == "off") { //17 20reads "off" from a message saying "Lights off"
//digitalWrite(ledPin, LOW); //turns off debug LED
//tone(buzzerPin, 4200, 1000); //beeps
digitalWrite(lightsPin, LOW);
//delay(5000); //simulates a 5 second button press to turn the lights off
//digitalWrite(lightsPin, LOW);
//delay(1000);
Serial.println("Lights are off");
}
bodyMsgLast = bodyMsg; //Copies this message to the Last message variable
} else {
Serial.println("Identical to Last"); //if identical, do nothing.
}
Serial.println();
Serial.println("Waiting...");
delay(timeToWait); // wait a period between GetLastMessageThatContains calls
GetLastMessageThatContainsChoreo.close();
}
Serial.println("\nWaiting...\n");
delay(30000); // wait 30 seconds between GetLastMessageThatContains calls
}
TembooAccount.h
you must edit your tembooaccount.h file as well. make sure you get an up to date app key FOR YOUR APP from the temboo website.
/*
IMPORTANT NOTE about TembooAccount.h
TembooAccount.h contains your Temboo account information and must be included
alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h,
and copy this content into it.
*/
#define TEMBOO_ACCOUNT "lagunabeachcomputer" // Your Temboo account name
#define TEMBOO_APP_KEY_NAME "myFirstApp" // Your Temboo app key name
#define TEMBOO_APP_KEY "2761f18fae384543af4f... xxxx " // Your Temboo app key
#define ETHERNET_SHIELD_MAC {0xFE, 0xAD, 0xBE, 0xEF, 0xFE, 0xFD}
/*
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the
main .ino file without worrying that you forgot to delete your credentials.
*/