Skip to content

Instantly share code, notes, and snippets.

@andysheen-zz
Created June 15, 2015 16:20
Show Gist options
  • Save andysheen-zz/10b621058528e9f39a37 to your computer and use it in GitHub Desktop.
Save andysheen-zz/10b621058528e9f39a37 to your computer and use it in GitHub Desktop.
Tweeting thirsty plant
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
const String TWITTER_ACCESS_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const String TWITTER_ACCESS_TOKEN_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const String TWITTER_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxx";
const String TWITTER_API_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
int numRuns = 1; // execution count, so this sketch doesn't run forever
int maxRuns = 1; // the max number of times the Twitter Update Choreo should run
boolean tweeted = false; //creating a boolean allows us to send a tweet once and then not send again until the status has changed
void setup() {
Serial.begin(9600);
// for debugging, wait until a serial console is connected
delay(4000);
while (!Serial);
Bridge.begin();
}
void loop()
{
// only try to send the tweet if we haven't already sent it successfully
if (numRuns <= maxRuns)
{
if(analogRead(A0) >50 && tweeted==false)
{
tweeted = true;
Serial.println("Running SendATweet - Super Thirsty");
// define the text of the tweet we want to send
String tweetText("I could really do with a drink of water.");
TembooChoreo StatusesUpdateChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked, and repopulated with
// appropriate arguments, each time its run() method is called.
StatusesUpdateChoreo.begin();
// set Temboo account credentials
StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate)
StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/
// for complete details about the inputs for this Choreo
// add the Twitter account information
StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_API_KEY);
StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_API_SECRET);
// and the tweet we want to send
StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = StatusesUpdateChoreo.run();
// a return code of zero (0) means everything worked
if (returnCode == 0)
{
Serial.println("Success! Tweet sent!");
}
else
{
// a non-zero return code means there was an error
// read and print the error message
while (StatusesUpdateChoreo.available())
{
char c = StatusesUpdateChoreo.read();
Serial.print(c);
}
}
StatusesUpdateChoreo.close();
// do nothing for the next 90 seconds
Serial.println("Waiting...");
delay(4000);
}
if(analogRead(A0) <50 && tweeted==true)
{
tweeted = false;
Serial.println("Running SendATweet - TankedUp");
// define the text of the tweet we want to send
String tweetText("That is much better, thanks for the water.");
TembooChoreo StatusesUpdateChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked, and repopulated with
// appropriate arguments, each time its run() method is called.
StatusesUpdateChoreo.begin();
// set Temboo account credentials
StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate)
StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/
// for complete details about the inputs for this Choreo
// add the Twitter account information
StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_API_KEY);
StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_API_SECRET);
// and the tweet we want to send
StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = StatusesUpdateChoreo.run();
// a return code of zero (0) means everything worked
if (returnCode == 0)
{
Serial.println("Success! Tweet sent!");
}
else
{
// a non-zero return code means there was an error
// read and print the error message
while (StatusesUpdateChoreo.available())
{
char c = StatusesUpdateChoreo.read();
Serial.print(c);
}
}
StatusesUpdateChoreo.close();
// do nothing for the next 90 seconds
Serial.println("Waiting...");
delay(4000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment