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:
@ -55,7 +55,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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -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);
|
||||||
@ -214,7 +214,7 @@ 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');
|
||||||
@ -243,7 +243,7 @@ void checkForMessages(bool 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);
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ 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.
|
||||||
|
@ -20,7 +20,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
|
||||||
|
|
||||||
|
|
||||||
// the address for which a weather forecast will be retrieved
|
// the address for which a weather forecast will be retrieved
|
||||||
@ -35,7 +35,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();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ void loop()
|
|||||||
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);
|
||||||
|
@ -27,7 +27,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: ***/
|
||||||
|
|
||||||
@ -46,7 +46,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();
|
||||||
}
|
}
|
||||||
void loop()
|
void loop()
|
||||||
@ -98,8 +98,8 @@ void loop()
|
|||||||
// 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
|
||||||
@ -115,7 +115,7 @@ void loop()
|
|||||||
// 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();
|
||||||
@ -137,7 +137,7 @@ void loop()
|
|||||||
} 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);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,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: ***/
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ void loop()
|
|||||||
|
|
||||||
// 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
|
||||||
|
@ -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: ***/
|
||||||
|
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ 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
|
||||||
@ -99,7 +99,7 @@ void loop()
|
|||||||
|
|
||||||
// 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
|
||||||
|
@ -33,7 +33,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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +62,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();
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ void loop()
|
|||||||
|
|
||||||
// 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
|
||||||
@ -128,7 +128,7 @@ void loop()
|
|||||||
SendSMSChoreo.close();
|
SendSMSChoreo.close();
|
||||||
|
|
||||||
// set the flag indicatine we've tried once.
|
// set the flag indicatine we've tried once.
|
||||||
attempted = true;
|
attempted=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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: ***/
|
||||||
@ -60,14 +60,14 @@ const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo
|
|||||||
// 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();
|
||||||
|
@ -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
|
||||||
|
|
@ -22,7 +22,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
|
||||||
|
|
||||||
// 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";
|
||||||
@ -35,7 +35,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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();
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ void loop()
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,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: ***/
|
||||||
|
|
||||||
@ -46,7 +46,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ void loop() {
|
|||||||
// 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);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,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: ***/
|
||||||
@ -60,7 +60,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ 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);
|
||||||
@ -121,8 +121,8 @@ void loop()
|
|||||||
|
|
||||||
// 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!");
|
||||||
@ -149,41 +149,41 @@ void loop()
|
|||||||
*/
|
*/
|
||||||
String base64Encode(String toEncode) {
|
String base64Encode(String toEncode) {
|
||||||
|
|
||||||
// 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 Base64EncodeChoreo;
|
TembooChoreo Base64EncodeChoreo;
|
||||||
|
|
||||||
// invoke the Temboo client
|
// invoke the Temboo client
|
||||||
Base64EncodeChoreo.begin();
|
Base64EncodeChoreo.begin();
|
||||||
|
|
||||||
// set Temboo account credentials
|
// set Temboo account credentials
|
||||||
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
|
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||||
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||||
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
|
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||||
|
|
||||||
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
|
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
|
||||||
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
|
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
|
||||||
|
|
||||||
// set choreo inputs
|
// set choreo inputs
|
||||||
Base64EncodeChoreo.addInput("Text", toEncode);
|
Base64EncodeChoreo.addInput("Text", toEncode);
|
||||||
|
|
||||||
// run the choreo
|
// run the choreo
|
||||||
Base64EncodeChoreo.run();
|
Base64EncodeChoreo.run();
|
||||||
|
|
||||||
// read in the choreo results, and return the "Base64EncodedText" output value.
|
// read in the choreo results, and return the "Base64EncodedText" output value.
|
||||||
// see http://www.temboo.com/arduino for more details on using choreo outputs.
|
// see http://www.temboo.com/arduino for more details on using choreo outputs.
|
||||||
while (Base64EncodeChoreo.available()) {
|
while(Base64EncodeChoreo.available()) {
|
||||||
// read the name of the output item
|
// read the name of the output item
|
||||||
String name = Base64EncodeChoreo.readStringUntil('\x1F');
|
String name = Base64EncodeChoreo.readStringUntil('\x1F');
|
||||||
name.trim();
|
name.trim();
|
||||||
|
|
||||||
// read the value of the output item
|
// read the value of the output item
|
||||||
String data = Base64EncodeChoreo.readStringUntil('\x1E');
|
String data = Base64EncodeChoreo.readStringUntil('\x1E');
|
||||||
data.trim();
|
data.trim();
|
||||||
|
|
||||||
if (name == "Base64EncodedText") {
|
if(name == "Base64EncodedText") {
|
||||||
return data;
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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)
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,17 +27,17 @@
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user