Posting to Twitter - JuliaElizabethLittle/peeMarksmanship GitHub Wiki

So here is where all the fun happens!!

Once we had all the code for the score set up, and the pot sensors (since our liquid sensors never actually worked) detected and calculated the value, and we had a high score system up and running, we thought it would be fun if every time there was a new high score this was updated in the twitter page. So we started looking at different ways this could be done, examples in other projects and so on, and we found the following ones:

Problem #1: Arduino uno doesn't have a wifi or internet connection. So... we started checking out ways to set up an internet connection without a shield. We found a few:

But as we were trying them, a miracle happened, and we managed to get hold of an Arduino Yún which does have an internet connection, so we ended up following these examples:

We first of all had to set up our new Arduino Board which is explained step by step in the Arduino Page Arduino Yún has a wifi receptor that has to be set up with your current internet and your computer.

The setup page hasn't been included since then anyone would be able to use it and post on our twitter account.

Once we had our Yún up and running (we checked by running the score code on it and seeing how that worked out) we created a twitter account for our product: PeeMarksmanship In which the high scores would be updated every time there was a new one. In order to do this we had to register as a Twitter developer.

Once Everything was in place, the arduino connected to the wifi and the twitter account all set up, we decided to test some code (extracted from the Teembo example):

/*
  SendATweet

  Demonstrates sending a tweet via a Twitter account using the Temboo Arduino Yun SDK.
  
  This example code is in the public domain.
*/

#include <Bridge.h>
#include <Temboo.h>
#define TEMBOO_ACCOUNT "peemarksmanship"  // your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // your Temboo app key name
#define TEMBOO_APP_KEY  "ml8JY4TLjJrV9R10AqyEUuFyIZ66NzVy"  // your Temboo app key

/*** 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 = "807742366039863297-x4WpWQvT2Dn2ua32WO9bz6jvyywiMhX";
const String TWITTER_ACCESS_TOKEN_SECRET = "ACBEvRfHsLiTrcpzqOJkYUtxfngwdLM9zLwdkcSDXIhzG";
const String TWITTER_API_KEY = "zwii7ZcCbcogVqJaswXxOiRVd";
const String TWITTER_API_SECRET = "HHtXDQRdxay9u5eu4tCJGaIvGaFJof9vYp3y5CgO78k9xT072E";

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

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) {

    Serial.println("Running SendATweet - Run #" + String(numRuns++) + "...");
  
    // define the text of the tweet we want to send
    String tweetText("is this working?");

    
    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(90000);
  }
}

And it worked without problem!

So we finally put it all together.

⚠️ **GitHub.com Fallback** ⚠️