mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Temboo: library and examples update
This commit is contained in:
@ -8,26 +8,26 @@
|
|||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid
|
Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid
|
||||||
Twilio account. You can create one for free at https://www.twilio.com.
|
Twilio account. You can create one for free at https://www.twilio.com.
|
||||||
|
|
||||||
The sketch needs your Twilio Account SID and Auth Token you get when you
|
The sketch needs your Twilio Account SID and Auth Token you get when you
|
||||||
register with Twilio. Make sure to use the Account SID and Auth Token from
|
register with Twilio. Make sure to use the Account SID and Auth Token from
|
||||||
your Twilio Dashboard (not your test credentials from the Dev Tools panel).
|
your Twilio Dashboard (not your test credentials from the Dev Tools panel).
|
||||||
|
|
||||||
Normally, Twilio expects to contact a web site you provide to get a response
|
Normally, Twilio expects to contact a web site you provide to get a response
|
||||||
when an SMS message is received for your Twilio number. In this case, we
|
when an SMS message is received for your Twilio number. In this case, we
|
||||||
don't want to send any response (and we don't want to have to set up a web
|
don't want to send any response (and we don't want to have to set up a web
|
||||||
site just to receive SMS messages.) You can use a URL that Twilio provides
|
site just to receive SMS messages.) You can use a URL that Twilio provides
|
||||||
for this purpose. When a message is received and sent to the Twilio "twimlets"
|
for this purpose. When a message is received and sent to the Twilio "twimlets"
|
||||||
URL, it returns a code meaning "no response required." To set this up:
|
URL, it returns a code meaning "no response required." To set this up:
|
||||||
|
|
||||||
1. Log in to your Twilio account and go to this URL:
|
1. Log in to your Twilio account and go to this URL:
|
||||||
|
|
||||||
https://www.twilio.com/user/account/phone-numbers/incoming
|
https://www.twilio.com/user/account/phone-numbers/incoming
|
||||||
|
|
||||||
2. Select the Twilio number you want to receive SMS messages at.
|
2. Select the Twilio number you want to receive SMS messages at.
|
||||||
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
https://www.twilio.com/help/faq/sms/how-can-i-receive-sms-messages-without-responding
|
https://www.twilio.com/help/faq/sms/how-can-i-receive-sms-messages-without-responding
|
||||||
|
|
||||||
4. Click the "Save Changes" button at the bottom of the page.
|
4. Click the "Save Changes" button at the bottom of the page.
|
||||||
|
|
||||||
Your account will now receive SMS messages, but won't send any responses.
|
Your account will now receive SMS messages, but won't send any responses.
|
||||||
|
|
||||||
@ -48,14 +48,14 @@
|
|||||||
to the Internet.
|
to the Internet.
|
||||||
|
|
||||||
Looking for another API? We've got over 100 in our Library!
|
Looking for another API? We've got over 100 in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ unsigned long lastSMSCheckTime = -SMS_CHECK_PERIOD;
|
|||||||
// (we only need to process newer messages)
|
// (we only need to process newer messages)
|
||||||
String lastSid;
|
String lastSid;
|
||||||
|
|
||||||
// we'll be turning the LED built in to the Yun on and off
|
// we'll be turning the LED built in to the Yun on and off
|
||||||
// to simulate controlling some device. That LED is on pin 13.
|
// to simulate controlling some device. That LED is on pin 13.
|
||||||
int LED_PIN = 13;
|
int LED_PIN = 13;
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ void setup() {
|
|||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
|
|
||||||
// tell the board to treat the LED pin as an output.
|
// tell the board to treat the LED pin as an output.
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
@ -109,7 +109,7 @@ void setup() {
|
|||||||
// initialize the connection to the Linino processor.
|
// initialize the connection to the Linino processor.
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
|
|
||||||
// Twilio will report old SMS messages. We want to
|
// Twilio will report old SMS messages. We want to
|
||||||
// ignore any existing control messages when we start.
|
// ignore any existing control messages when we start.
|
||||||
Serial.println("Ignoring any existing control messages...");
|
Serial.println("Ignoring any existing control messages...");
|
||||||
checkForMessages(true);
|
checkForMessages(true);
|
||||||
@ -124,15 +124,15 @@ void loop()
|
|||||||
|
|
||||||
// see if it's time to check for new SMS messages.
|
// see if it's time to check for new SMS messages.
|
||||||
if (now - lastSMSCheckTime >= SMS_CHECK_PERIOD) {
|
if (now - lastSMSCheckTime >= SMS_CHECK_PERIOD) {
|
||||||
|
|
||||||
// it's time to check for new messages
|
// it's time to check for new messages
|
||||||
// save this time so we know when to check next
|
// save this time so we know when to check next
|
||||||
lastSMSCheckTime = now;
|
lastSMSCheckTime = now;
|
||||||
|
|
||||||
if (numRuns <= maxRuns) {
|
if (numRuns <= maxRuns) {
|
||||||
Serial.println("Checking for new SMS messages - Run #" + String(numRuns++));
|
Serial.println("Checking for new SMS messages - Run #" + String(numRuns++));
|
||||||
|
|
||||||
// execute the choreo and don't ignore control messages.
|
// execute the choreo and don't ignore control messages.
|
||||||
checkForMessages(false);
|
checkForMessages(false);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Already ran " + String(maxRuns) + " times.");
|
Serial.println("Already ran " + String(maxRuns) + " times.");
|
||||||
@ -145,7 +145,7 @@ This function executes the Twilio > SMSMessages > ListMessages choreo
|
|||||||
and processes the results.
|
and processes the results.
|
||||||
|
|
||||||
If ignoreCommands is 'true', this function will read and process messages
|
If ignoreCommands is 'true', this function will read and process messages
|
||||||
updating 'lastSid', but will not actually take any action on any commands
|
updating 'lastSid', but will not actually take any action on any commands
|
||||||
found. This is so we can ignore any old control messages when we start.
|
found. This is so we can ignore any old control messages when we start.
|
||||||
|
|
||||||
If ignoreCommands is 'false', control messages WILL be acted on.
|
If ignoreCommands is 'false', control messages WILL be acted on.
|
||||||
@ -156,7 +156,7 @@ void checkForMessages(bool ignoreCommands) {
|
|||||||
TembooChoreo ListMessagesChoreo;
|
TembooChoreo ListMessagesChoreo;
|
||||||
|
|
||||||
ListMessagesChoreo.begin();
|
ListMessagesChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
ListMessagesChoreo.setAccountName(TEMBOO_ACCOUNT);
|
ListMessagesChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
ListMessagesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
ListMessagesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
@ -166,12 +166,12 @@ void checkForMessages(bool ignoreCommands) {
|
|||||||
ListMessagesChoreo.setChoreo("/Library/Twilio/SMSMessages/ListMessages");
|
ListMessagesChoreo.setChoreo("/Library/Twilio/SMSMessages/ListMessages");
|
||||||
|
|
||||||
// set the choreo inputs
|
// set the choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/
|
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
|
|
||||||
// the first input is a your Twilio AccountSID
|
// the first input is a your Twilio AccountSID
|
||||||
ListMessagesChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
|
ListMessagesChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
|
||||||
|
|
||||||
// next is your Twilio Auth Token
|
// next is your Twilio Auth Token
|
||||||
ListMessagesChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
|
ListMessagesChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
|
||||||
|
|
||||||
@ -179,24 +179,24 @@ void checkForMessages(bool ignoreCommands) {
|
|||||||
ListMessagesChoreo.addInput("From", FROM_PHONE_NUMBER);
|
ListMessagesChoreo.addInput("From", FROM_PHONE_NUMBER);
|
||||||
|
|
||||||
// Twilio can return information about up to 1000 messages at a time.
|
// Twilio can return information about up to 1000 messages at a time.
|
||||||
// we're only interested in the 3 most recent ones. Note that if
|
// we're only interested in the 3 most recent ones. Note that if
|
||||||
// this account receives lots of messages in quick succession,
|
// this account receives lots of messages in quick succession,
|
||||||
// (more than 3 per minute in this case), we might miss some control
|
// (more than 3 per minute in this case), we might miss some control
|
||||||
// messages. But if we request too many messages, we might run out of
|
// messages. But if we request too many messages, we might run out of
|
||||||
// memory on the Arduino side of the Yun.
|
// memory on the Arduino side of the Yun.
|
||||||
ListMessagesChoreo.addInput("PageSize", "3");
|
ListMessagesChoreo.addInput("PageSize", "3");
|
||||||
|
|
||||||
// We want the response in XML format to process with our
|
// We want the response in XML format to process with our
|
||||||
// XPath output filters.
|
// XPath output filters.
|
||||||
ListMessagesChoreo.addInput("ResponseFormat", "xml");
|
ListMessagesChoreo.addInput("ResponseFormat", "xml");
|
||||||
|
|
||||||
// we don't want everything from the output, just the
|
// we don't want everything from the output, just the
|
||||||
// message IDs (the Sids) and the message texts
|
// message IDs (the Sids) and the message texts
|
||||||
ListMessagesChoreo.addOutputFilter("sid", "Sid", "Response");
|
ListMessagesChoreo.addOutputFilter("sid", "Sid", "Response");
|
||||||
ListMessagesChoreo.addOutputFilter("text", "Body", "Response");
|
ListMessagesChoreo.addOutputFilter("text", "Body", "Response");
|
||||||
|
|
||||||
// tell the Choreo to run and wait for the results. The
|
// tell the Choreo to run and wait for the results. The
|
||||||
// return code (returnCode) will tell us whether the Temboo client
|
// return code (returnCode) will tell us whether the Temboo client
|
||||||
// was able to send our request to the Temboo servers
|
// was able to send our request to the Temboo servers
|
||||||
unsigned int returnCode = ListMessagesChoreo.run();
|
unsigned int returnCode = ListMessagesChoreo.run();
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ void checkForMessages(bool ignoreCommands) {
|
|||||||
if (returnCode == 0) {
|
if (returnCode == 0) {
|
||||||
|
|
||||||
// Need a string to hold the list of message IDs.
|
// Need a string to hold the list of message IDs.
|
||||||
String messageSids;
|
String messageSids;
|
||||||
|
|
||||||
// Need a string to hold the texts of the messages.
|
// Need a string to hold the texts of the messages.
|
||||||
String messageTexts;
|
String messageTexts;
|
||||||
@ -214,8 +214,8 @@ void checkForMessages(bool ignoreCommands) {
|
|||||||
// lists containing the Sids and texts of the messages
|
// lists containing the Sids and texts of the messages
|
||||||
// from our designated phone number.
|
// from our designated phone number.
|
||||||
|
|
||||||
while (ListMessagesChoreo.available()) {
|
while(ListMessagesChoreo.available()) {
|
||||||
|
|
||||||
// output names are terminated with '\x1F' characters.
|
// output names are terminated with '\x1F' characters.
|
||||||
String name = ListMessagesChoreo.readStringUntil('\x1F');
|
String name = ListMessagesChoreo.readStringUntil('\x1F');
|
||||||
name.trim();
|
name.trim();
|
||||||
@ -236,46 +236,46 @@ void checkForMessages(bool ignoreCommands) {
|
|||||||
|
|
||||||
// done reading output, close the Choreo to free up resources.
|
// done reading output, close the Choreo to free up resources.
|
||||||
ListMessagesChoreo.close();
|
ListMessagesChoreo.close();
|
||||||
|
|
||||||
// parse the comma delimited lists of messages and Sids
|
// parse the comma delimited lists of messages and Sids
|
||||||
processMessages(messageTexts, messageSids, ignoreCommands);
|
processMessages(messageTexts, messageSids, ignoreCommands);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// a non-zero return code means there was an error
|
// a non-zero return code means there was an error
|
||||||
// read and print the error message
|
// read and print the error message
|
||||||
while (ListMessagesChoreo.available()) {
|
while(ListMessagesChoreo.available()) {
|
||||||
char c = ListMessagesChoreo.read();
|
char c = ListMessagesChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function processes the lists of message texts and Sids.
|
This function processes the lists of message texts and Sids.
|
||||||
If a message contains a comma as part of the
|
If a message contains a comma as part of the
|
||||||
message text, that message will be enclosed in double quotes
|
message text, that message will be enclosed in double quotes
|
||||||
(") in the list. Example:
|
(") in the list. Example:
|
||||||
|
|
||||||
A message,"Hey, now",Another message text
|
A message,"Hey, now",Another message text
|
||||||
|
|
||||||
If the message contains double quotes, it will be enclosed in
|
If the message contains double quotes, it will be enclosed in
|
||||||
double quotes AND the internal quotes will be doubled.
|
double quotes AND the internal quotes will be doubled.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
"Hi ""Sam"" the man", Led on
|
"Hi ""Sam"" the man", Led on
|
||||||
|
|
||||||
NOTE! We are assuming that Twilio returns more recent messages
|
NOTE! We are assuming that Twilio returns more recent messages
|
||||||
first. This isn't officially documented by Twilio, but we've
|
first. This isn't officially documented by Twilio, but we've
|
||||||
not seen any other case.
|
not seen any other case.
|
||||||
|
|
||||||
'messageTexts' is a String containing a comma separated list of
|
'messageTexts' is a String containing a comma separated list of
|
||||||
message texts with commas and quotes escaped as described above.
|
message texts with commas and quotes escaped as described above.
|
||||||
|
|
||||||
'messageSids' is a String containing a comma separated list of
|
'messageSids' is a String containing a comma separated list of
|
||||||
message Sids. Sids should not contain embedded commas or quotes.
|
message Sids. Sids should not contain embedded commas or quotes.
|
||||||
|
|
||||||
'ignoreCommands' is a boolean. 'true' means and control messages
|
'ignoreCommands' is a boolean. 'true' means and control messages
|
||||||
will not be acted upon. 'false' means control messages will be
|
will not be acted upon. 'false' means control messages will be
|
||||||
acted upon in the usual way.
|
acted upon in the usual way.
|
||||||
*/
|
*/
|
||||||
void processMessages(String messageTexts, String messageSids, bool ignoreCommands) {
|
void processMessages(String messageTexts, String messageSids, bool ignoreCommands) {
|
||||||
@ -297,14 +297,14 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
|
|||||||
// find the start of the next item in the list
|
// find the start of the next item in the list
|
||||||
i = messageSids.indexOf(',', sidsStart);
|
i = messageSids.indexOf(',', sidsStart);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
|
|
||||||
//extract a single Sid from the list.
|
//extract a single Sid from the list.
|
||||||
sid = messageSids.substring(sidsStart, i);
|
sid = messageSids.substring(sidsStart, i);
|
||||||
sidsStart = i + 1;
|
sidsStart = i + 1;
|
||||||
|
|
||||||
// find the start of the next text in the list.
|
// find the start of the next text in the list.
|
||||||
// Note that we have to be prepared to handle embedded
|
// Note that we have to be prepared to handle embedded
|
||||||
// quotes and commans in the message texts.
|
// quotes and commans in the message texts.
|
||||||
// The standard Arduino String class doesn't handle
|
// The standard Arduino String class doesn't handle
|
||||||
// this, so we have to write our own function to do it.
|
// this, so we have to write our own function to do it.
|
||||||
i = quotedIndexOf(messageTexts, ',', textsStart);
|
i = quotedIndexOf(messageTexts, ',', textsStart);
|
||||||
@ -314,12 +314,12 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
|
|||||||
text = messageTexts.substring(textsStart, i);
|
text = messageTexts.substring(textsStart, i);
|
||||||
textsStart = i + 1;
|
textsStart = i + 1;
|
||||||
|
|
||||||
// process the Sid and text to see if it's a
|
// process the Sid and text to see if it's a
|
||||||
// control message.
|
// control message.
|
||||||
ledUpdated = processMessage(sid, text, ignoreCommands);
|
ledUpdated = processMessage(sid, text, ignoreCommands);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// the last item in the lists won't have a comma at the end,
|
// the last item in the lists won't have a comma at the end,
|
||||||
// so we have to handle them specially.
|
// so we have to handle them specially.
|
||||||
// Since we know this is the last item, we can just
|
// Since we know this is the last item, we can just
|
||||||
@ -333,9 +333,9 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
|
|||||||
|
|
||||||
// keep going until either we run out of list items
|
// keep going until either we run out of list items
|
||||||
// or we run into a message we processed on a previous run.
|
// or we run into a message we processed on a previous run.
|
||||||
} while ((i >= 0) && (sid != lastSid));
|
} while ((i >=0) && (sid != lastSid));
|
||||||
|
|
||||||
// print what we've found to the serial monitor,
|
// print what we've found to the serial monitor,
|
||||||
// just so we can see what's going on.
|
// just so we can see what's going on.
|
||||||
if (sid == lastSid) {
|
if (sid == lastSid) {
|
||||||
if (ledUpdated)
|
if (ledUpdated)
|
||||||
@ -359,17 +359,17 @@ A message with the text "LED ON" turns the LED on.
|
|||||||
A message with the text "LED OFF" turns the LED off.
|
A message with the text "LED OFF" turns the LED off.
|
||||||
(Case is ignored.)
|
(Case is ignored.)
|
||||||
|
|
||||||
If 'ignoreCommands' is true, the actions described above will NOT
|
If 'ignoreCommands' is true, the actions described above will NOT
|
||||||
take place.
|
take place.
|
||||||
|
|
||||||
It also updates the 'lastSid' global variable when
|
It also updates the 'lastSid' global variable when
|
||||||
a control message is processed.
|
a control message is processed.
|
||||||
|
|
||||||
It returns 'true' if the message was a control message, and
|
It returns 'true' if the message was a control message, and
|
||||||
'false' if it wasn't or if we've already processed this message.
|
'false' if it wasn't or if we've already processed this message.
|
||||||
*/
|
*/
|
||||||
bool processMessage(String sid, String text, bool ignoreCommands) {
|
bool processMessage(String sid, String text, bool ignoreCommands) {
|
||||||
|
|
||||||
// a flag to indicate whether this was a control message or not
|
// a flag to indicate whether this was a control message or not
|
||||||
bool ledUpdated = false;
|
bool ledUpdated = false;
|
||||||
|
|
||||||
@ -377,7 +377,7 @@ bool processMessage(String sid, String text, bool ignoreCommands) {
|
|||||||
if (sid != lastSid) {
|
if (sid != lastSid) {
|
||||||
|
|
||||||
if (text.equalsIgnoreCase("LED ON")) {
|
if (text.equalsIgnoreCase("LED ON")) {
|
||||||
|
|
||||||
if (!ignoreCommands) {
|
if (!ignoreCommands) {
|
||||||
//turn on the LED
|
//turn on the LED
|
||||||
digitalWrite(LED_PIN, HIGH);
|
digitalWrite(LED_PIN, HIGH);
|
||||||
@ -394,7 +394,7 @@ bool processMessage(String sid, String text, bool ignoreCommands) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the LED state was updated, remember the Sid if this message.
|
// If the LED state was updated, remember the Sid if this message.
|
||||||
if (ledUpdated)
|
if (ledUpdated)
|
||||||
lastSid = sid;
|
lastSid = sid;
|
||||||
}
|
}
|
||||||
return ledUpdated;
|
return ledUpdated;
|
||||||
@ -428,16 +428,16 @@ int quotedIndexOf(String s, char delim, int start) {
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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 save it once,
|
Keeping your account information in a separate file means you can save it once,
|
||||||
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
|
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
GetYahooWeatherReport
|
GetYahooWeatherReport
|
||||||
|
|
||||||
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yun.
|
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yun.
|
||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||||
to the Internet.
|
to the Internet.
|
||||||
|
|
||||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
|
|
||||||
// the address for which a weather forecast will be retrieved
|
// the address for which a weather forecast will be retrieved
|
||||||
@ -32,10 +32,10 @@ int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo shou
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -44,13 +44,13 @@ void loop()
|
|||||||
{
|
{
|
||||||
// while we haven't reached the max number of runs...
|
// while we haven't reached the max number of runs...
|
||||||
if (numRuns <= maxRuns) {
|
if (numRuns <= maxRuns) {
|
||||||
|
|
||||||
// print status
|
// print status
|
||||||
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
|
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
|
||||||
|
|
||||||
// create a TembooChoreo object to send a Choreo request to Temboo
|
// create a TembooChoreo object to send a Choreo request to Temboo
|
||||||
TembooChoreo GetWeatherByAddressChoreo;
|
TembooChoreo GetWeatherByAddressChoreo;
|
||||||
|
|
||||||
// invoke the Temboo client
|
// invoke the Temboo client
|
||||||
GetWeatherByAddressChoreo.begin();
|
GetWeatherByAddressChoreo.begin();
|
||||||
|
|
||||||
@ -58,30 +58,30 @@ void loop()
|
|||||||
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
|
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);
|
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||||
|
|
||||||
// set the name of the choreo we want to run
|
// set the name of the choreo we want to run
|
||||||
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
|
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
|
||||||
|
|
||||||
// set choreo inputs; in this case, the address for which to retrieve weather data
|
// set choreo inputs; in this case, the address for which to retrieve weather data
|
||||||
// the Temboo client provides standardized calls to 100+ cloud APIs
|
// the Temboo client provides standardized calls to 100+ cloud APIs
|
||||||
GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);
|
GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);
|
||||||
|
|
||||||
// add an output filter to extract the name of the city.
|
// add an output filter to extract the name of the city.
|
||||||
GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");
|
GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");
|
||||||
|
|
||||||
// add an output filter to extract the current temperature
|
// add an output filter to extract the current temperature
|
||||||
GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
|
GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
|
||||||
|
|
||||||
// add an output filter to extract the date and time of the last report.
|
// add an output filter to extract the date and time of the last report.
|
||||||
GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");
|
GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");
|
||||||
|
|
||||||
// run the choreo
|
// run the choreo
|
||||||
GetWeatherByAddressChoreo.run();
|
GetWeatherByAddressChoreo.run();
|
||||||
|
|
||||||
// when the choreo results are available, print them to the serial monitor
|
// when the choreo results are available, print them to the serial monitor
|
||||||
while (GetWeatherByAddressChoreo.available()) {
|
while(GetWeatherByAddressChoreo.available()) {
|
||||||
|
|
||||||
char c = GetWeatherByAddressChoreo.read();
|
char c = GetWeatherByAddressChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
GetWeatherByAddressChoreo.close();
|
GetWeatherByAddressChoreo.close();
|
||||||
@ -101,15 +101,15 @@ void loop()
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
ReadATweet
|
ReadATweet
|
||||||
|
|
||||||
Demonstrates retrieving the most recent Tweet from a user's home timeline
|
Demonstrates retrieving the most recent Tweet from a user's home timeline
|
||||||
using Temboo from an Arduino Yun.
|
using Temboo from an Arduino Yun.
|
||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
In order to run this sketch, you'll need to register an application using
|
In order to run this sketch, you'll need to register an application using
|
||||||
the Twitter dev console at https://dev.twitter.com. After creating the
|
the Twitter dev console at https://dev.twitter.com. After creating the
|
||||||
app, you'll find OAuth credentials for that application under the "OAuth Tool" tab.
|
app, you'll find OAuth credentials for that application under the "OAuth Tool" tab.
|
||||||
Substitute these values for the placeholders below.
|
Substitute these values for the placeholders below.
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
||||||
is connected to the Internet.
|
is connected to the Internet.
|
||||||
|
|
||||||
Want to use another social API with your Arduino Yun? We've got Facebook,
|
Want to use another social API with your Arduino Yun? We've got Facebook,
|
||||||
Google+, Instagram, Tumblr and more in our Library!
|
Google+, Instagram, Tumblr and more in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||||
|
|
||||||
@ -43,10 +43,10 @@ int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo s
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// For debugging, wait until a serial console is connected.
|
// For debugging, wait until a serial console is connected.
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
}
|
}
|
||||||
void loop()
|
void loop()
|
||||||
@ -54,14 +54,14 @@ void loop()
|
|||||||
// while we haven't reached the max number of runs...
|
// while we haven't reached the max number of runs...
|
||||||
if (numRuns <= maxRuns) {
|
if (numRuns <= maxRuns) {
|
||||||
Serial.println("Running ReadATweet - Run #" + String(numRuns++));
|
Serial.println("Running ReadATweet - Run #" + String(numRuns++));
|
||||||
|
|
||||||
TembooChoreo HomeTimelineChoreo;
|
TembooChoreo HomeTimelineChoreo;
|
||||||
|
|
||||||
// invoke the Temboo client.
|
// invoke the Temboo client.
|
||||||
// NOTE that the client must be reinvoked, and repopulated with
|
// NOTE that the client must be reinvoked, and repopulated with
|
||||||
// appropriate arguments, each time its run() method is called.
|
// appropriate arguments, each time its run() method is called.
|
||||||
HomeTimelineChoreo.begin();
|
HomeTimelineChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT);
|
HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
@ -69,8 +69,8 @@ void loop()
|
|||||||
|
|
||||||
// tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline)
|
// tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline)
|
||||||
HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline");
|
HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline");
|
||||||
|
|
||||||
|
|
||||||
// set the required choreo inputs
|
// set the required choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/
|
// see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
@ -78,44 +78,44 @@ void loop()
|
|||||||
HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request
|
HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request
|
||||||
HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
|
HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
|
||||||
HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
|
HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
|
||||||
HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
||||||
HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
|
HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
|
||||||
|
|
||||||
// next, we'll define two output filters that let us specify the
|
// next, we'll define two output filters that let us specify the
|
||||||
// elements of the response from Twitter that we want to receive.
|
// elements of the response from Twitter that we want to receive.
|
||||||
// see the examples at http://www.temboo.com/arduino
|
// see the examples at http://www.temboo.com/arduino
|
||||||
// for more on using output filters
|
// for more on using output filters
|
||||||
|
|
||||||
// we want the text of the tweet
|
// we want the text of the tweet
|
||||||
HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response");
|
HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response");
|
||||||
|
|
||||||
// and the name of the author
|
// and the name of the author
|
||||||
HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response");
|
HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response");
|
||||||
|
|
||||||
|
|
||||||
// tell the Process to run and wait for the results. The
|
// tell the Process to run and wait for the results. The
|
||||||
// return code will tell us whether the Temboo client
|
// return code will tell us whether the Temboo client
|
||||||
// was able to send our request to the Temboo servers
|
// was able to send our request to the Temboo servers
|
||||||
unsigned int returnCode = HomeTimelineChoreo.run();
|
unsigned int returnCode = HomeTimelineChoreo.run();
|
||||||
|
|
||||||
// a response code of 0 means success; print the API response
|
// a response code of 0 means success; print the API response
|
||||||
if (returnCode == 0) {
|
if(returnCode == 0) {
|
||||||
|
|
||||||
String author; // a String to hold the tweet author's name
|
String author; // a String to hold the tweet author's name
|
||||||
String tweet; // a String to hold the text of the tweet
|
String tweet; // a String to hold the text of the tweet
|
||||||
|
|
||||||
|
|
||||||
// choreo outputs are returned as key/value pairs, delimited with
|
// choreo outputs are returned as key/value pairs, delimited with
|
||||||
// newlines and record/field terminator characters, for example:
|
// newlines and record/field terminator characters, for example:
|
||||||
// Name1\n\x1F
|
// Name1\n\x1F
|
||||||
// Value1\n\x1E
|
// Value1\n\x1E
|
||||||
// Name2\n\x1F
|
// Name2\n\x1F
|
||||||
// Value2\n\x1E
|
// Value2\n\x1E
|
||||||
|
|
||||||
// see the examples at http://www.temboo.com/arduino for more details
|
// see the examples at http://www.temboo.com/arduino for more details
|
||||||
// we can read this format into separate variables, as follows:
|
// we can read this format into separate variables, as follows:
|
||||||
|
|
||||||
while (HomeTimelineChoreo.available()) {
|
while(HomeTimelineChoreo.available()) {
|
||||||
// read the name of the output item
|
// read the name of the output item
|
||||||
String name = HomeTimelineChoreo.readStringUntil('\x1F');
|
String name = HomeTimelineChoreo.readStringUntil('\x1F');
|
||||||
name.trim();
|
name.trim();
|
||||||
@ -131,13 +131,13 @@ void loop()
|
|||||||
author = data;
|
author = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("@" + author + " - " + tweet);
|
Serial.println("@" + author + " - " + tweet);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// there was an error
|
// there was an error
|
||||||
// print the raw output from the choreo
|
// print the raw output from the choreo
|
||||||
while (HomeTimelineChoreo.available()) {
|
while(HomeTimelineChoreo.available()) {
|
||||||
char c = HomeTimelineChoreo.read();
|
char c = HomeTimelineChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
@ -159,15 +159,15 @@ void loop()
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -5,30 +5,30 @@
|
|||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
In order to run this sketch, you'll need to register an application using
|
In order to run this sketch, you'll need to register an application using
|
||||||
the Twitter dev console at https://dev.twitter.com. Note that since this
|
the Twitter dev console at https://dev.twitter.com. Note that since this
|
||||||
sketch creates a new tweet, your application will need to be configured with
|
sketch creates a new tweet, your application will need to be configured with
|
||||||
read+write permissions. After creating the app, you'll find OAuth credentials
|
read+write permissions. After creating the app, you'll find OAuth credentials
|
||||||
for that application under the "OAuth Tool" tab. Substitute these values for
|
for that application under the "OAuth Tool" tab. Substitute these values for
|
||||||
the placeholders below.
|
the placeholders below.
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||||
to the Internet.
|
to the Internet.
|
||||||
|
|
||||||
Want to use another social API with your Arduino Yun? We've got Facebook,
|
Want to use another social API with your Arduino Yun? We've got Facebook,
|
||||||
Google+, Instagram, Tumblr and more in our Library!
|
Google+, Instagram, Tumblr and more in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
|
|
||||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||||
@ -48,7 +48,7 @@ void setup() {
|
|||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
|
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
}
|
}
|
||||||
@ -59,18 +59,18 @@ void loop()
|
|||||||
if (numRuns <= maxRuns) {
|
if (numRuns <= maxRuns) {
|
||||||
|
|
||||||
Serial.println("Running SendATweet - Run #" + String(numRuns++) + "...");
|
Serial.println("Running SendATweet - Run #" + String(numRuns++) + "...");
|
||||||
|
|
||||||
// define the text of the tweet we want to send
|
// define the text of the tweet we want to send
|
||||||
String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds.");
|
String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds.");
|
||||||
|
|
||||||
|
|
||||||
TembooChoreo StatusesUpdateChoreo;
|
TembooChoreo StatusesUpdateChoreo;
|
||||||
|
|
||||||
// invoke the Temboo client
|
// invoke the Temboo client
|
||||||
// NOTE that the client must be reinvoked, and repopulated with
|
// NOTE that the client must be reinvoked, and repopulated with
|
||||||
// appropriate arguments, each time its run() method is called.
|
// appropriate arguments, each time its run() method is called.
|
||||||
StatusesUpdateChoreo.begin();
|
StatusesUpdateChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
|
StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
@ -80,26 +80,26 @@ void loop()
|
|||||||
StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");
|
StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");
|
||||||
|
|
||||||
// set the required choreo inputs
|
// set the required choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/
|
// see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
|
|
||||||
// add the Twitter account information
|
// add the Twitter account information
|
||||||
StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
|
StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
|
||||||
StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
|
StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
|
||||||
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
||||||
StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
|
StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
|
||||||
|
|
||||||
// and the tweet we want to send
|
// and the tweet we want to send
|
||||||
StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);
|
StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);
|
||||||
|
|
||||||
// tell the Process to run and wait for the results. The
|
// tell the Process to run and wait for the results. The
|
||||||
// return code (returnCode) will tell us whether the Temboo client
|
// return code (returnCode) will tell us whether the Temboo client
|
||||||
// was able to send our request to the Temboo servers
|
// was able to send our request to the Temboo servers
|
||||||
unsigned int returnCode = StatusesUpdateChoreo.run();
|
unsigned int returnCode = StatusesUpdateChoreo.run();
|
||||||
|
|
||||||
// a return code of zero (0) means everything worked
|
// a return code of zero (0) means everything worked
|
||||||
if (returnCode == 0) {
|
if (returnCode == 0) {
|
||||||
Serial.println("Success! Tweet sent!");
|
Serial.println("Success! Tweet sent!");
|
||||||
} else {
|
} else {
|
||||||
// a non-zero return code means there was an error
|
// a non-zero return code means there was an error
|
||||||
// read and print the error message
|
// read and print the error message
|
||||||
@ -107,7 +107,7 @@ void loop()
|
|||||||
char c = StatusesUpdateChoreo.read();
|
char c = StatusesUpdateChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StatusesUpdateChoreo.close();
|
StatusesUpdateChoreo.close();
|
||||||
|
|
||||||
// do nothing for the next 90 seconds
|
// do nothing for the next 90 seconds
|
||||||
@ -124,15 +124,15 @@ void loop()
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -5,17 +5,17 @@
|
|||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
Since this sketch uses Gmail to send the email, you'll also need a valid
|
Since this sketch uses Gmail to send the email, you'll also need a valid
|
||||||
Google Gmail account. The sketch needs the username and password you use
|
Google Gmail account. The sketch needs the username and password you use
|
||||||
to log into your Gmail account - substitute the placeholders below for these values.
|
to log into your Gmail account - substitute the placeholders below for these values.
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||||
to the Internet.
|
to the Internet.
|
||||||
|
|
||||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
@ -24,7 +24,7 @@
|
|||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||||
|
|
||||||
@ -41,14 +41,14 @@ const String GMAIL_PASSWORD = "xxxxxxxxxx";
|
|||||||
const String TO_EMAIL_ADDRESS = "xxxxxxxxxx";
|
const String TO_EMAIL_ADDRESS = "xxxxxxxxxx";
|
||||||
|
|
||||||
// a flag to indicate whether we've tried to send the email yet or not
|
// a flag to indicate whether we've tried to send the email yet or not
|
||||||
boolean attempted = false;
|
boolean attempted = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
|
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
}
|
}
|
||||||
@ -59,14 +59,14 @@ void loop()
|
|||||||
if (!attempted) {
|
if (!attempted) {
|
||||||
|
|
||||||
Serial.println("Running SendAnEmail...");
|
Serial.println("Running SendAnEmail...");
|
||||||
|
|
||||||
TembooChoreo SendEmailChoreo;
|
TembooChoreo SendEmailChoreo;
|
||||||
|
|
||||||
// invoke the Temboo client
|
// invoke the Temboo client
|
||||||
// NOTE that the client must be reinvoked, and repopulated with
|
// NOTE that the client must be reinvoked, and repopulated with
|
||||||
// appropriate arguments, each time its run() method is called.
|
// appropriate arguments, each time its run() method is called.
|
||||||
SendEmailChoreo.begin();
|
SendEmailChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
|
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
@ -74,13 +74,13 @@ void loop()
|
|||||||
|
|
||||||
// identify the Temboo Library choreo to run (Google > Gmail > SendEmail)
|
// identify the Temboo Library choreo to run (Google > Gmail > SendEmail)
|
||||||
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
|
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
|
||||||
|
|
||||||
|
|
||||||
// set the required choreo inputs
|
// set the required choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
|
// see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
|
|
||||||
// the first input is your Gmail email address.
|
// the first input is your Gmail email address.
|
||||||
SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
|
SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
|
||||||
// next is your Gmail password.
|
// next is your Gmail password.
|
||||||
SendEmailChoreo.addInput("Password", GMAIL_PASSWORD);
|
SendEmailChoreo.addInput("Password", GMAIL_PASSWORD);
|
||||||
@ -89,17 +89,17 @@ void loop()
|
|||||||
// then a subject line
|
// then a subject line
|
||||||
SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
|
SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
|
||||||
|
|
||||||
// next comes the message body, the main content of the email
|
// next comes the message body, the main content of the email
|
||||||
SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
|
SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
|
||||||
|
|
||||||
// tell the Choreo to run and wait for the results. The
|
// tell the Choreo to run and wait for the results. The
|
||||||
// return code (returnCode) will tell us whether the Temboo client
|
// return code (returnCode) will tell us whether the Temboo client
|
||||||
// was able to send our request to the Temboo servers
|
// was able to send our request to the Temboo servers
|
||||||
unsigned int returnCode = SendEmailChoreo.run();
|
unsigned int returnCode = SendEmailChoreo.run();
|
||||||
|
|
||||||
// a return code of zero (0) means everything worked
|
// a return code of zero (0) means everything worked
|
||||||
if (returnCode == 0) {
|
if (returnCode == 0) {
|
||||||
Serial.println("Success! Email sent!");
|
Serial.println("Success! Email sent!");
|
||||||
} else {
|
} else {
|
||||||
// a non-zero return code means there was an error
|
// a non-zero return code means there was an error
|
||||||
// read and print the error message
|
// read and print the error message
|
||||||
@ -107,9 +107,9 @@ void loop()
|
|||||||
char c = SendEmailChoreo.read();
|
char c = SendEmailChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SendEmailChoreo.close();
|
SendEmailChoreo.close();
|
||||||
|
|
||||||
// set the flag showing we've tried
|
// set the flag showing we've tried
|
||||||
attempted = true;
|
attempted = true;
|
||||||
}
|
}
|
||||||
@ -123,15 +123,15 @@ void loop()
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -5,35 +5,35 @@
|
|||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
Since this sketch uses Twilio to send the SMS, you'll also need a valid
|
Since this sketch uses Twilio to send the SMS, you'll also need a valid
|
||||||
Twilio account. You can create one for free at https://www.twilio.com.
|
Twilio account. You can create one for free at https://www.twilio.com.
|
||||||
|
|
||||||
The sketch needs your Twilio phone number, along with
|
The sketch needs your Twilio phone number, along with
|
||||||
the Account SID and Auth Token you get when you register with Twilio.
|
the Account SID and Auth Token you get when you register with Twilio.
|
||||||
Make sure to use the Account SID and Auth Token from your Twilio Dashboard
|
Make sure to use the Account SID and Auth Token from your Twilio Dashboard
|
||||||
(not your test credentials from the Dev Tools panel).
|
(not your test credentials from the Dev Tools panel).
|
||||||
|
|
||||||
Also note that if you're using a free Twilio account, you'll need to verify
|
Also note that if you're using a free Twilio account, you'll need to verify
|
||||||
the phone number to which messages are being sent by going to twilio.com and following
|
the phone number to which messages are being sent by going to twilio.com and following
|
||||||
the instructions under the "Numbers > Verified Caller IDs" tab (this restriction
|
the instructions under the "Numbers > Verified Caller IDs" tab (this restriction
|
||||||
doesn't apply if you have a paid Twilio account).
|
doesn't apply if you have a paid Twilio account).
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||||
to the Internet.
|
to the Internet.
|
||||||
|
|
||||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -55,14 +55,14 @@ const String TWILIO_NUMBER = "xxxxxxxxxx";
|
|||||||
const String RECIPIENT_NUMBER = "xxxxxxxxxx";
|
const String RECIPIENT_NUMBER = "xxxxxxxxxx";
|
||||||
|
|
||||||
// a flag to indicate whether we've attempted to send the SMS yet or not
|
// a flag to indicate whether we've attempted to send the SMS yet or not
|
||||||
boolean attempted = false;
|
boolean attempted = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
|
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ void loop()
|
|||||||
if (!attempted) {
|
if (!attempted) {
|
||||||
|
|
||||||
Serial.println("Running SendAnSMS...");
|
Serial.println("Running SendAnSMS...");
|
||||||
|
|
||||||
// we need a Process object to send a Choreo request to Temboo
|
// we need a Process object to send a Choreo request to Temboo
|
||||||
TembooChoreo SendSMSChoreo;
|
TembooChoreo SendSMSChoreo;
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ void loop()
|
|||||||
// NOTE that the client must be reinvoked and repopulated with
|
// NOTE that the client must be reinvoked and repopulated with
|
||||||
// appropriate arguments each time its run() method is called.
|
// appropriate arguments each time its run() method is called.
|
||||||
SendSMSChoreo.begin();
|
SendSMSChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
|
SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
@ -91,32 +91,32 @@ void loop()
|
|||||||
SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");
|
SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");
|
||||||
|
|
||||||
// set the required choreo inputs
|
// set the required choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/
|
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
|
|
||||||
// the first input is a your AccountSID
|
// the first input is a your AccountSID
|
||||||
SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
|
SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
|
||||||
|
|
||||||
// next is your Auth Token
|
// next is your Auth Token
|
||||||
SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
|
SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
|
||||||
|
|
||||||
// next is your Twilio phone number
|
// next is your Twilio phone number
|
||||||
SendSMSChoreo.addInput("From", TWILIO_NUMBER);
|
SendSMSChoreo.addInput("From", TWILIO_NUMBER);
|
||||||
|
|
||||||
// next, what number to send the SMS to
|
// next, what number to send the SMS to
|
||||||
SendSMSChoreo.addInput("To", RECIPIENT_NUMBER);
|
SendSMSChoreo.addInput("To", RECIPIENT_NUMBER);
|
||||||
|
|
||||||
// finally, the text of the message to send
|
// finally, the text of the message to send
|
||||||
SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!");
|
SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!");
|
||||||
|
|
||||||
// tell the Process to run and wait for the results. The
|
// tell the Process to run and wait for the results. The
|
||||||
// return code (returnCode) will tell us whether the Temboo client
|
// return code (returnCode) will tell us whether the Temboo client
|
||||||
// was able to send our request to the Temboo servers
|
// was able to send our request to the Temboo servers
|
||||||
unsigned int returnCode = SendSMSChoreo.run();
|
unsigned int returnCode = SendSMSChoreo.run();
|
||||||
|
|
||||||
// a return code of zero (0) means everything worked
|
// a return code of zero (0) means everything worked
|
||||||
if (returnCode == 0) {
|
if (returnCode == 0) {
|
||||||
Serial.println("Success! SMS sent!");
|
Serial.println("Success! SMS sent!");
|
||||||
} else {
|
} else {
|
||||||
// a non-zero return code means there was an error
|
// a non-zero return code means there was an error
|
||||||
// read and print the error message
|
// read and print the error message
|
||||||
@ -124,11 +124,11 @@ void loop()
|
|||||||
char c = SendSMSChoreo.read();
|
char c = SendSMSChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SendSMSChoreo.close();
|
SendSMSChoreo.close();
|
||||||
|
|
||||||
// set the flag indicatine we've tried once.
|
// set the flag indicatine we've tried once.
|
||||||
attempted = true;
|
attempted=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,15 +140,15 @@ void loop()
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
Since this sketch uses a Google spreadsheet, you'll also need a
|
Since this sketch uses a Google spreadsheet, you'll also need a
|
||||||
Google account: substitute the placeholders below for your Google account values.
|
Google account: substitute the placeholders below for your Google account values.
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your
|
This example assumes basic familiarity with Arduino sketches, and that your
|
||||||
Yun is connected to the Internet.
|
Yun is connected to the Internet.
|
||||||
|
|
||||||
The columns in your spreadsheet must have labels for the Choreo to
|
The columns in your spreadsheet must have labels for the Choreo to
|
||||||
@ -21,14 +21,14 @@
|
|||||||
assumes there are two columns. The first column is the time (in milliseconds)
|
assumes there are two columns. The first column is the time (in milliseconds)
|
||||||
that the row was appended, and the second column is a sensor value.
|
that the row was appended, and the second column is a sensor value.
|
||||||
In other words, your spreadsheet should look like:
|
In other words, your spreadsheet should look like:
|
||||||
|
|
||||||
Time | Sensor Value |
|
Time | Sensor Value |
|
||||||
------+-----------------
|
------+-----------------
|
||||||
| |
|
| |
|
||||||
|
|
||||||
NOTE that the first time you run this sketch, you may receive a warning from
|
NOTE that the first time you run this sketch, you may receive a warning from
|
||||||
Google, prompting you to authorize access from a 3rd party system.
|
Google, prompting you to authorize access from a 3rd party system.
|
||||||
|
|
||||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
@ -38,7 +38,7 @@
|
|||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information,
|
#include "TembooAccount.h" // contains Temboo account information,
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
|
|
||||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||||
@ -57,17 +57,17 @@ const String SPREADSHEET_TITLE = "your-spreadsheet-title";
|
|||||||
|
|
||||||
const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds)
|
const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds)
|
||||||
|
|
||||||
// the last time we ran the Choreo
|
// the last time we ran the Choreo
|
||||||
// (initialized to 60 seconds ago so the
|
// (initialized to 60 seconds ago so the
|
||||||
// Choreo is run immediately when we start up)
|
// Choreo is run immediately when we start up)
|
||||||
unsigned long lastRun = (unsigned long) - 60000;
|
unsigned long lastRun = (unsigned long)-60000;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
|
|
||||||
Serial.print("Initializing the bridge...");
|
Serial.print("Initializing the bridge...");
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
@ -84,7 +84,7 @@ void loop()
|
|||||||
|
|
||||||
// remember 'now' as the last time we ran the choreo
|
// remember 'now' as the last time we ran the choreo
|
||||||
lastRun = now;
|
lastRun = now;
|
||||||
|
|
||||||
Serial.println("Getting sensor value...");
|
Serial.println("Getting sensor value...");
|
||||||
|
|
||||||
// get the value we want to append to our spreadsheet
|
// get the value we want to append to our spreadsheet
|
||||||
@ -99,19 +99,19 @@ void loop()
|
|||||||
// NOTE that the client must be reinvoked and repopulated with
|
// NOTE that the client must be reinvoked and repopulated with
|
||||||
// appropriate arguments each time its run() method is called.
|
// appropriate arguments each time its run() method is called.
|
||||||
AppendRowChoreo.begin();
|
AppendRowChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
|
AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
|
AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||||
|
|
||||||
// identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow)
|
// identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow)
|
||||||
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
|
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
|
||||||
|
|
||||||
// set the required Choreo inputs
|
// set the required Choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/
|
// see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
|
|
||||||
// your Google username (usually your email address)
|
// your Google username (usually your email address)
|
||||||
AppendRowChoreo.addInput("Username", GOOGLE_USERNAME);
|
AppendRowChoreo.addInput("Username", GOOGLE_USERNAME);
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ void loop()
|
|||||||
AppendRowChoreo.addInput("RowData", rowData);
|
AppendRowChoreo.addInput("RowData", rowData);
|
||||||
|
|
||||||
// run the Choreo and wait for the results
|
// run the Choreo and wait for the results
|
||||||
// The return code (returnCode) will indicate success or failure
|
// The return code (returnCode) will indicate success or failure
|
||||||
unsigned int returnCode = AppendRowChoreo.run();
|
unsigned int returnCode = AppendRowChoreo.run();
|
||||||
|
|
||||||
// return code of zero (0) means success
|
// return code of zero (0) means success
|
||||||
@ -139,7 +139,7 @@ void loop()
|
|||||||
Serial.println("Success! Appended " + rowData);
|
Serial.println("Success! Appended " + rowData);
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
} else {
|
} else {
|
||||||
// return code of anything other than zero means failure
|
// return code of anything other than zero means failure
|
||||||
// read and display any error messages
|
// read and display any error messages
|
||||||
while (AppendRowChoreo.available()) {
|
while (AppendRowChoreo.available()) {
|
||||||
char c = AppendRowChoreo.read();
|
char c = AppendRowChoreo.read();
|
||||||
@ -151,7 +151,7 @@ void loop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function simulates reading the value of a sensor
|
// this function simulates reading the value of a sensor
|
||||||
unsigned long getSensorValue() {
|
unsigned long getSensorValue() {
|
||||||
return analogRead(A0);
|
return analogRead(A0);
|
||||||
}
|
}
|
||||||
@ -164,15 +164,15 @@ unsigned long getSensorValue() {
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,328 @@
|
|||||||
|
/*
|
||||||
|
SendDataToMySQL
|
||||||
|
|
||||||
|
Demonstrates storing and reading values in a MySQL database using
|
||||||
|
the Temboo Arduino Yun SDK. This example will periodically
|
||||||
|
update a MySQL instance with dummy sensor values from the Yun, and
|
||||||
|
then read those values back from the database.
|
||||||
|
|
||||||
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
|
http://www.temboo.com
|
||||||
|
|
||||||
|
To use this example, you'll need a MySQL instance. These instructions
|
||||||
|
assume that you are using an Amazon RDS instance in the "US East"
|
||||||
|
region. For details on how to use a database hosted elsewhere, see
|
||||||
|
http://temboo.com/library/Library/MySQL
|
||||||
|
|
||||||
|
To configure an RDS MySQL instance for Temboo connectivity:
|
||||||
|
|
||||||
|
1. If you don't already have one, create an Amazon AWS account and
|
||||||
|
a new MySQL RDS instance. The instructions at
|
||||||
|
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.html
|
||||||
|
will guide you through this process. Be sure to select the "US East (N. Virginia)"
|
||||||
|
region in the dropdown menu in the upper right side of the RDS Management Console
|
||||||
|
before creating the new instance.
|
||||||
|
|
||||||
|
2. Configure your RDS instance by adding a security rule to allow access
|
||||||
|
by Temboo. If you're familiar with the RDS command line tools,
|
||||||
|
you can do so using the instructions at https://www.temboo.com/library/Library/MySQL/
|
||||||
|
If you're not familiar with the RDS command line tools, the following steps
|
||||||
|
will guide you through this process using a Temboo Choreo:
|
||||||
|
|
||||||
|
-Obtain your AWS Access Key ID and Secret Access Key from the "Security Credentials"
|
||||||
|
pane of the AWS management console. If you haven't yet created an Access Key, you
|
||||||
|
will be able to do so from this interface.
|
||||||
|
|
||||||
|
-Log in to your Temboo account at https://www.temboo.com/login
|
||||||
|
|
||||||
|
-Navigate to https://www.temboo.com/library/Library/Amazon/RDS/AuthorizeDBSecurityGroupIngress/
|
||||||
|
|
||||||
|
-Turn on Run Mode, and enter the following inputs:
|
||||||
|
|
||||||
|
AWSAccessKeyId: your AWS access key
|
||||||
|
AWSSecretKeyId: your AWS secret key
|
||||||
|
CIDRIP: (leave empty)
|
||||||
|
DBSecurityGroupName: your RDS DBSecurityGroup name
|
||||||
|
EC2SecurityGroupName: Temboo Access
|
||||||
|
EC2SecurityGroupOwnerId: 114370834540
|
||||||
|
|
||||||
|
-Click the "Try it Out" button. If all went well, you should see an XML document
|
||||||
|
in the "Output" section of the Choreo description page listing the access permissions
|
||||||
|
in your RDS security group. Temboo should now have access to your RDS database.
|
||||||
|
|
||||||
|
3. To run the SendDataToMySQL sketch, you'll need the following information
|
||||||
|
about your database. These values can be found on the RDS Management Console:
|
||||||
|
|
||||||
|
-The address of the DB server (eg, somename.abc3xy6ijklmn.us-east-1.rds.amazonaws.com)
|
||||||
|
-The database name
|
||||||
|
-A username for a user with read, write, and create access to the DB
|
||||||
|
-The password for that user
|
||||||
|
|
||||||
|
Substitute these values into the DATABASE_SERVER, DATABASE_NAME, DATABASE_USERNAME,
|
||||||
|
and DATABASE_PASSWORD constants in the sketch.
|
||||||
|
|
||||||
|
When you run the sketch, it will attempt to create a new table named "readings" in the
|
||||||
|
database if it doesn't already exist. The table contains two columns: an unsigned INT
|
||||||
|
column named "cpu_time" and an INT column named "sensor_value".
|
||||||
|
|
||||||
|
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||||
|
to the Internet.
|
||||||
|
|
||||||
|
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Bridge.h>
|
||||||
|
#include <Temboo.h>
|
||||||
|
#include "TembooAccount.h" // contains Temboo account information,
|
||||||
|
// as described in the footer comment below
|
||||||
|
|
||||||
|
|
||||||
|
/*** 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 DATABASE_SERVER = "server-address-of-your-MySQL-instance";
|
||||||
|
const String DATABASE_NAME = "your-MySQL-database-name";
|
||||||
|
const String DATABASE_USERNAME = "your-MySQL-user-name";
|
||||||
|
const String DATABASE_PASSWORD = "your-MySQL-user-password";
|
||||||
|
|
||||||
|
// the name of the table to write to and read from
|
||||||
|
const String DATABASE_TABLE_NAME = "readings";
|
||||||
|
|
||||||
|
|
||||||
|
// how often to run the Choreo (in milliseconds)
|
||||||
|
const unsigned long RUN_INTERVAL_MILLIS = 60000;
|
||||||
|
|
||||||
|
// the last time we ran the Choreos (initialized to 60 seconds ago,
|
||||||
|
// so the Choreos are run immediately when we start up)
|
||||||
|
unsigned long lastRun = (unsigned long)-60000;
|
||||||
|
|
||||||
|
// a flag to indicate if we were able to create the table
|
||||||
|
// (or that it already existed)
|
||||||
|
bool haveTable = false;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// for debugging, wait until a serial console is connected
|
||||||
|
Serial.begin(9600);
|
||||||
|
delay(4000);
|
||||||
|
while(!Serial);
|
||||||
|
|
||||||
|
Serial.print("Initializing the bridge...");
|
||||||
|
Bridge.begin();
|
||||||
|
Serial.println("OK");
|
||||||
|
|
||||||
|
// make sure the table we need exists or create it if it doesn't
|
||||||
|
// (see the comments in the createTable function for details)
|
||||||
|
unsigned int result = createTable();
|
||||||
|
|
||||||
|
// set the 'haveTable' flag to true on success,
|
||||||
|
// or false if there was a problem creating the table
|
||||||
|
haveTable = (result == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// get the number of milliseconds this sketch has been running
|
||||||
|
unsigned long now = millis();
|
||||||
|
|
||||||
|
// run again if it's been RUN_INTERVAL_MILLIS milliseconds since we last ran
|
||||||
|
if (now - lastRun >= RUN_INTERVAL_MILLIS) {
|
||||||
|
|
||||||
|
// remember 'now' as the last time we ran the choreo
|
||||||
|
lastRun = now;
|
||||||
|
|
||||||
|
// do the database write/read only if we have the table.
|
||||||
|
if (haveTable) {
|
||||||
|
|
||||||
|
// get the value we want to add to our table
|
||||||
|
int sensorValue = getSensorValue();
|
||||||
|
|
||||||
|
// add a record containing the cpu time and sensor value
|
||||||
|
appendRow(now, sensorValue);
|
||||||
|
|
||||||
|
// Read the values just written to verify that they really
|
||||||
|
// did get sent to the database. (Not necessary in a real
|
||||||
|
// sketch, but done here to demonstrate retrieving data.)
|
||||||
|
retrieveRow(now);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Serial.println("Table creation failed, not appending row.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* createTable is a function that executes a SQL statement to
|
||||||
|
* create a table with the correct columns needed for this sketch.
|
||||||
|
*/
|
||||||
|
unsigned int createTable() {
|
||||||
|
Serial.print("Creating table '" + DATABASE_TABLE_NAME + "' (if needed)...");
|
||||||
|
|
||||||
|
// We need a table with columns to contain the cpu time and the sensor value.
|
||||||
|
// cpu time is an 'unsigned long' which is 4 bytes on the Yun,
|
||||||
|
// so an INT UNSIGNED in MySQL will hold any possible value.
|
||||||
|
// Our sensor values are 'int' values on the Yun,
|
||||||
|
// so an INT in MySQL will hold all possible values.
|
||||||
|
|
||||||
|
// Create a String containing the SQL statement to create the table.
|
||||||
|
String sql = "CREATE TABLE IF NOT EXISTS " + DATABASE_TABLE_NAME + " (cpu_time INT UNSIGNED, sensor_value INT);";
|
||||||
|
|
||||||
|
// Send the SQL to Temboo so it can forward it to your database.
|
||||||
|
unsigned int result = executeSQLCommand(sql, false);
|
||||||
|
|
||||||
|
// If there was an error, the executeSQLCommand function will have
|
||||||
|
// printed it to the Serial console. Otherwise, print OK.
|
||||||
|
if (result == 0) {
|
||||||
|
Serial.println("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* appendRow is a function that executes a SQL statement to
|
||||||
|
* insert a new row of data into the database.
|
||||||
|
* cpuTime is the value to be inserted into the cpu_time column
|
||||||
|
* value is the value wot be inserted into the sensor_value column
|
||||||
|
*/
|
||||||
|
unsigned int appendRow(unsigned long cpuTime, int value) {
|
||||||
|
Serial.print("Inserting row " + String(cpuTime) + ", " + String(value) + "...");
|
||||||
|
|
||||||
|
// Create a String containing the SQL statement to insert a row.
|
||||||
|
String sql = "INSERT " + DATABASE_TABLE_NAME + " VALUES (" + cpuTime + "," + value + ");";
|
||||||
|
|
||||||
|
// Send the SQL to Temboo so it can forward it to your database.
|
||||||
|
unsigned int result = executeSQLCommand(sql, false);
|
||||||
|
|
||||||
|
// If there was an error, the executeSQLCommand function will have
|
||||||
|
// printed it to the Serial console. Otherwise, print OK.
|
||||||
|
if (result == 0) {
|
||||||
|
Serial.println("OK");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* retrieveRow is a function that executes a SQL statement to
|
||||||
|
* retrieve a row of data from the database.
|
||||||
|
* cpuTime is the cpu_time value of the row to be retrieved.
|
||||||
|
* (note that it must exactly match the value stored.)
|
||||||
|
*/
|
||||||
|
unsigned int retrieveRow(unsigned long cpuTime) {
|
||||||
|
Serial.println("Retrieving row with time " + String(cpuTime) + "...");
|
||||||
|
|
||||||
|
// Create a String containing the SQL statement to retrieve a row.
|
||||||
|
String sql = "SELECT * FROM " + DATABASE_TABLE_NAME + " WHERE cpu_time = '" + cpuTime + "';";
|
||||||
|
|
||||||
|
// Send the SQL to Temboo so it can forward it to your database.
|
||||||
|
// In this case, we want to print the raw output we get from
|
||||||
|
// Temboo. This is just to demonstrate that the data really did
|
||||||
|
// get written to the database.
|
||||||
|
unsigned int result = executeSQLCommand(sql, true);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* executeSQLCommand is a function for sending SQL statements to
|
||||||
|
* Temboo for execution on your database.
|
||||||
|
* sql is a String containing the SQL statement to be executed.
|
||||||
|
* showOutput is a boolean flag which if set to 'true' will cause
|
||||||
|
* the raw Choreo results to be printed to the Serial console.
|
||||||
|
*/
|
||||||
|
unsigned int executeSQLCommand(String sql, bool showOutput) {
|
||||||
|
|
||||||
|
// Create a TembooChoreo object
|
||||||
|
TembooChoreo choreo;
|
||||||
|
|
||||||
|
// Initialize the Choreo object.
|
||||||
|
choreo.begin();
|
||||||
|
|
||||||
|
// set Temboo account credentials
|
||||||
|
choreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
|
choreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
|
choreo.setAppKey(TEMBOO_APP_KEY);
|
||||||
|
|
||||||
|
// specify the Choreo to be run
|
||||||
|
choreo.setChoreo("/Library/MySQL/RunCommand");
|
||||||
|
|
||||||
|
// add inputs specifying the RDS endpoint address
|
||||||
|
// and the database name within that RDS instance
|
||||||
|
choreo.addInput("Server", DATABASE_SERVER);
|
||||||
|
choreo.addInput("DatabaseName", DATABASE_NAME);
|
||||||
|
|
||||||
|
// add inputs for the MySQL user credentials
|
||||||
|
choreo.addInput("Username", DATABASE_USERNAME);
|
||||||
|
choreo.addInput("Password", DATABASE_PASSWORD);
|
||||||
|
|
||||||
|
// add the SQL command to be executed
|
||||||
|
choreo.addInput("SQL", sql);
|
||||||
|
|
||||||
|
// run the Choreo and wait for the results
|
||||||
|
// The return code (returnCode) will indicate success or failure
|
||||||
|
unsigned int returnCode = choreo.run();
|
||||||
|
|
||||||
|
// return code of zero (0) means success
|
||||||
|
if (returnCode == 0) {
|
||||||
|
|
||||||
|
// print the raw output if requested.
|
||||||
|
if (showOutput) {
|
||||||
|
while (choreo.available()) {
|
||||||
|
char c = choreo.read();
|
||||||
|
Serial.print(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// return code of anything other than zero means failure
|
||||||
|
// read and display any error messages
|
||||||
|
while (choreo.available()) {
|
||||||
|
char c = choreo.read();
|
||||||
|
Serial.print(c);
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
}
|
||||||
|
|
||||||
|
choreo.close();
|
||||||
|
|
||||||
|
return returnCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getSensorValue is a function to simulates reading the value of a sensor
|
||||||
|
*/
|
||||||
|
int getSensorValue() {
|
||||||
|
Serial.print("Reading sensor value...");
|
||||||
|
int value = analogRead(A0);
|
||||||
|
Serial.println("OK");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
IMPORTANT NOTE: TembooAccount.h:
|
||||||
|
|
||||||
|
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
|
||||||
|
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
|
||||||
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
|
look like:
|
||||||
|
|
||||||
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
|
under My Account > Application Keys
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,4 @@
|
|||||||
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
ToxicFacilitiesSearch
|
ToxicFacilitiesSearch
|
||||||
|
|
||||||
Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yun.
|
Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yun.
|
||||||
This example retrieves the names and addresses of EPA-regulated facilities in the
|
This example retrieves the names and addresses of EPA-regulated facilities in the
|
||||||
Toxins Release Inventory (TRI) database within a given zip code.
|
Toxins Release Inventory (TRI) database within a given zip code.
|
||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||||
to the Internet.
|
to the Internet.
|
||||||
|
|
||||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
// the zip code to search for toxin-emitting facilities
|
// the zip code to search for toxin-emitting facilities
|
||||||
String US_ZIP_CODE = "11215";
|
String US_ZIP_CODE = "11215";
|
||||||
@ -32,10 +32,10 @@ int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Chore
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ void loop()
|
|||||||
{
|
{
|
||||||
// while we haven't reached the max number of runs...
|
// while we haven't reached the max number of runs...
|
||||||
if (numRuns <= maxRuns) {
|
if (numRuns <= maxRuns) {
|
||||||
|
|
||||||
// print status
|
// print status
|
||||||
Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "...");
|
Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "...");
|
||||||
|
|
||||||
@ -54,26 +54,26 @@ void loop()
|
|||||||
// NOTE that the client must be reinvoked and repopulated with
|
// NOTE that the client must be reinvoked and repopulated with
|
||||||
// appropriate arguments each time its run() method is called.
|
// appropriate arguments each time its run() method is called.
|
||||||
FacilitiesSearchByZipChoreo.begin();
|
FacilitiesSearchByZipChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT);
|
FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY);
|
FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||||
|
|
||||||
// identify the Temboo Library choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip)
|
// identify the Temboo Library choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip)
|
||||||
FacilitiesSearchByZipChoreo.setChoreo("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip");
|
FacilitiesSearchByZipChoreo.setChoreo("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip");
|
||||||
|
|
||||||
// set choreo inputs; in this case, the US zip code for which to retrieve toxin release data
|
// set choreo inputs; in this case, the US zip code for which to retrieve toxin release data
|
||||||
// the Temboo client provides standardized calls to 100+ cloud APIs
|
// the Temboo client provides standardized calls to 100+ cloud APIs
|
||||||
FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE);
|
FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE);
|
||||||
|
|
||||||
// specify two output filters, to help simplify the Envirofacts API results.
|
// specify two output filters, to help simplify the Envirofacts API results.
|
||||||
// see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino
|
// see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino
|
||||||
FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response");
|
FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response");
|
||||||
|
|
||||||
FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response");
|
FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response");
|
||||||
|
|
||||||
// run the choreo
|
// run the choreo
|
||||||
unsigned int returnCode = FacilitiesSearchByZipChoreo.run();
|
unsigned int returnCode = FacilitiesSearchByZipChoreo.run();
|
||||||
if (returnCode == 0) {
|
if (returnCode == 0) {
|
||||||
String facilities;
|
String facilities;
|
||||||
@ -83,7 +83,7 @@ void loop()
|
|||||||
// the output filters we specified will return comma delimited
|
// the output filters we specified will return comma delimited
|
||||||
// lists containing the name and street address of the facilities
|
// lists containing the name and street address of the facilities
|
||||||
// located in the specified zip code.
|
// located in the specified zip code.
|
||||||
while (FacilitiesSearchByZipChoreo.available()) {
|
while(FacilitiesSearchByZipChoreo.available()) {
|
||||||
String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F');
|
String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F');
|
||||||
name.trim();
|
name.trim();
|
||||||
|
|
||||||
@ -97,8 +97,8 @@ void loop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FacilitiesSearchByZipChoreo.close();
|
FacilitiesSearchByZipChoreo.close();
|
||||||
|
|
||||||
// parse the comma delimited lists of facilities to join the
|
// parse the comma delimited lists of facilities to join the
|
||||||
// name with the address and print it to the serial monitor
|
// name with the address and print it to the serial monitor
|
||||||
if (facilities.length() > 0) {
|
if (facilities.length() > 0) {
|
||||||
int i = -1;
|
int i = -1;
|
||||||
@ -118,12 +118,12 @@ void loop()
|
|||||||
address = addresses.substring(addressStart, i);
|
address = addresses.substring(addressStart, i);
|
||||||
addressStart = i + 1;
|
addressStart = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
printResult(facility, address);
|
printResult(facility, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (i >= 0);
|
}while (i >= 0);
|
||||||
facility = facilities.substring(facilityStart);
|
facility = facilities.substring(facilityStart);
|
||||||
address = addresses.substring(addressStart);
|
address = addresses.substring(addressStart);
|
||||||
printResult(facility, address);
|
printResult(facility, address);
|
||||||
@ -131,7 +131,7 @@ void loop()
|
|||||||
Serial.println("No facilities found in zip code " + US_ZIP_CODE);
|
Serial.println("No facilities found in zip code " + US_ZIP_CODE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (FacilitiesSearchByZipChoreo.available()) {
|
while(FacilitiesSearchByZipChoreo.available()) {
|
||||||
char c = FacilitiesSearchByZipChoreo.read();
|
char c = FacilitiesSearchByZipChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
@ -157,15 +157,15 @@ void printResult(String facility, String address) {
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
Demonstrates sending a Facebook status update using Temboo from an Arduino Yun.
|
Demonstrates sending a Facebook status update using Temboo from an Arduino Yun.
|
||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
In order to run this sketch, you'll need to register an application using
|
In order to run this sketch, you'll need to register an application using
|
||||||
@ -15,19 +15,19 @@
|
|||||||
to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token.
|
to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token.
|
||||||
Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below.
|
Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below.
|
||||||
|
|
||||||
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
||||||
is connected to the Internet.
|
is connected to the Internet.
|
||||||
|
|
||||||
Want to use another social API with your Arduino Yun? We've got Twitter, Google+,
|
Want to use another social API with your Arduino Yun? We've got Twitter, Google+,
|
||||||
Instagram, Tumblr and more in our Library!
|
Instagram, Tumblr and more in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information,
|
#include "TembooAccount.h" // contains Temboo account information,
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||||
|
|
||||||
@ -43,10 +43,10 @@ int maxRuns = 10; // the max number of times the Facebook SetStatus Choreo shou
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// For debugging, wait until a serial console is connected.
|
// For debugging, wait until a serial console is connected.
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,19 +56,19 @@ void loop() {
|
|||||||
|
|
||||||
// print status
|
// print status
|
||||||
Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "...");
|
Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "...");
|
||||||
|
|
||||||
// Define the status message we want to post on Facebook; since Facebook
|
// Define the status message we want to post on Facebook; since Facebook
|
||||||
// doesn't allow duplicate status messages, we'll include a changing value.
|
// doesn't allow duplicate status messages, we'll include a changing value.
|
||||||
String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!";
|
String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!";
|
||||||
|
|
||||||
// define the Process that will be used to call the "temboo" client
|
// define the Process that will be used to call the "temboo" client
|
||||||
TembooChoreo SetStatusChoreo;
|
TembooChoreo SetStatusChoreo;
|
||||||
|
|
||||||
// invoke the Temboo client
|
// invoke the Temboo client
|
||||||
// NOTE that the client must be reinvoked and repopulated with
|
// NOTE that the client must be reinvoked and repopulated with
|
||||||
// appropriate arguments each time its run() method is called.
|
// appropriate arguments each time its run() method is called.
|
||||||
SetStatusChoreo.begin();
|
SetStatusChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT);
|
SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
@ -80,23 +80,23 @@ void loop() {
|
|||||||
// set the required choreo inputs
|
// set the required choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
|
// see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
|
|
||||||
SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);
|
SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);
|
||||||
SetStatusChoreo.addInput("Message", statusMsg);
|
SetStatusChoreo.addInput("Message", statusMsg);
|
||||||
|
|
||||||
|
|
||||||
// tell the Process to run and wait for the results. The
|
// tell the Process to run and wait for the results. The
|
||||||
// return code (returnCode) will tell us whether the Temboo client
|
// return code (returnCode) will tell us whether the Temboo client
|
||||||
// was able to send our request to the Temboo servers
|
// was able to send our request to the Temboo servers
|
||||||
unsigned int returnCode = SetStatusChoreo.run();
|
unsigned int returnCode = SetStatusChoreo.run();
|
||||||
|
|
||||||
// print the response code and API response.
|
// print the response code and API response.
|
||||||
Serial.println("Response code: " + String(returnCode));
|
Serial.println("Response code: " + String(returnCode));
|
||||||
|
|
||||||
// note that in this case, we're just printing the raw response from Facebook.
|
// note that in this case, we're just printing the raw response from Facebook.
|
||||||
// see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
|
// see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
|
||||||
// for information on how to filter this data
|
// for information on how to filter this data
|
||||||
while (SetStatusChoreo.available()) {
|
while(SetStatusChoreo.available()) {
|
||||||
char c = SetStatusChoreo.read();
|
char c = SetStatusChoreo.read();
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ void loop() {
|
|||||||
Serial.println("Waiting...");
|
Serial.println("Waiting...");
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
|
||||||
delay(30000); // wait 30 seconds between SetStatus calls
|
delay(30000); // wait 30 seconds between SetStatus calls
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -118,15 +118,15 @@ void loop() {
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
UploadToDropbox
|
UploadToDropbox
|
||||||
|
|
||||||
Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yun.
|
Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yun.
|
||||||
|
|
||||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
A Temboo account and application key are necessary to run all Temboo examples.
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
If you don't already have one, you can register for a free Temboo account at
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
http://www.temboo.com
|
http://www.temboo.com
|
||||||
|
|
||||||
You'll also need a valid Dropbox app and accompanying OAuth credentials.
|
You'll also need a valid Dropbox app and accompanying OAuth credentials.
|
||||||
To create a Dropbox app, visit https://www.dropbox.com/developers/apps and
|
To create a Dropbox app, visit https://www.dropbox.com/developers/apps and
|
||||||
do the following:
|
do the following:
|
||||||
|
|
||||||
1. Create a "Dropbox API app"
|
1. Create a "Dropbox API app"
|
||||||
2. Select "Files and datastores"
|
2. Select "Files and datastores"
|
||||||
3. Select "Yes - my app only needs access to the files it creates."
|
3. Select "Yes - my app only needs access to the files it creates."
|
||||||
|
|
||||||
Once you've created your app, follow the instructions at
|
Once you've created your app, follow the instructions at
|
||||||
https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize
|
https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize
|
||||||
OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens.
|
OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens.
|
||||||
|
|
||||||
@ -25,14 +25,14 @@
|
|||||||
to the Internet.
|
to the Internet.
|
||||||
|
|
||||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Bridge.h>
|
#include <Bridge.h>
|
||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
#include "TembooAccount.h" // contains Temboo account information
|
#include "TembooAccount.h" // contains Temboo account information
|
||||||
// as described in the footer comment below
|
// as described in the footer comment below
|
||||||
|
|
||||||
|
|
||||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||||
@ -43,7 +43,7 @@
|
|||||||
// your Dropbox app key, available on the Dropbox developer console after registering an app
|
// your Dropbox app key, available on the Dropbox developer console after registering an app
|
||||||
const String DROPBOX_APP_KEY = "xxxxxxxxxx";
|
const String DROPBOX_APP_KEY = "xxxxxxxxxx";
|
||||||
|
|
||||||
// your Dropbox app secret, available on the Dropbox developer console after registering an app
|
// your Dropbox app secret, available on the Dropbox developer console after registering an app
|
||||||
const String DROPBOX_APP_SECRET = "xxxxxxxxxx";
|
const String DROPBOX_APP_SECRET = "xxxxxxxxxx";
|
||||||
|
|
||||||
// your Dropbox access token, which is returned by the FinalizeOAuth Choreo
|
// your Dropbox access token, which is returned by the FinalizeOAuth Choreo
|
||||||
@ -57,10 +57,10 @@ boolean success = false; // a flag to indicate whether we've uploaded the file y
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// For debugging, wait until a serial console is connected.
|
// For debugging, wait until a serial console is connected.
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial);
|
while(!Serial);
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,23 +68,23 @@ void loop()
|
|||||||
{
|
{
|
||||||
// only try to upload the file if we haven't already done so
|
// only try to upload the file if we haven't already done so
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|
||||||
Serial.println("Base64 encoding data to upload...");
|
Serial.println("Base64 encoding data to upload...");
|
||||||
|
|
||||||
// base64 encode the data to upload
|
// base64 encode the data to upload
|
||||||
String base64EncodedData = base64Encode("Hello, Arduino!");
|
String base64EncodedData = base64Encode("Hello, Arduino!");
|
||||||
|
|
||||||
|
|
||||||
Serial.println("Uploading data to Dropbox...");
|
Serial.println("Uploading data to Dropbox...");
|
||||||
|
|
||||||
// we need a Process object to send a Choreo request to Temboo
|
// we need a Process object to send a Choreo request to Temboo
|
||||||
TembooChoreo UploadFileChoreo;
|
TembooChoreo UploadFileChoreo;
|
||||||
|
|
||||||
// invoke the Temboo client
|
// invoke the Temboo client
|
||||||
// NOTE that the client must be reinvoked and repopulated with
|
// NOTE that the client must be reinvoked and repopulated with
|
||||||
// appropriate arguments each time its run() method is called.
|
// appropriate arguments each time its run() method is called.
|
||||||
UploadFileChoreo.begin();
|
UploadFileChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT);
|
UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
@ -92,7 +92,7 @@ void loop()
|
|||||||
|
|
||||||
// identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile)
|
// identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile)
|
||||||
UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile");
|
UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile");
|
||||||
|
|
||||||
// set the required choreo inputs
|
// set the required choreo inputs
|
||||||
// see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/
|
// see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/
|
||||||
// for complete details about the inputs for this Choreo
|
// for complete details about the inputs for this Choreo
|
||||||
@ -103,31 +103,31 @@ void loop()
|
|||||||
// next, the root folder on Dropbox relative to which the file path is specified.
|
// next, the root folder on Dropbox relative to which the file path is specified.
|
||||||
// to work with the Dropbox app you created earlier, this should be left as "sandbox"
|
// to work with the Dropbox app you created earlier, this should be left as "sandbox"
|
||||||
// if your Dropbox app has full access to your files, specify "dropbox"
|
// if your Dropbox app has full access to your files, specify "dropbox"
|
||||||
UploadFileChoreo.addInput("Root", "sandbox");
|
UploadFileChoreo.addInput("Root","sandbox");
|
||||||
|
|
||||||
// next, the Base64 encoded file data to upload
|
// next, the Base64 encoded file data to upload
|
||||||
UploadFileChoreo.addInput("FileContents", base64EncodedData);
|
UploadFileChoreo.addInput("FileContents", base64EncodedData);
|
||||||
|
|
||||||
// finally, the Dropbox OAuth credentials defined above
|
// finally, the Dropbox OAuth credentials defined above
|
||||||
UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET);
|
UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET);
|
||||||
UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN);
|
UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN);
|
||||||
UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET);
|
UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET);
|
||||||
UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY);
|
UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY);
|
||||||
|
|
||||||
// tell the Process to run and wait for the results. The
|
// tell the Process to run and wait for the results. The
|
||||||
// return code (returnCode) will tell us whether the Temboo client
|
// return code (returnCode) will tell us whether the Temboo client
|
||||||
// was able to send our request to the Temboo servers
|
// was able to send our request to the Temboo servers
|
||||||
unsigned int returnCode = UploadFileChoreo.run();
|
unsigned int returnCode = UploadFileChoreo.run();
|
||||||
|
|
||||||
// a return code of zero (0) means everything worked
|
// a return code of zero (0) means everything worked
|
||||||
if (returnCode == 0) {
|
if (returnCode == 0) {
|
||||||
Serial.println("Success! File uploaded!");
|
Serial.println("Success! File uploaded!");
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
// a non-zero return code means there was an error
|
// a non-zero return code means there was an error
|
||||||
Serial.println("Uh-oh! Something went wrong!");
|
Serial.println("Uh-oh! Something went wrong!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// print out the full response to the serial monitor in all
|
// print out the full response to the serial monitor in all
|
||||||
// cases, just for debugging
|
// cases, just for debugging
|
||||||
while (UploadFileChoreo.available()) {
|
while (UploadFileChoreo.available()) {
|
||||||
@ -148,42 +148,42 @@ void loop()
|
|||||||
by calling a Temboo Utilities Choreo.
|
by calling a Temboo Utilities Choreo.
|
||||||
*/
|
*/
|
||||||
String base64Encode(String toEncode) {
|
String base64Encode(String toEncode) {
|
||||||
|
|
||||||
|
// we need a Process object to send a Choreo request to Temboo
|
||||||
|
TembooChoreo Base64EncodeChoreo;
|
||||||
|
|
||||||
// we need a Process object to send a Choreo request to Temboo
|
// invoke the Temboo client
|
||||||
TembooChoreo Base64EncodeChoreo;
|
Base64EncodeChoreo.begin();
|
||||||
|
|
||||||
|
// set Temboo account credentials
|
||||||
|
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
|
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
|
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||||
|
|
||||||
// invoke the Temboo client
|
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
|
||||||
Base64EncodeChoreo.begin();
|
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
|
||||||
|
|
||||||
|
// set choreo inputs
|
||||||
|
Base64EncodeChoreo.addInput("Text", toEncode);
|
||||||
|
|
||||||
|
// run the choreo
|
||||||
|
Base64EncodeChoreo.run();
|
||||||
|
|
||||||
|
// read in the choreo results, and return the "Base64EncodedText" output value.
|
||||||
|
// see http://www.temboo.com/arduino for more details on using choreo outputs.
|
||||||
|
while(Base64EncodeChoreo.available()) {
|
||||||
|
// read the name of the output item
|
||||||
|
String name = Base64EncodeChoreo.readStringUntil('\x1F');
|
||||||
|
name.trim();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// read the value of the output item
|
||||||
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
|
String data = Base64EncodeChoreo.readStringUntil('\x1E');
|
||||||
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
data.trim();
|
||||||
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
|
|
||||||
|
|
||||||
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
|
if(name == "Base64EncodedText") {
|
||||||
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
|
return data;
|
||||||
|
}
|
||||||
// set choreo inputs
|
|
||||||
Base64EncodeChoreo.addInput("Text", toEncode);
|
|
||||||
|
|
||||||
// run the choreo
|
|
||||||
Base64EncodeChoreo.run();
|
|
||||||
|
|
||||||
// read in the choreo results, and return the "Base64EncodedText" output value.
|
|
||||||
// see http://www.temboo.com/arduino for more details on using choreo outputs.
|
|
||||||
while (Base64EncodeChoreo.available()) {
|
|
||||||
// read the name of the output item
|
|
||||||
String name = Base64EncodeChoreo.readStringUntil('\x1F');
|
|
||||||
name.trim();
|
|
||||||
|
|
||||||
// read the value of the output item
|
|
||||||
String data = Base64EncodeChoreo.readStringUntil('\x1E');
|
|
||||||
data.trim();
|
|
||||||
|
|
||||||
if (name == "Base64EncodedText") {
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -194,15 +194,15 @@ String base64Encode(String toEncode) {
|
|||||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||||
look like:
|
look like:
|
||||||
|
|
||||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||||
|
|
||||||
You can find your Temboo App Key information on the Temboo website,
|
You can find your Temboo App Key information on the Temboo website,
|
||||||
under My Account > Application Keys
|
under My Account > Application Keys
|
||||||
|
|
||||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
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
|
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.
|
that you forgot to delete your credentials.
|
||||||
*/
|
*/
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
name=Temboo
|
name=Temboo
|
||||||
version=1.0
|
|
||||||
author=Temboo
|
author=Temboo
|
||||||
maintainer=Temboo <support@temboo.com>
|
email=support@temboo.com
|
||||||
sentence=This library enables calls to Temboo, a platform that connects the Yun to 100+ APIs.
|
sentence=This library enables calls to Temboo, a platform that connects the Yun to 100+ APIs.
|
||||||
paragraph=Temboo is a platform that provides normalized access to 100+ APIs, databases, code utilities and more. This library enables the Yun to connect to Temboo, making it simple to interact with a vast array of web-based resources and services.
|
paragraph=Temboo is a platform that provides normalized access to 100+ APIs, databases, code utilities and more. This library enables the Yun to connect to Temboo, making it simple to interact with a vast array of web-based resources and services.
|
||||||
url=http://www.temboo.com
|
url=http://www.temboo.com
|
||||||
architectures=*
|
architectures=avr
|
||||||
|
version=1.0
|
||||||
|
dependencies=
|
||||||
|
core-dependencies=arduino (>=1.5.0)
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
# Temboo Arduino Yun library
|
# Temboo Arduino Yun library
|
||||||
#
|
#
|
||||||
# Copyright 2013, Temboo Inc.
|
# Copyright 2013, Temboo Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing,
|
# Unless required by applicable law or agreed to in writing,
|
||||||
# software distributed under the License is distributed on an
|
# software distributed under the License is distributed on an
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
@ -23,42 +23,42 @@
|
|||||||
#include <Temboo.h>
|
#include <Temboo.h>
|
||||||
|
|
||||||
void TembooChoreo::begin() {
|
void TembooChoreo::begin() {
|
||||||
Process::begin("temboo");
|
Process::begin("temboo");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::setAccountName(const String& accountName) {
|
void TembooChoreo::setAccountName(const String& accountName) {
|
||||||
addParameter("-a" + accountName);
|
addParameter("-a" + accountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::setAppKeyName(const String& appKeyName) {
|
void TembooChoreo::setAppKeyName(const String& appKeyName) {
|
||||||
addParameter("-u" + appKeyName);
|
addParameter("-u" + appKeyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::setAppKey(const String& appKey) {
|
void TembooChoreo::setAppKey(const String& appKey) {
|
||||||
addParameter("-p" + appKey);
|
addParameter("-p" + appKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::setChoreo(const String& choreo) {
|
void TembooChoreo::setChoreo(const String& choreo) {
|
||||||
addParameter("-c" + choreo);
|
addParameter("-c" + choreo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::setCredential(const String& credentialName) {
|
void TembooChoreo::setCredential(const String& credentialName) {
|
||||||
addParameter("-e" + credentialName);
|
addParameter("-e" + credentialName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::addInput(const String& inputName, const String& inputValue) {
|
void TembooChoreo::addInput(const String& inputName, const String& inputValue) {
|
||||||
addParameter("-i" + inputName + ":" + inputValue);
|
addParameter("-i" + inputName + ":" + inputValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::addOutputFilter(const String& outputName, const String& filterPath, const String& variableName) {
|
void TembooChoreo::addOutputFilter(const String& outputName, const String& filterPath, const String& variableName) {
|
||||||
addParameter("-o" + outputName + ":" + filterPath + ":" + variableName);
|
addParameter("-o" + outputName + ":" + filterPath + ":" + variableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::setSettingsFileToWrite(const String& filePath) {
|
void TembooChoreo::setSettingsFileToWrite(const String& filePath) {
|
||||||
addParameter("-w" + filePath);
|
addParameter("-w" + filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TembooChoreo::setSettingsFileToRead(const String& filePath) {
|
void TembooChoreo::setSettingsFileToRead(const String& filePath) {
|
||||||
addParameter("-r" + filePath);
|
addParameter("-r" + filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
# Temboo Arduino Yun library
|
# Temboo Arduino Yun library
|
||||||
#
|
#
|
||||||
# Copyright 2013, Temboo Inc.
|
# Copyright 2013, Temboo Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing,
|
# Unless required by applicable law or agreed to in writing,
|
||||||
# software distributed under the License is distributed on an
|
# software distributed under the License is distributed on an
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
@ -27,18 +27,18 @@
|
|||||||
|
|
||||||
class TembooChoreo : public Process {
|
class TembooChoreo : public Process {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void begin();
|
void begin();
|
||||||
void setAccountName(const String& accountName);
|
void setAccountName(const String& accountName);
|
||||||
void setAppKeyName(const String& appKeyName);
|
void setAppKeyName(const String& appKeyName);
|
||||||
void setAppKey(const String& appKey);
|
void setAppKey(const String& appKey);
|
||||||
void setChoreo(const String& choreo);
|
void setChoreo(const String& choreo);
|
||||||
void setCredential(const String& credentialName);
|
void setCredential(const String& credentialName);
|
||||||
void addInput(const String& inputName, const String& inputValue);
|
void addInput(const String& inputName, const String& inputValue);
|
||||||
void addOutputFilter(const String& filterName, const String& filterPath, const String& variableName);
|
void addOutputFilter(const String& filterName, const String& filterPath, const String& variableName);
|
||||||
void setSettingsFileToWrite(const String& filePath);
|
void setSettingsFileToWrite(const String& filePath);
|
||||||
void setSettingsFileToRead(const String& filePath);
|
void setSettingsFileToRead(const String& filePath);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user