Post Facebook Status from TI CC3200 Launchpad Using Temboo Choreo and Energia Sketch

Here is YouTube video below after I have copied the Temboo Choreo code to Energia and build without errors.

I have introduced at my other post how, by using Temboo Choreos I am able to integrate web services to programs running on my TI Launchpad.

I would like to venture further and test how conveniently, I will be able to integrate a web service like Facebook to a program running on my TI Launchpad using Temboo Choreos and Energia Sketch. I have no prior experience in web services and before don’t know that it is possible to communicate an electronic kit to a web service like Facebook.

What I know of from browsing in the internet are Twitter message activated devices such as this brewing machine, and vending machine below.

Lets start now, to show you how to Post Facebook Status from TI CC3200 Launchpad.

Requirements to send Facebook posts from CC3200 Launchpad:

  1. You need a Temboo account. If you don’t have one yet, you can register for free here.
  2. Get the latest version of Energia Sketch here.
  3. A Facebook account, which most likely you already have one.
  4. A TI CC3200 Launchpad.
  5. A WiFi internet connection.

Get Facebook App ID and App Secret:

  1. Log in to your Facebook Developers Account. If you don’t have an account, you can make one here. After you have logged in go to Apps.
  2. If you are using an existing App, select your App on the Facebook Dashboard. You will be able to see the existing app at a drop down menu when you select App. Copy your AppID and App Secret.
  3. If you don’t have an existing App, at Apps select “Add a New App” to create a new App. Select Website and at the Site URL field of the form, enter https://www.temboo.com/oauth_helpers/confirm_facebook/ 
  4. After finish creating new App, select your App and Copy your App ID and App Secret.

Auto-Generate your Launchpad Energia Sketch Code from Temboo:

  1. Log in to Temboo, and go to Facebook->Publishing->Post Choreo Library.
  2. Turn the IoT Mode switch to ON, and select Texas Instruments Launchpad from the drop down menu. Also, at “How is it Connected” drop down menu, select TI CC3200 Launchpad (Wifi) and provide the details of your WiFi internet connection.
  3. At Input fields “click” the Get OAuth Tokens icon. A window will open providing instructions how obtain OAuth Tokens. Steps 1 and 2 are discussed in more detail at Get Facebook App ID and App Secret steps above.
  4. At Step 3, enter your AppID and AppSecret at the fields and select “NEXT“.
  5. At step 4, select “LAUNCH AUTHORIZATION”. Then you will be automatically be at Step 5 with the Access Token. Select “USE THESE VALUES”. The window will close and the Access Token value will be automatically entered at the Input Access Token field.
  6. The two other fields are the “Link” and “Message”. Since I just want to post a Message at my Facebook account, I entered my message at field box.
  7. Click “Run” to test the Facebook->Publishing->Post Choreo. If there are errors after the test, means that you have a wrong value at the input fields. If pass, your C codes below are good to be copied into Energia Sketch. (YouTube video after step 7 is shown at the top of this post)

CC3200temboofacebookpost.c Energia Sketch Code:

#include <WiFi.h>
#include <WiFiClient.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information

WiFiClient client;

int numRuns = 1; // Execution count, so this doesn't run forever
int maxRuns = 10; // Maximum number of times the Choreo should be executed

void setup() {
 Serial.begin(9600);
 
 int wifiStatus = WL_IDLE_STATUS;

 // Determine if the WiFi Shield is present.
 Serial.print("\n\nShield:");
 if (WiFi.status() == WL_NO_SHIELD) {
 Serial.println("FAIL");

 // If there's no WiFi shield, stop here.
 while(true);
 }

 Serial.println("OK");

 // Try to connect to the local WiFi network.
 while(wifiStatus != WL_CONNECTED) {
 Serial.print("WiFi:");
 wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD);

 if (wifiStatus == WL_CONNECTED) {
 Serial.println("OK");
 } else {
 Serial.println("FAIL");
 }
 delay(5000);
 }

 Serial.println("Setup complete.\n");
}

void loop() {
 if (numRuns <= maxRuns) {
 Serial.println("Running Post - Run #" + String(numRuns++));

 TembooChoreo PostChoreo(client);

 // Invoke the Temboo client
 PostChoreo.begin();

 // Set Temboo account credentials
 PostChoreo.setAccountName(TEMBOO_ACCOUNT);
 PostChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
 PostChoreo.setAppKey(TEMBOO_APP_KEY);

 // Set Choreo inputs
 String AccessTokenValue = "xxxxxxxx";
 PostChoreo.addInput("AccessToken", AccessTokenValue);
 String MessageValue = "Hello from Temboo ! ! ! - Message was posted from CC3200 Launchpad";
 PostChoreo.addInput("Message", MessageValue);

 // Identify the Choreo to run
 PostChoreo.setChoreo("/Library/Facebook/Publishing/Post");

 // Run the Choreo; when results are available, print them to serial
 PostChoreo.run();

 while(PostChoreo.available()) {
 char c = PostChoreo.read();
 Serial.print(c);
 }
 PostChoreo.close();
 }

 Serial.println("\nWaiting...\n");
 delay(30000); // wait 30 seconds between Post calls
}

TembooAccount.h Energia Sketch code:

/*
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 Energia, call it TembooAccount.h,
and copy this content into it. 
*/

#define TEMBOO_ACCOUNT "xxxxxxxx" // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp" // Your Temboo app name
#define TEMBOO_APP_KEY "xxxxxxxx" // Your Temboo app key

#define WIFI_SSID "xxxxxxxx"
#define WPA_PASSWORD "xxxxxxxx"

/* 
The same TembooAccount.h file settings can be used for all Temboo 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.
*/

After just about less than 30 minutes, being able to post a message to Facebook using TI CC3200 Launchpad, I have a base product that I can already work on and expand to other possible applications.

There are lots of applications for having able to post a message, a link, a picture at Facebook using a TI CC3200 Launchpad. You can have it set as a home security alarm, a fire alarm, and a lot more.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s