diff options
Diffstat (limited to 'libraries/Bridge/examples')
35 files changed, 2625 insertions, 0 deletions
diff --git a/libraries/Bridge/examples/Bridge/Bridge.ino b/libraries/Bridge/examples/Bridge/Bridge.ino new file mode 100644 index 0000000..277982a --- /dev/null +++ b/libraries/Bridge/examples/Bridge/Bridge.ino @@ -0,0 +1,175 @@ + +// Possible commands are listed here: +// +// "digital/13" -> digitalRead(13) +// "digital/13/1" -> digitalWrite(13, HIGH) +// "analog/2/123" -> analogWrite(2, 123) +// "analog/2" -> analogRead(2) +// "mode/13/input" -> pinMode(13, INPUT) +// "mode/13/output" -> pinMode(13, OUTPUT) + +#include <Bridge.h> +#include <YunServer.h> +#include <YunClient.h> + +// Listen on default port 5555, the webserver on the Yun +// will forward there all the HTTP requests for us. +YunServer server; + +void setup() { + Serial.begin(9600); + + // Bridge startup + pinMode(13,OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); + digitalWrite(13, HIGH); + + // Listen for incoming connection only from localhost + // (no one from the external network could connect) + server.listenOnLocalhost(); + server.begin(); +} + +void loop() { + // Get clients coming from server + YunClient client = server.accept(); + + // There is a new client? + if (client) { + // Process request + process(client); + + // Close connection and free resources. + client.stop(); + } + + delay(50); // Poll every 50ms +} + +void process(YunClient client) { + // read the command + String command = client.readStringUntil('/'); + + // is "digital" command? + if (command == "digital") { + digitalCommand(client); + } + + // is "analog" command? + if (command == "analog") { + analogCommand(client); + } + + // is "mode" command? + if (command == "mode") { + modeCommand(client); + } +} + +void digitalCommand(YunClient client) { + int pin, value; + + // Read pin number + pin = client.parseInt(); + + // If the next character is a '/' it means we have an URL + // with a value like: "/digital/13/1" + if (client.read() == '/') { + value = client.parseInt(); + digitalWrite(pin, value); + } + else { + value = digitalRead(pin); + } + + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" set to ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "D"; + key += pin; + Bridge.put(key, String(value)); +} + +void analogCommand(YunClient client) { + int pin, value; + + // Read pin number + pin = client.parseInt(); + + // If the next character is a '/' it means we have an URL + // with a value like: "/analog/5/120" + if (client.read() == '/') { + // Read value and execute command + value = client.parseInt(); + analogWrite(pin, value); + + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" set to analog ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "D"; + key += pin; + Bridge.put(key, String(value)); + } + else { + // Read analog pin + value = analogRead(pin); + + // Send feedback to client + client.print(F("Pin A")); + client.print(pin); + client.print(F(" reads analog ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "A"; + key += pin; + Bridge.put(key, String(value)); + } +} + +void modeCommand(YunClient client) { + int pin; + + // Read pin number + pin = client.parseInt(); + + // If the next character is not a '/' we have a malformed URL + if (client.read() != '/') { + client.println(F("error")); + return; + } + + String mode = client.readStringUntil('\r'); + + if (mode == "input") { + pinMode(pin, INPUT); + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" configured as INPUT!")); + return; + } + + if (mode == "output") { + pinMode(pin, OUTPUT); + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" configured as OUTPUT!")); + return; + } + + client.print(F("error: invalid mode ")); + client.print(mode); +} + + diff --git a/libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino b/libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino new file mode 100644 index 0000000..4cdf4c1 --- /dev/null +++ b/libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino @@ -0,0 +1,94 @@ +/* + ASCII table + + Prints out byte values in all possible formats: + * as raw binary values + * as ASCII-encoded decimal, hex, octal, and binary values + + For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII + + The circuit: No external hardware needed. + + created 2006 + by Nicholas Zambetti + modified 9 Apr 2012 + by Tom Igoe + modified 22 May 2013 + by Cristian Maglie + + This example code is in the public domain. + + <http://www.zambetti.com> + + */ + +#include <Console.h> + +void setup() { + //Initialize Console and wait for port to open: + Bridge.begin(); + Console.begin(); + + // Uncomment the following line to enable buffering: + // - better transmission speed and efficiency + // - needs to call Console.flush() to ensure that all + // transmitted data is sent + + //Console.buffer(64); + + while (!Console) { + ; // wait for Console port to connect. + } + + // prints title with ending line break + Console.println("ASCII Table ~ Character Map"); +} + +// first visible ASCIIcharacter '!' is number 33: +int thisByte = 33; +// you can also write ASCII characters in single quotes. +// for example. '!' is the same as 33, so you could also use this: +//int thisByte = '!'; + +void loop() { + // prints value unaltered, i.e. the raw binary version of the + // byte. The Console monitor interprets all bytes as + // ASCII, so 33, the first number, will show up as '!' + Console.write(thisByte); + + Console.print(", dec: "); + // prints value as string as an ASCII-encoded decimal (base 10). + // Decimal is the default format for Console.print() and Console.println(), + // so no modifier is needed: + Console.print(thisByte); + // But you can declare the modifier for decimal if you want to. + //this also works if you uncomment it: + + // Console.print(thisByte, DEC); + + Console.print(", hex: "); + // prints value as string in hexadecimal (base 16): + Console.print(thisByte, HEX); + + Console.print(", oct: "); + // prints value as string in octal (base 8); + Console.print(thisByte, OCT); + + Console.print(", bin: "); + // prints value as string in binary (base 2) + // also prints ending line break: + Console.println(thisByte, BIN); + + // if printed last visible character '~' or 126, stop: + if(thisByte == 126) { // you could also use if (thisByte == '~') { + // ensure the latest bit of data is sent + Console.flush(); + + // This loop loops forever and does nothing + while(true) { + continue; + } + } + // go on to the next character + thisByte++; +} diff --git a/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino b/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino new file mode 100644 index 0000000..c962b6e --- /dev/null +++ b/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino @@ -0,0 +1,62 @@ +/* + Console Pixel + + An example of using the Arduino board to receive data from the + Console on the Arduino Yun. In this case, the Arduino boards turns on an LED when + it receives the character 'H', and turns off the LED when it + receives the character 'L'. + + To see the Console, pick your Yún's name and IP address in the Port menu + then open the Port Monitor. You can also see it by opening a terminal window + and typing + ssh root@ yourYunsName.local 'telnet localhost 6571' + then pressing enter. When prompted for the password, enter it. + + + The circuit: + * LED connected from digital pin 13 to ground + + created 2006 + by David A. Mellis + modified 25 Jun 2013 + by Tom Igoe + + This example code is in the public domain. + + */ + +#include <Console.h> + +const int ledPin = 13; // the pin that the LED is attached to +char incomingByte; // a variable to read incoming Console data into + +void setup() { + Bridge.begin(); // Initialize Bridge + Console.begin(); // Initialize Console + + // Wait for the Console port to connect + while(!Console); + + Console.println("type H or L to turn pin 13 on or off"); + + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // see if there's incoming Console data: + if (Console.available() > 0) { + // read the oldest byte in the Console buffer: + incomingByte = Console.read(); + Console.println(incomingByte); + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + digitalWrite(ledPin, HIGH); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + digitalWrite(ledPin, LOW); + } + } +} + diff --git a/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino new file mode 100644 index 0000000..0019c20 --- /dev/null +++ b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino @@ -0,0 +1,56 @@ +/* + Console Read example + + Read data coming from bridge using the Console.read() function + and store it in a string. + + To see the Console, pick your Yún's name and IP address in the Port menu + then open the Port Monitor. You can also see it by opening a terminal window + and typing: + ssh root@ yourYunsName.local 'telnet localhost 6571' + then pressing enter. When prompted for the password, enter it. + + created 13 Jun 2013 + by Angelo Scialabba + modified 16 June 2013 + by Tom Igoe + + This example code is in the public domain. + */ + +#include <Console.h> + +String name; + +void setup() { + // Initialize Console and wait for port to open: + Bridge.begin(); + Console.begin(); + + // Wait for Console port to connect + while (!Console); + + Console.println("Hi, what's your name?"); +} + +void loop() { + if (Console.available() > 0) { + char c = Console.read(); // read the next char received + // look for the newline character, this is the last character in the string + if (c == '\n') { + //print text with the name received + Console.print("Hi "); + Console.print(name); + Console.println("! Nice to meet you!"); + Console.println(); + // Ask again for name and clear the old name + Console.println("Hi, what's your name?"); + name = ""; // clear the name string + } + else { // if the buffer is empty Cosole.read() returns -1 + name += c; // append the read char from Console to the name string + } + } +} + + diff --git a/libraries/Bridge/examples/Datalogger/Datalogger.ino b/libraries/Bridge/examples/Datalogger/Datalogger.ino new file mode 100644 index 0000000..2d792a4 --- /dev/null +++ b/libraries/Bridge/examples/Datalogger/Datalogger.ino @@ -0,0 +1,99 @@ +/* + SD card datalogger + + This example shows how to log data from three analog sensors + to an SD card mounted on the Arduino Yún using the Bridge library. + + The circuit: + * analog sensors on analog pins 0, 1 and 2 + * SD card attached to SD card slot of the Arduino Yún + + Prepare your SD card creating an empty folder in the SD root + named "arduino". This will ensure that the Yún will create a link + to the SD to the "/mnt/sd" path. + + You can remove the SD card while the Linux and the + sketch are running but be careful not to remove it while + the system is writing to it. + + created 24 Nov 2010 + modified 9 Apr 2012 + by Tom Igoe + adapted to the Yún Bridge library 20 Jun 2013 + by Federico Vanzati + modified 21 Jun 2013 + by Tom Igoe + + This example code is in the public domain. + + */ + +#include <FileIO.h> + +void setup() { + // Initialize the Bridge and the Serial + Bridge.begin(); + Serial.begin(9600); + FileSystem.begin(); + + while(!Serial); // wait for Serial port to connect. + Serial.println("Filesystem datalogger\n"); +} + + +void loop () { + // make a string that start with a timestamp for assembling the data to log: + String dataString; + dataString += getTimeStamp(); + dataString += " = "; + + // read three sensors and append to the string: + for (int analogPin = 0; analogPin < 3; analogPin++) { + int sensor = analogRead(analogPin); + dataString += String(sensor); + if (analogPin < 2) { + dataString += ","; // separate the values with a comma + } + } + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + // The FileSystem card is mounted at the following "/mnt/FileSystema1" + File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND); + + // if the file is available, write to it: + if (dataFile) { + dataFile.println(dataString); + dataFile.close(); + // print to the serial port too: + Serial.println(dataString); + } + // if the file isn't open, pop up an error: + else { + Serial.println("error opening datalog.txt"); + } + + delay(15000); + +} + +// This function return a string with the time stamp +String getTimeStamp() { + String result; + Process time; + // date is a command line utility to get the date and the time + // in different formats depending on the additional parameter + time.begin("date"); + time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy + // T for the time hh:mm:ss + time.run(); // run the command + + // read the output of the command + while(time.available()>0) { + char c = time.read(); + if(c != '\n') + result += c; + } + + return result; +} diff --git a/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino b/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino new file mode 100644 index 0000000..b550db2 --- /dev/null +++ b/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino @@ -0,0 +1,82 @@ +/* + Write to file using FileIO classes. + + This sketch demonstrate how to write file into the Yún filesystem. + A shell script file is created in /tmp, and it is executed afterwards. + + created 7 June 2010 + by Cristian Maglie + + This example code is in the public domain. + + */ + +#include <FileIO.h> + +void setup() { + // Setup Bridge (needed every time we communicate with the Arduino Yún) + Bridge.begin(); + // Initialize the Serial + Serial.begin(9600); + + while(!Serial); // wait for Serial port to connect. + Serial.println("File Write Script example\n\n"); + + // Setup File IO + FileSystem.begin(); + + // Upload script used to gain network statistics + uploadScript(); +} + +void loop() { + // Run stats script every 5 secs. + runScript(); + delay(5000); +} + +// this function creates a file into the linux processor that contains a shell script +// to check the network traffic of the WiFi interface +void uploadScript() { + // Write our shell script in /tmp + // Using /tmp stores the script in RAM this way we can preserve + // the limited amount of FLASH erase/write cycles + File script = FileSystem.open("/tmp/wlan-stats.sh", FILE_WRITE); + // Shell script header + script.print("#!/bin/sh\n"); + // shell commands: + // ifconfig: is a command line utility for controlling the network interfaces. + // wlan0 is the interface we want to query + // grep: search inside the output of the ifconfig command the "RX bytes" keyword + // and extract the line that contains it + script.print("ifconfig wlan0 | grep 'RX bytes'\n"); + script.close(); // close the file + + // Make the script executable + Process chmod; + chmod.begin("chmod"); // chmod: change mode + chmod.addParameter("+x"); // x stays for executable + chmod.addParameter("/tmp/wlan-stats.sh"); // path to the file to make it executable + chmod.run(); +} + + +// this function run the script and read the output data +void runScript() { + // Run the script and show results on the Serial + Process myscript; + myscript.begin("/tmp/wlan-stats.sh"); + myscript.run(); + + String output = ""; + + // read the output of the script + while (myscript.available()) { + output += (char)myscript.read(); + } + // remove the blank spaces at the beginning and the ending of the string + output.trim(); + Serial.println(output); + Serial.flush(); +} + diff --git a/libraries/Bridge/examples/HttpClient/HttpClient.ino b/libraries/Bridge/examples/HttpClient/HttpClient.ino new file mode 100644 index 0000000..4104ef4 --- /dev/null +++ b/libraries/Bridge/examples/HttpClient/HttpClient.ino @@ -0,0 +1,26 @@ + +#include <Bridge.h> +#include <HttpClient.h> + +void setup() { + pinMode(13, OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); + Serial.begin(9600); + while(!Serial); +} + +void loop() { + HttpClient client; + client.get("http://arduino.cc/asciilogo.txt"); + + while (client.available()) { + char c = client.read(); + Serial.print(c); + } + Serial.flush(); + + delay(5000); +} + + diff --git a/libraries/Bridge/examples/Process/Process.ino b/libraries/Bridge/examples/Process/Process.ino new file mode 100644 index 0000000..7646d15 --- /dev/null +++ b/libraries/Bridge/examples/Process/Process.ino @@ -0,0 +1,70 @@ +/* + Running process using Process class. + + This sketch demonstrate how to run linux processes + using an Arduino Yún. + + created 5 Jun 2013 + by Cristian Maglie + + This example code is in the public domain. + + */ + +#include <Process.h> + +void setup() { + // Initialize Bridge + Bridge.begin(); + + // Initialize Serial + Serial.begin(9600); + + // Wait until a Serial Monitor is connected. + while (!Serial); + + // run various example processes + runCurl(); + runCpuInfo(); +} + +void loop() { + // Do nothing here. +} + +void runCurl() { + // Launch "curl" command and get Arduino ascii art logo from the network + // curl is command line program for transferring data using different internet protocols + Process p; // Create a process and call it "p" + p.begin("curl"); // Process that launch the "curl" command + p.addParameter("http://arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl" + p.run(); // Run the process and wait for its termination + + // Print arduino logo over the Serial + // A process output can be read with the stream methods + while (p.available()>0) { + char c = p.read(); + Serial.print(c); + } + // Ensure the last bit of data is sent. + Serial.flush(); +} + +void runCpuInfo() { + // Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU) + // cat is a command line utility that shows the content of a file + Process p; // Create a process and call it "p" + p.begin("cat"); // Process that launch the "cat" command + p.addParameter("/proc/cpuinfo"); // Add the cpuifo file path as parameter to cut + p.run(); // Run the process and wait for its termination + + // Print command output on the Serial. + // A process output can be read with the stream methods + while (p.available()>0) { + char c = p.read(); + Serial.print(c); + } + // Ensure the last bit of data is sent. + Serial.flush(); +} + diff --git a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino new file mode 100644 index 0000000..5a4c291 --- /dev/null +++ b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino @@ -0,0 +1,53 @@ +/* + Running shell commands using Process class. + + This sketch demonstrate how to run linux shell commands + using an Arduino Yún. It runs the wifiCheck script on the linino side + of the Yun, then uses grep to get just the signal strength line. + Then it uses parseInt() to read the wifi signal strength as an integer, + and finally uses that number to fade an LED using analogWrite(). + + The circuit: + * Arduino Yun with LED connected to pin 9 + + created 12 Jun 2013 + by Cristian Maglie + modified 25 June 2013 + by Tom Igoe + + This example code is in the public domain. + + */ + +#include <Process.h> + +void setup() { + Bridge.begin(); // Initialize the Bridge + Serial.begin(9600); // Initialize the Serial + + // Wait until a Serial Monitor is connected. + while(!Serial); +} + +void loop() { + Process p; + // This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then + // sends the result to the grep command to look for a line containing the word + // "Signal:" the result is passed to this sketch: + p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal"); + + // do nothing until the process finishes, so you get the whole output: + while(p.running()); + + // Read command output. runShellCommand() should have passed "Signal: xx&": + while (p.available()) { + int result = p.parseInt(); // look for an integer + int signal = map(result, 0, 100, 0, 255); // map result from 0-100 range to 0-255 + analogWrite(9, signal); // set the brightness of LED on pin 9 + Serial.println(result); // print the number as well + } + delay(5000); // wait 5 seconds before you do it again +} + + + diff --git a/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino b/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino new file mode 100644 index 0000000..669aba5 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino @@ -0,0 +1,115 @@ +/* + GetYahooWeatherReport + + 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 + + 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 + + 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 + + +// the address for which a weather forecast will be retrieved +String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013"; + +int numRuns = 1; // execution count, so that this doesn't run forever +int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run + + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + Bridge.begin(); + +} + +void loop() +{ + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "..."); + + // create a TembooChoreo object to send a Choreo request to Temboo + TembooChoreo GetWeatherByAddressChoreo; + + // invoke the Temboo client + GetWeatherByAddressChoreo.begin(); + + // add your temboo account info + GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT); + GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY); + + // set the name of the choreo we want to run + GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress"); + + // set choreo inputs; in this case, the address for which to retrieve weather data + // the Temboo client provides standardized calls to 100+ cloud APIs + GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST); + + // add an output filter to extract the name of the city. + GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response"); + + // add an output filter to extract the current temperature + GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response"); + + // add an output filter to extract the date and time of the last report. + GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response"); + + // run the choreo + GetWeatherByAddressChoreo.run(); + + // when the choreo results are available, print them to the serial monitor + while(GetWeatherByAddressChoreo.available()) { + + char c = GetWeatherByAddressChoreo.read(); + Serial.print(c); + } + GetWeatherByAddressChoreo.close(); + + } + + Serial.println("Waiting..."); + Serial.println(""); + delay(30000); // wait 30 seconds between GetWeatherByAddress calls +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/TembooAccount.h b/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/TembooAccount.h new file mode 100644 index 0000000..c58b447 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/TembooAccount.h @@ -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 + diff --git a/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino b/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino new file mode 100644 index 0000000..b2edd1f --- /dev/null +++ b/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino @@ -0,0 +1,173 @@ +/* + ReadATweet + + Demonstrates retrieving the most recent Tweet from a user's home timeline + using Temboo from an Arduino Yun. + + 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 + + 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 + app, you'll find OAuth credentials for that application under the "OAuth Tool" tab. + Substitute these values for the placeholders below. + + This example assumes basic familiarity with Arduino sketches, and that your Yun + is connected to the Internet. + + Want to use another social API with your Arduino Yun? We've got Facebook, + Google+, Instagram, Tumblr and more 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 TWITTER_ACCESS_TOKEN = "your-twitter-access-token"; +const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret"; +const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key"; +const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret"; + +int numRuns = 1; // execution count, so this doesn't run forever +int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo should run + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while(!Serial); + Bridge.begin(); +} +void loop() +{ + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + Serial.println("Running ReadATweet - Run #" + String(numRuns++)); + + TembooChoreo HomeTimelineChoreo; + + // invoke the Temboo client. + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + HomeTimelineChoreo.begin(); + + // set Temboo account credentials + HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT); + HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + HomeTimelineChoreo.setAppKey(TEMBOO_APP_KEY); + + // tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline) + HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline"); + + + // set the required choreo inputs + // see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/ + // for complete details about the inputs for this Choreo + + HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request + HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); + HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); + HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); + + // next, we'll define two output filters that let us specify the + // elements of the response from Twitter that we want to receive. + // see the examples at http://www.temboo.com/arduino + // for more on using output filters + + // we want the text of the tweet + HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response"); + + // and the name of the author + HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response"); + + + // tell the Process to run and wait for the results. The + // return code will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = HomeTimelineChoreo.run(); + + // a response code of 0 means success; print the API response + if(returnCode == 0) { + + String author; // a String to hold the tweet author's name + String tweet; // a String to hold the text of the tweet + + + // choreo outputs are returned as key/value pairs, delimited with + // newlines and record/field terminator characters, for example: + // Name1\n\x1F + // Value1\n\x1E + // Name2\n\x1F + // Value2\n\x1E + + // see the examples at http://www.temboo.com/arduino for more details + // we can read this format into separate variables, as follows: + + while(HomeTimelineChoreo.available()) { + // read the name of the output item + String name = HomeTimelineChoreo.readStringUntil('\x1F'); + name.trim(); + + // read the value of the output item + String data = HomeTimelineChoreo.readStringUntil('\x1E'); + data.trim(); + + // assign the value to the appropriate String + if (name == "tweet") { + tweet = data; + } else if (name == "author") { + author = data; + } + } + + Serial.println("@" + author + " - " + tweet); + + } else { + // there was an error + // print the raw output from the choreo + while(HomeTimelineChoreo.available()) { + char c = HomeTimelineChoreo.read(); + Serial.print(c); + } + } + + HomeTimelineChoreo.close(); + + } + + Serial.println("Waiting..."); + delay(90000); // wait 90 seconds between HomeTimeline calls +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/ReadATweet/TembooAccount.h b/libraries/Bridge/examples/Temboo/ReadATweet/TembooAccount.h new file mode 100644 index 0000000..c58b447 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/ReadATweet/TembooAccount.h @@ -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 + diff --git a/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino b/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino new file mode 100644 index 0000000..2e34a82 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino @@ -0,0 +1,138 @@ +/* + SendATweet + + Demonstrates sending a tweet via a Twitter account using Temboo from an Arduino Yun. + + 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 + + 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 + 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 + for that application under the "OAuth Tool" tab. Substitute these values for + the placeholders below. + + This example assumes basic familiarity with Arduino sketches, and that your Yun is connected + to the Internet. + + Want to use another social API with your Arduino Yun? We've got Facebook, + Google+, Instagram, Tumblr and more 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 TWITTER_ACCESS_TOKEN = "your-twitter-access-token"; +const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret"; +const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key"; +const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret"; + +int numRuns = 1; // execution count, so this sketch doesn't run forever +int maxRuns = 3; // the max number of times the Twitter Update Choreo should run + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + + Bridge.begin(); +} + +void loop() +{ + // only try to send the tweet if we haven't already sent it successfully + if (numRuns <= maxRuns) { + + Serial.println("Running SendATweet - Run #" + String(numRuns++) + "..."); + + // define the text of the tweet we want to send + String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds."); + + + TembooChoreo StatusesUpdateChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + StatusesUpdateChoreo.begin(); + + // set Temboo account credentials + StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT); + StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate) + StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate"); + + // set the required choreo inputs + // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ + // for complete details about the inputs for this Choreo + + // add the Twitter account information + StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); + StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); + StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); + + // and the tweet we want to send + StatusesUpdateChoreo.addInput("StatusUpdate", tweetText); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = StatusesUpdateChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! Tweet sent!"); + } else { + // a non-zero return code means there was an error + // read and print the error message + while (StatusesUpdateChoreo.available()) { + char c = StatusesUpdateChoreo.read(); + Serial.print(c); + } + } + StatusesUpdateChoreo.close(); + + // do nothing for the next 90 seconds + Serial.println("Waiting..."); + delay(90000); + } +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/SendATweet/TembooAccount.h b/libraries/Bridge/examples/Temboo/SendATweet/TembooAccount.h new file mode 100644 index 0000000..c58b447 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendATweet/TembooAccount.h @@ -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 + diff --git a/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino b/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino new file mode 100644 index 0000000..a1cabce --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino @@ -0,0 +1,138 @@ +/* + SendAnEmail + + Demonstrates sending an email via a Google Gmail account using Temboo from an Arduino Yun. + + 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 + + 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 + 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 + 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. + +// your Gmail username, formatted as a complete email address, eg "bob.smith@gmail.com" +const String GMAIL_USER_NAME = "xxxxxxxxxx"; + +// your Gmail password +const String GMAIL_PASSWORD = "xxxxxxxxxx"; + +// the email address you want to send the email to, eg "jane.doe@temboo.com" +const String TO_EMAIL_ADDRESS = "xxxxxxxxxx"; + + +boolean success = false; // a flag to indicate whether we've sent the email yet or not + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + + Bridge.begin(); +} + +void loop() +{ + // only try to send the email if we haven't already sent it successfully + if (!success) { + + Serial.println("Running SendAnEmail..."); + + TembooChoreo SendEmailChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + SendEmailChoreo.begin(); + + // set Temboo account credentials + SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); + SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SendEmailChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library choreo to run (Google > Gmail > SendEmail) + SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); + + + // set the required choreo inputs + // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ + // for complete details about the inputs for this Choreo + + // the first input is your Gmail email address. + SendEmailChoreo.addInput("Username", GMAIL_USER_NAME); + // next is your Gmail password. + SendEmailChoreo.addInput("Password", GMAIL_PASSWORD); + // who to send the email to + SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS); + // then a subject line + SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature"); + + // next comes the message body, the main content of the email + SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!"); + + // tell the Choreo to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SendEmailChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! Email sent!"); + success = true; + } else { + // a non-zero return code means there was an error + // read and print the error message + while (SendEmailChoreo.available()) { + char c = SendEmailChoreo.read(); + Serial.print(c); + } + } + SendEmailChoreo.close(); + + // do nothing for the next 60 seconds + delay(60000); + } +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/SendAnEmail/TembooAccount.h b/libraries/Bridge/examples/Temboo/SendAnEmail/TembooAccount.h new file mode 100644 index 0000000..c58b447 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendAnEmail/TembooAccount.h @@ -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 + diff --git a/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino b/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino new file mode 100644 index 0000000..04c827e --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino @@ -0,0 +1,155 @@ +/* + SendAnSMS + + Demonstrates sending an SMS via Twilio using Temboo from an Arduino Yun. + + 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 + + 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. + + The sketch needs your Twilio phone number, along with + 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 + (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 + 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 + doesn't apply if you have a paid Twilio account). + + 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. + +// the Account SID from your Twilio account +const String TWILIO_ACCOUNT_SID = "xxxxxxxxxx"; + +// the Auth Token from your Twilio account +const String TWILIO_AUTH_TOKEN = "xxxxxxxxxx"; + +// your Twilio phone number, e.g., "+1 555-222-1212" +const String TWILIO_NUMBER = "xxxxxxxxxx"; + +// the number to which the SMS should be sent, e.g., "+1 555-222-1212" +const String RECIPIENT_NUMBER = "xxxxxxxxxx"; + +boolean success = false; // a flag to indicate whether we've sent the SMS yet or not + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + + Bridge.begin(); +} + +void loop() +{ + // only try to send the SMS if we haven't already sent it successfully + if (!success) { + + Serial.println("Running SendAnSMS..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo SendSMSChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + SendSMSChoreo.begin(); + + // set Temboo account credentials + SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT); + SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SendSMSChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library choreo to run (Twilio > SMSMessages > SendSMS) + SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS"); + + // set the required choreo inputs + // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ + // for complete details about the inputs for this Choreo + + // the first input is a your AccountSID + SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID); + + // next is your Auth Token + SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN); + + // next is your Twilio phone number + SendSMSChoreo.addInput("From", TWILIO_NUMBER); + + // next, what number to send the SMS to + SendSMSChoreo.addInput("To", RECIPIENT_NUMBER); + + // finally, the text of the message to send + SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!"); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SendSMSChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! SMS sent!"); + success = true; + } else { + // a non-zero return code means there was an error + // read and print the error message + while (SendSMSChoreo.available()) { + char c = SendSMSChoreo.read(); + Serial.print(c); + } + } + SendSMSChoreo.close(); + + // do nothing for the next 60 seconds + Serial.println("Waiting..."); + delay(60000); + } +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/SendAnSMS/TembooAccount.h b/libraries/Bridge/examples/Temboo/SendAnSMS/TembooAccount.h new file mode 100644 index 0000000..8d7dcfb --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendAnSMS/TembooAccount.h @@ -0,0 +1,5 @@ +#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 + + diff --git a/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino new file mode 100644 index 0000000..1f1b6b4 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino @@ -0,0 +1,178 @@ +/* + SendDataToGoogleSpreadsheet + + Demonstrates appending a row of data to a Google spreadsheet using Temboo from an Arduino Yun. + + 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 + + Since this sketch uses a Google spreadsheet, you'll also need a + Google account: substitute the placeholders below for your Google account values. + + This example assumes basic familiarity with Arduino sketches, and that your + Yun is connected to the Internet. + + The columns in your spreadsheet must have labels for the Choreo to + work properly. It doesn't matter what the column labels actually are, + but there must be text in the first row of each column. This example + 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. + In other words, your spreadsheet should look like: + + Time | Sensor Value | + ------+----------------- + | | + + 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. + + 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 GOOGLE_USERNAME = "your-google-username"; +const String GOOGLE_PASSWORD = "your-google-password"; + +// the title of the spreadsheet you want to send data to +// (Note that this must actually be the title of a Google spreadsheet +// that exists in your Google Drive/Docs account, and is configured +// as described above.) +const String SPREADSHEET_TITLE = "your-spreadsheet-title"; + +const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds) + +// the last time we ran the Choreo +// (initialized to 60 seconds ago so the +// Choreo is run immediately when we start up) +unsigned long lastRun = (unsigned long)-60000; + +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("Done"); +} + +void loop() +{ + // get the number of milliseconds this sketch has been running + unsigned long now = millis(); + + // run again if it's been 60 seconds since we last ran + if (now - lastRun >= RUN_INTERVAL_MILLIS) { + + // remember 'now' as the last time we ran the choreo + lastRun = now; + + Serial.println("Getting sensor value..."); + + // get the value we want to append to our spreadsheet + unsigned long sensorValue = getSensorValue(); + + Serial.println("Appending value to spreadsheet..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo AppendRowChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + AppendRowChoreo.begin(); + + // set Temboo account credentials + AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT); + AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + AppendRowChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow) + AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/ + // for complete details about the inputs for this Choreo + + // your Google username (usually your email address) + AppendRowChoreo.addInput("Username", GOOGLE_USERNAME); + + // your Google account password + AppendRowChoreo.addInput("Password", GOOGLE_PASSWORD); + + // the title of the spreadsheet you want to append to + // NOTE: substitute your own value, retaining the "SpreadsheetTitle:" prefix. + AppendRowChoreo.addInput("SpreadsheetTitle", SPREADSHEET_TITLE); + + // convert the time and sensor values to a comma separated string + String rowData(now); + rowData += ","; + rowData += sensorValue; + + // add the RowData input item + AppendRowChoreo.addInput("RowData", rowData); + + // run the Choreo and wait for the results + // The return code (returnCode) will indicate success or failure + unsigned int returnCode = AppendRowChoreo.run(); + + // return code of zero (0) means success + if (returnCode == 0) { + Serial.println("Success! Appended " + rowData); + Serial.println(""); + } else { + // return code of anything other than zero means failure + // read and display any error messages + while (AppendRowChoreo.available()) { + char c = AppendRowChoreo.read(); + Serial.print(c); + } + } + + AppendRowChoreo.close(); + } +} + +// this function simulates reading the value of a sensor +unsigned long getSensorValue() { + return analogRead(A0); +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/TembooAccount.h b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/TembooAccount.h new file mode 100644 index 0000000..8d7dcfb --- /dev/null +++ b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/TembooAccount.h @@ -0,0 +1,5 @@ +#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 + + diff --git a/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/TembooAccount.h b/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/TembooAccount.h new file mode 100644 index 0000000..8d7dcfb --- /dev/null +++ b/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/TembooAccount.h @@ -0,0 +1,5 @@ +#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 + + diff --git a/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino b/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino new file mode 100644 index 0000000..3b7f1d1 --- /dev/null +++ b/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino @@ -0,0 +1,171 @@ +/* + ToxicFacilitiesSearch + + 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 + 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 + + 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 + + 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 + +// the zip code to search for toxin-emitting facilities +String US_ZIP_CODE = "11215"; + +int numRuns = 1; // execution count, so that this doesn't run forever +int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Choreo should be run + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + Bridge.begin(); +} + +void loop() +{ + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo FacilitiesSearchByZipChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + FacilitiesSearchByZipChoreo.begin(); + + // set Temboo account credentials + FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT); + FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library choreo to run (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 + // the Temboo client provides standardized calls to 100+ cloud APIs + FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE); + + // 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 + FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response"); + + FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response"); + + // run the choreo + unsigned int returnCode = FacilitiesSearchByZipChoreo.run(); + if (returnCode == 0) { + String facilities; + String addresses; + + // when the choreo results are available, process them. + // the output filters we specified will return comma delimited + // lists containing the name and street address of the facilities + // located in the specified zip code. + while(FacilitiesSearchByZipChoreo.available()) { + String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F'); + name.trim(); + + String data = FacilitiesSearchByZipChoreo.readStringUntil('\x1E'); + data.trim(); + + if (name == "fac") { + facilities = data; + } else if (name == "addr") { + addresses = data; + } + } + FacilitiesSearchByZipChoreo.close(); + + // parse the comma delimited lists of facilities to join the + // name with the address and print it to the serial monitor + if (facilities.length() > 0) { + int i = -1; + int facilityStart = 0; + int addressStart = 0; + String facility; + String address; + do { + i = facilities.indexOf(',', facilityStart); + if (i >= 0) { + facility = facilities.substring(facilityStart, i); + facilityStart = i + 1; + } + + i = addresses.indexOf(',', addressStart); + if (i >= 0) { + address = addresses.substring(addressStart, i); + addressStart = i + 1; + } + + if (i >= 0) { + printResult(facility, address); + } + + }while (i >= 0); + facility = facilities.substring(facilityStart); + address = addresses.substring(addressStart); + printResult(facility, address); + } else { + Serial.println("No facilities found in zip code " + US_ZIP_CODE); + } + } else { + while(FacilitiesSearchByZipChoreo.available()) { + char c = FacilitiesSearchByZipChoreo.read(); + Serial.print(c); + } + } + } + Serial.println("Waiting..."); + Serial.println(""); + delay(30000); // wait 30 seconds between calls +} + +// a simple utility function, to output the facility name and address in the serial monitor. +void printResult(String facility, String address) { + Serial.print(facility); + Serial.print(" - "); + Serial.println(address); +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/TembooAccount.h b/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/TembooAccount.h new file mode 100644 index 0000000..8d7dcfb --- /dev/null +++ b/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/TembooAccount.h @@ -0,0 +1,5 @@ +#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 + + diff --git a/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino b/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino new file mode 100644 index 0000000..dd8cabd --- /dev/null +++ b/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino @@ -0,0 +1,132 @@ +/* + UpdateFacebookStatus + + 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 + + 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 + + In order to run this sketch, you'll need to register an application using + the Facebook dev console at https://developers.facebook.com/apps -- after creating + the app, log in to Temboo and visit https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/ + 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. + + This example assumes basic familiarity with Arduino sketches, and that your Yun + is connected to the Internet. + + Want to use another social API with your Arduino Yun? We've got Twitter, Google+, + Instagram, Tumblr and more 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 a #define statement to specify this value in a .h file. + +// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos +const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx"; + + +int numRuns = 1; // execution count, so this sketch doesn't run forever +int maxRuns = 10; // the max number of times the Facebook SetStatus Choreo should run + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while(!Serial); + Bridge.begin(); +} + +void loop() { + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "..."); + + // Define the status message we want to post on Facebook; since Facebook + // doesn't allow duplicate status messages, we'll include a changing value. + String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!"; + + // define the Process that will be used to call the "temboo" client + TembooChoreo SetStatusChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + SetStatusChoreo.begin(); + + // set Temboo account credentials + SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT); + SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SetStatusChoreo.setAppKey(TEMBOO_APP_KEY); + + // tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus) + SetStatusChoreo.setChoreo("/Library/Facebook/Publishing/SetStatus"); + + // set the required choreo inputs + // see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/ + // for complete details about the inputs for this Choreo + + SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN); + SetStatusChoreo.addInput("Message", statusMsg); + + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SetStatusChoreo.run(); + + // print the response code and API response. + Serial.println("Response code: " + String(returnCode)); + + // 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 + // for information on how to filter this data + while(SetStatusChoreo.available()) { + char c = SetStatusChoreo.read(); + Serial.print(c); + } + + SetStatusChoreo.close(); + } + + Serial.println("Waiting..."); + Serial.println(""); + + delay(30000); // wait 30 seconds between SetStatus calls +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/Temboo/UploadToDropbox/TembooAccount.h b/libraries/Bridge/examples/Temboo/UploadToDropbox/TembooAccount.h new file mode 100644 index 0000000..8d7dcfb --- /dev/null +++ b/libraries/Bridge/examples/Temboo/UploadToDropbox/TembooAccount.h @@ -0,0 +1,5 @@ +#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 + + diff --git a/libraries/Bridge/examples/Temboo/UploadToDropbox/UploadToDropbox.ino b/libraries/Bridge/examples/Temboo/UploadToDropbox/UploadToDropbox.ino new file mode 100644 index 0000000..744dcdb --- /dev/null +++ b/libraries/Bridge/examples/Temboo/UploadToDropbox/UploadToDropbox.ino @@ -0,0 +1,208 @@ +/* + UploadToDropbox + + 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 + + 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 + + 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 + do the following: + + 1. Create a "Dropbox API app" + 2. Select "Files and datastores" + 3. Select "Yes - my app only needs access to the files it creates." + + Once you've created your app, follow the instructions at + 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. + + 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. + +// your Dropbox app key, available on the Dropbox developer console after registering an app +const String DROPBOX_APP_KEY = "xxxxxxxxxx"; + +// your Dropbox app secret, available on the Dropbox developer console after registering an app +const String DROPBOX_APP_SECRET = "xxxxxxxxxx"; + +// your Dropbox access token, which is returned by the FinalizeOAuth Choreo +const String DROPBOX_ACCESS_TOKEN = "xxxxxxxxxx"; + +// your Dropbox access token secret, which is returned by the FinalizeOAuth Choreo +const String DROPBOX_ACCESS_TOKEN_SECRET = "xxxxxxxxxx"; + + +boolean success = false; // a flag to indicate whether we've uploaded the file yet + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while(!Serial); + Bridge.begin(); +} + +void loop() +{ + // only try to upload the file if we haven't already done so + if (!success) { + + Serial.println("Base64 encoding data to upload..."); + + // base64 encode the data to upload + String base64EncodedData = base64Encode("Hello, Arduino!"); + + + Serial.println("Uploading data to Dropbox..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo UploadFileChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + UploadFileChoreo.begin(); + + // set Temboo account credentials + UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT); + UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + UploadFileChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile) + UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile"); + + // set the required choreo inputs + // see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/ + // for complete details about the inputs for this Choreo + + // first specify the name of the file to create/update on Dropbox + UploadFileChoreo.addInput("FileName", "ArduinoTest.txt"); + + // 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" + // if your Dropbox app has full access to your files, specify "dropbox" + UploadFileChoreo.addInput("Root","sandbox"); + + // next, the Base64 encoded file data to upload + UploadFileChoreo.addInput("FileContents", base64EncodedData); + + // finally, the Dropbox OAuth credentials defined above + UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET); + UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN); + UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET); + UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = UploadFileChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! File uploaded!"); + success = true; + } else { + // a non-zero return code means there was an error + Serial.println("Uh-oh! Something went wrong!"); + } + + // print out the full response to the serial monitor in all + // cases, just for debugging + while (UploadFileChoreo.available()) { + char c = UploadFileChoreo.read(); + Serial.print(c); + } + UploadFileChoreo.close(); + + Serial.println("Waiting..."); + } + + delay(30000); // wait 30 seconds between upload attempts +} + + +/* + A utility function to Base64 encode the specified string + by calling a Temboo Utilities Choreo. +*/ +String base64Encode(String toEncode) { + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo Base64EncodeChoreo; + + // invoke the Temboo client + Base64EncodeChoreo.begin(); + + // set Temboo account credentials + Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); + Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode) + 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(); + + // read the value of the output item + String data = Base64EncodeChoreo.readStringUntil('\x1E'); + data.trim(); + + if(name == "Base64EncodedText") { + return data; + } + } +} + +/* + 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. +*/ diff --git a/libraries/Bridge/examples/TemperatureWebPanel/.DS_Store b/libraries/Bridge/examples/TemperatureWebPanel/.DS_Store Binary files differnew file mode 100644 index 0000000..5008ddf --- /dev/null +++ b/libraries/Bridge/examples/TemperatureWebPanel/.DS_Store diff --git a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino new file mode 100644 index 0000000..2149737 --- /dev/null +++ b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino @@ -0,0 +1,121 @@ +/* + Temperature web interface + + This example shows how to serve data from an analog input + via the Arduino Yún's built-in webserver using the Bridge library. + + The circuit: + * TMP36 temperature sensor on analog pin A1 + * SD card attached to SD card slot of the Arduino Yún + + Prepare your SD card with an empty folder in the SD root + named "arduino" and a subfolder of that named "www". + This will ensure that the Yún will create a link + to the SD to the "/mnt/sd" path. + + In this sketch folder is a basic webpage and a copy of zepto.js, a + minimized version of jQuery. When you upload your sketch, these files + will be placed in the /arduino/www/TemperatureWebPanel folder on your SD card. + + You can then go to http://arduino.local/sd/TemperatureWebPanel + to see the output of this sketch. + + You can remove the SD card while the Linux and the + sketch are running but be careful not to remove it while + the system is writing to it. + + created 6 July 2013 + by Tom Igoe + + + This example code is in the public domain. + + */ +#include <Bridge.h> +#include <YunServer.h> +#include <YunClient.h> + +// Listen on default port 5555, the webserver on the Yun +// will forward there all the HTTP requests for us. +YunServer server; +String startString; +long hits = 0; + +void setup() { + Serial.begin(9600); + + // Bridge startup + pinMode(13,OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); + digitalWrite(13, HIGH); + + // using A0 and A2 as vcc and gnd for the TMP36 sensor: + pinMode(A0, OUTPUT); + pinMode(A2, OUTPUT); + digitalWrite(A0, HIGH); + digitalWrite(A2, LOW); + + // Listen for incoming connection only from localhost + // (no one from the external network could connect) + server.listenOnLocalhost(); + server.begin(); + + // get the time that this sketch started: + Process startTime; + startTime.runShellCommand("date"); + while(startTime.available()) { + char c = startTime.read(); + startString += c; + } +} + +void loop() { + // Get clients coming from server + YunClient client = server.accept(); + + // There is a new client? + if (client) { + // read the command + String command = client.readString(); + command.trim(); //kill whitespace + Serial.println(command); + // is "temperature" command? + if (command == "temperature") { + + // get the time from the server: + Process time; + time.runShellCommand("date"); + String timeString = ""; + while(time.available()) { + char c = time.read(); + timeString += c; + } + Serial.println(timeString); + int sensorValue = analogRead(A1); + // convert the reading to millivolts: + float voltage = sensorValue * (5000/ 1024); + // convert the millivolts to temperature celsius: + float temperature = (voltage - 500)/10; + // print the temperature: + client.print("Current time on the Yún: "); + client.println(timeString); + client.print("<br>Current temperature: "); + client.print(temperature); + client.print(" degrees C"); + client.print("<br>This sketch has been running since "); + client.print(startString); + client.print("<br>Hits so far: "); + client.print(hits); + } + + // Close connection and free resources. + client.stop(); + hits++; + } + + delay(50); // Poll every 50ms +} + + + diff --git a/libraries/Bridge/examples/TemperatureWebPanel/www/index.html b/libraries/Bridge/examples/TemperatureWebPanel/www/index.html new file mode 100755 index 0000000..29c2704 --- /dev/null +++ b/libraries/Bridge/examples/TemperatureWebPanel/www/index.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <head> + <script type="text/javascript" src="zepto.min.js"></script> + <script type="text/javascript"> + function refresh() { + $('#content').load('/arduino/temperature'); + } +</script> + + </head> + <body onload="setInterval(refresh, 1000);"> + <span id="content">0</span> + </body> +</html> + diff --git a/libraries/Bridge/examples/TemperatureWebPanel/www/zepto.min.js b/libraries/Bridge/examples/TemperatureWebPanel/www/zepto.min.js new file mode 100755 index 0000000..dbe4e3c --- /dev/null +++ b/libraries/Bridge/examples/TemperatureWebPanel/www/zepto.min.js @@ -0,0 +1,2 @@ +/* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ +(function(a){String.prototype.trim===a&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),Array.prototype.reduce===a&&(Array.prototype.reduce=function(b){if(this===void 0||this===null)throw new TypeError;var c=Object(this),d=c.length>>>0,e=0,f;if(typeof b!="function")throw new TypeError;if(d==0&&arguments.length==1)throw new TypeError;if(arguments.length>=2)f=arguments[1];else do{if(e in c){f=c[e++];break}if(++e>=d)throw new TypeError}while(!0);while(e<d)e in c&&(f=b.call(a,f,c[e],e,c)),e++;return f})})();var Zepto=function(){function E(a){return a==null?String(a):y[z.call(a)]||"object"}function F(a){return E(a)=="function"}function G(a){return a!=null&&a==a.window}function H(a){return a!=null&&a.nodeType==a.DOCUMENT_NODE}function I(a){return E(a)=="object"}function J(a){return I(a)&&!G(a)&&a.__proto__==Object.prototype}function K(a){return a instanceof Array}function L(a){return typeof a.length=="number"}function M(a){return g.call(a,function(a){return a!=null})}function N(a){return a.length>0?c.fn.concat.apply([],a):a}function O(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function P(a){return a in j?j[a]:j[a]=new RegExp("(^|\\s)"+a+"(\\s|$)")}function Q(a,b){return typeof b=="number"&&!l[O(a)]?b+"px":b}function R(a){var b,c;return i[a]||(b=h.createElement(a),h.body.appendChild(b),c=k(b,"").getPropertyValue("display"),b.parentNode.removeChild(b),c=="none"&&(c="block"),i[a]=c),i[a]}function S(a){return"children"in a?f.call(a.children):c.map(a.childNodes,function(a){if(a.nodeType==1)return a})}function T(c,d,e){for(b in d)e&&(J(d[b])||K(d[b]))?(J(d[b])&&!J(c[b])&&(c[b]={}),K(d[b])&&!K(c[b])&&(c[b]=[]),T(c[b],d[b],e)):d[b]!==a&&(c[b]=d[b])}function U(b,d){return d===a?c(b):c(b).filter(d)}function V(a,b,c,d){return F(b)?b.call(a,c,d):b}function W(a,b,c){c==null?a.removeAttribute(b):a.setAttribute(b,c)}function X(b,c){var d=b.className,e=d&&d.baseVal!==a;if(c===a)return e?d.baseVal:d;e?d.baseVal=c:b.className=c}function Y(a){var b;try{return a?a=="true"||(a=="false"?!1:a=="null"?null:isNaN(b=Number(a))?/^[\[\{]/.test(a)?c.parseJSON(a):a:b):a}catch(d){return a}}function Z(a,b){b(a);for(var c in a.childNodes)Z(a.childNodes[c],b)}var a,b,c,d,e=[],f=e.slice,g=e.filter,h=window.document,i={},j={},k=h.defaultView.getComputedStyle,l={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},m=/^\s*<(\w+|!)[^>]*>/,n=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,o=/^(?:body|html)$/i,p=["val","css","html","text","data","width","height","offset"],q=["after","prepend","before","append"],r=h.createElement("table"),s=h.createElement("tr"),t={tr:h.createElement("tbody"),tbody:r,thead:r,tfoot:r,td:s,th:s,"*":h.createElement("div")},u=/complete|loaded|interactive/,v=/^\.([\w-]+)$/,w=/^#([\w-]*)$/,x=/^[\w-]+$/,y={},z=y.toString,A={},B,C,D=h.createElement("div");return A.matches=function(a,b){if(!a||a.nodeType!==1)return!1;var c=a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.matchesSelector;if(c)return c.call(a,b);var d,e=a.parentNode,f=!e;return f&&(e=D).appendChild(a),d=~A.qsa(e,b).indexOf(a),f&&D.removeChild(a),d},B=function(a){return a.replace(/-+(.)?/g,function(a,b){return b?b.toUpperCase():""})},C=function(a){return g.call(a,function(b,c){return a.indexOf(b)==c})},A.fragment=function(b,d,e){b.replace&&(b=b.replace(n,"<$1></$2>")),d===a&&(d=m.test(b)&&RegExp.$1),d in t||(d="*");var g,h,i=t[d];return i.innerHTML=""+b,h=c.each(f.call(i.childNodes),function(){i.removeChild(this)}),J(e)&&(g=c(h),c.each(e,function(a,b){p.indexOf(a)>-1?g[a](b):g.attr(a,b)})),h},A.Z=function(a,b){return a=a||[],a.__proto__=c.fn,a.selector=b||"",a},A.isZ=function(a){return a instanceof A.Z},A.init=function(b,d){if(!b)return A.Z();if(F(b))return c(h).ready(b);if(A.isZ(b))return b;var e;if(K(b))e=M(b);else if(I(b))e=[J(b)?c.extend({},b):b],b=null;else if(m.test(b))e=A.fragment(b.trim(),RegExp.$1,d),b=null;else{if(d!==a)return c(d).find(b);e=A.qsa(h,b)}return A.Z(e,b)},c=function(a,b){return A.init(a,b)},c.extend=function(a){var b,c=f.call(arguments,1);return typeof a=="boolean"&&(b=a,a=c.shift()),c.forEach(function(c){T(a,c,b)}),a},A.qsa=function(a,b){var c;return H(a)&&w.test(b)?(c=a.getElementById(RegExp.$1))?[c]:[]:a.nodeType!==1&&a.nodeType!==9?[]:f.call(v.test(b)?a.getElementsByClassName(RegExp.$1):x.test(b)?a.getElementsByTagName(b):a.querySelectorAll(b))},c.contains=function(a,b){return a!==b&&a.contains(b)},c.type=E,c.isFunction=F,c.isWindow=G,c.isArray=K,c.isPlainObject=J,c.isEmptyObject=function(a){var b;for(b in a)return!1;return!0},c.inArray=function(a,b,c){return e.indexOf.call(b,a,c)},c.camelCase=B,c.trim=function(a){return a.trim()},c.uuid=0,c.support={},c.expr={},c.map=function(a,b){var c,d=[],e,f;if(L(a))for(e=0;e<a.length;e++)c=b(a[e],e),c!=null&&d.push(c);else for(f in a)c=b(a[f],f),c!=null&&d.push(c);return N(d)},c.each=function(a,b){var c,d;if(L(a)){for(c=0;c<a.length;c++)if(b.call(a[c],c,a[c])===!1)return a}else for(d in a)if(b.call(a[d],d,a[d])===!1)return a;return a},c.grep=function(a,b){return g.call(a,b)},window.JSON&&(c.parseJSON=JSON.parse),c.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){y["[object "+b+"]"]=b.toLowerCase()}),c.fn={forEach:e.forEach,reduce:e.reduce,push:e.push,sort:e.sort,indexOf:e.indexOf,concat:e.concat,map:function(a){return c(c.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return c(f.apply(this,arguments))},ready:function(a){return u.test(h.readyState)?a(c):h.addEventListener("DOMContentLoaded",function(){a(c)},!1),this},get:function(b){return b===a?f.call(this):this[b>=0?b:b+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){this.parentNode!=null&&this.parentNode.removeChild(this)})},each:function(a){return e.every.call(this,function(b,c){return a.call(b,c,b)!==!1}),this},filter:function(a){return F(a)?this.not(this.not(a)):c(g.call(this,function(b){return A.matches(b,a)}))},add:function(a,b){return c(C(this.concat(c(a,b))))},is:function(a){return this.length>0&&A.matches(this[0],a)},not:function(b){var d=[];if(F(b)&&b.call!==a)this.each(function(a){b.call(this,a)||d.push(this)});else{var e=typeof b=="string"?this.filter(b):L(b)&&F(b.item)?f.call(b):c(b);this.forEach(function(a){e.indexOf(a)<0&&d.push(a)})}return c(d)},has:function(a){return this.filter(function(){return I(a)?c.contains(this,a):c(this).find(a).size()})},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){var a=this[0];return a&&!I(a)?a:c(a)},last:function(){var a=this[this.length-1];return a&&!I(a)?a:c(a)},find:function(a){var b,d=this;return typeof a=="object"?b=c(a).filter(function(){var a=this;return e.some.call(d,function(b){return c.contains(b,a)})}):this.length==1?b=c(A.qsa(this[0],a)):b=this.map(function(){return A.qsa(this,a)}),b},closest:function(a,b){var d=this[0],e=!1;typeof a=="object"&&(e=c(a));while(d&&!(e?e.indexOf(d)>=0:A.matches(d,a)))d=d!==b&&!H(d)&&d.parentNode;return c(d)},parents:function(a){var b=[],d=this;while(d.length>0)d=c.map(d,function(a){if((a=a.parentNode)&&!H(a)&&b.indexOf(a)<0)return b.push(a),a});return U(b,a)},parent:function(a){return U(C(this.pluck("parentNode")),a)},children:function(a){return U(this.map(function(){return S(this)}),a)},contents:function(){return this.map(function(){return f.call(this.childNodes)})},siblings:function(a){return U(this.map(function(a,b){return g.call(S(b.parentNode),function(a){return a!==b})}),a)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(a){return c.map(this,function(b){return b[a]})},show:function(){return this.each(function(){this.style.display=="none"&&(this.style.display=null),k(this,"").getPropertyValue("display")=="none"&&(this.style.display=R(this.nodeName))})},replaceWith:function(a){return this.before(a).remove()},wrap:function(a){var b=F(a);if(this[0]&&!b)var d=c(a).get(0),e=d.parentNode||this.length>1;return this.each(function(f){c(this).wrapAll(b?a.call(this,f):e?d.cloneNode(!0):d)})},wrapAll:function(a){if(this[0]){c(this[0]).before(a=c(a));var b;while((b=a.children()).length)a=b.first();c(a).append(this)}return this},wrapInner:function(a){var b=F(a);return this.each(function(d){var e=c(this),f=e.contents(),g=b?a.call(this,d):a;f.length?f.wrapAll(g):e.append(g)})},unwrap:function(){return this.parent().each(function(){c(this).replaceWith(c(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(b){return this.each(function(){var d=c(this);(b===a?d.css("display")=="none":b)?d.show():d.hide()})},prev:function(a){return c(this.pluck("previousElementSibling")).filter(a||"*")},next:function(a){return c(this.pluck("nextElementSibling")).filter(a||"*")},html:function(b){return b===a?this.length>0?this[0].innerHTML:null:this.each(function(a){var d=this.innerHTML;c(this).empty().append(V(this,b,a,d))})},text:function(b){return b===a?this.length>0?this[0].textContent:null:this.each(function(){this.textContent=b})},attr:function(c,d){var e;return typeof c=="string"&&d===a?this.length==0||this[0].nodeType!==1?a:c=="value"&&this[0].nodeName=="INPUT"?this.val():!(e=this[0].getAttribute(c))&&c in this[0]?this[0][c]:e:this.each(function(a){if(this.nodeType!==1)return;if(I(c))for(b in c)W(this,b,c[b]);else W(this,c,V(this,d,a,this.getAttribute(c)))})},removeAttr:function(a){return this.each(function(){this.nodeType===1&&W(this,a)})},prop:function(b,c){return c===a?this[0]&&this[0][b]:this.each(function(a){this[b]=V(this,c,a,this[b])})},data:function(b,c){var d=this.attr("data-"+O(b),c);return d!==null?Y(d):a},val:function(b){return b===a?this[0]&&(this[0].multiple?c(this[0]).find("option").filter(function(a){return this.selected}).pluck("value"):this[0].value):this.each(function(a){this.value=V(this,b,a,this.value)})},offset:function(a){if(a)return this.each(function(b){var d=c(this),e=V(this,a,b,d.offset()),f=d.offsetParent().offset(),g={top:e.top-f.top,left:e.left-f.left};d.css("position")=="static"&&(g.position="relative"),d.css(g)});if(this.length==0)return null;var b=this[0].getBoundingClientRect();return{left:b.left+window.pageXOffset,top:b.top+window.pageYOffset,width:Math.round(b.width),height:Math.round(b.height)}},css:function(a,c){if(arguments.length<2&&typeof a=="string")return this[0]&&(this[0].style[B(a)]||k(this[0],"").getPropertyValue(a));var d="";if(E(a)=="string")!c&&c!==0?this.each(function(){this.style.removeProperty(O(a))}):d=O(a)+":"+Q(a,c);else for(b in a)!a[b]&&a[b]!==0?this.each(function(){this.style.removeProperty(O(b))}):d+=O(b)+":"+Q(b,a[b])+";";return this.each(function(){this.style.cssText+=";"+d})},index:function(a){return a?this.indexOf(c(a)[0]):this.parent().children().indexOf(this[0])},hasClass:function(a){return e.some.call(this,function(a){return this.test(X(a))},P(a))},addClass:function(a){return this.each(function(b){d=[];var e=X(this),f=V(this,a,b,e);f.split(/\s+/g).forEach(function(a){c(this).hasClass(a)||d.push(a)},this),d.length&&X(this,e+(e?" ":"")+d.join(" "))})},removeClass:function(b){return this.each(function(c){if(b===a)return X(this,"");d=X(this),V(this,b,c,d).split(/\s+/g).forEach(function(a){d=d.replace(P(a)," ")}),X(this,d.trim())})},toggleClass:function(b,d){return this.each(function(e){var f=c(this),g=V(this,b,e,X(this));g.split(/\s+/g).forEach(function(b){(d===a?!f.hasClass(b):d)?f.addClass(b):f.removeClass(b)})})},scrollTop:function(){if(!this.length)return;return"scrollTop"in this[0]?this[0].scrollTop:this[0].scrollY},position:function(){if(!this.length)return;var a=this[0],b=this.offsetParent(),d=this.offset(),e=o.test(b[0].nodeName)?{top:0,left:0}:b.offset();return d.top-=parseFloat(c(a).css("margin-top"))||0,d.left-=parseFloat(c(a).css("margin-left"))||0,e.top+=parseFloat(c(b[0]).css("border-top-width"))||0,e.left+=parseFloat(c(b[0]).css("border-left-width"))||0,{top:d.top-e.top,left:d.left-e.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||h.body;while(a&&!o.test(a.nodeName)&&c(a).css("position")=="static")a=a.offsetParent;return a})}},c.fn.detach=c.fn.remove,["width","height"].forEach(function(b){c.fn[b]=function(d){var e,f=this[0],g=b.replace(/./,function(a){return a[0].toUpperCase()});return d===a?G(f)?f["inner"+g]:H(f)?f.documentElement["offset"+g]:(e=this.offset())&&e[b]:this.each(function(a){f=c(this),f.css(b,V(this,d,a,f[b]()))})}}),q.forEach(function(a,b){var d=b%2;c.fn[a]=function(){var a,e=c.map(arguments,function(b){return a=E(b),a=="object"||a=="array"||b==null?b:A.fragment(b)}),f,g=this.length>1;return e.length<1?this:this.each(function(a,h){f=d?h:h.parentNode,h=b==0?h.nextSibling:b==1?h.firstChild:b==2?h:null,e.forEach(function(a){if(g)a=a.cloneNode(!0);else if(!f)return c(a).remove();Z(f.insertBefore(a,h),function(a){a.nodeName!=null&&a.nodeName.toUpperCase()==="SCRIPT"&&(!a.type||a.type==="text/javascript")&&!a.src&&window.eval.call(window,a.innerHTML)})})})},c.fn[d?a+"To":"insert"+(b?"Before":"After")]=function(b){return c(b)[a](this),this}}),A.Z.prototype=c.fn,A.uniq=C,A.deserializeValue=Y,c.zepto=A,c}();window.Zepto=Zepto,"$"in window||(window.$=Zepto),function(a){function b(a){var b=this.os={},c=this.browser={},d=a.match(/WebKit\/([\d.]+)/),e=a.match(/(Android)\s+([\d.]+)/),f=a.match(/(iPad).*OS\s([\d_]+)/),g=!f&&a.match(/(iPhone\sOS)\s([\d_]+)/),h=a.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),i=h&&a.match(/TouchPad/),j=a.match(/Kindle\/([\d.]+)/),k=a.match(/Silk\/([\d._]+)/),l=a.match(/(BlackBerry).*Version\/([\d.]+)/),m=a.match(/(BB10).*Version\/([\d.]+)/),n=a.match(/(RIM\sTablet\sOS)\s([\d.]+)/),o=a.match(/PlayBook/),p=a.match(/Chrome\/([\d.]+)/)||a.match(/CriOS\/([\d.]+)/),q=a.match(/Firefox\/([\d.]+)/);if(c.webkit=!!d)c.version=d[1];e&&(b.android=!0,b.version=e[2]),g&&(b.ios=b.iphone=!0,b.version=g[2].replace(/_/g,".")),f&&(b.ios=b.ipad=!0,b.version=f[2].replace(/_/g,".")),h&&(b.webos=!0,b.version=h[2]),i&&(b.touchpad=!0),l&&(b.blackberry=!0,b.version=l[2]),m&&(b.bb10=!0,b.version=m[2]),n&&(b.rimtabletos=!0,b.version=n[2]),o&&(c.playbook=!0),j&&(b.kindle=!0,b.version=j[1]),k&&(c.silk=!0,c.version=k[1]),!k&&b.android&&a.match(/Kindle Fire/)&&(c.silk=!0),p&&(c.chrome=!0,c.version=p[1]),q&&(c.firefox=!0,c.version=q[1]),b.tablet=!!(f||o||e&&!a.match(/Mobile/)||q&&a.match(/Tablet/)),b.phone=!b.tablet&&!!(e||g||h||l||m||p&&a.match(/Android/)||p&&a.match(/CriOS\/([\d.]+)/)||q&&a.match(/Mobile/))}b.call(a,navigator.userAgent),a.__detect=b}(Zepto),function(a){function g(a){return a._zid||(a._zid=d++)}function h(a,b,d,e){b=i(b);if(b.ns)var f=j(b.ns);return(c[g(a)]||[]).filter(function(a){return a&&(!b.e||a.e==b.e)&&(!b.ns||f.test(a.ns))&&(!d||g(a.fn)===g(d))&&(!e||a.sel==e)})}function i(a){var b=(""+a).split(".");return{e:b[0],ns:b.slice(1).sort().join(" ")}}function j(a){return new RegExp("(?:^| )"+a.replace(" "," .* ?")+"(?: |$)")}function k(b,c,d){a.type(b)!="string"?a.each(b,d):b.split(/\s/).forEach(function(a){d(a,c)})}function l(a,b){return a.del&&(a.e=="focus"||a.e=="blur")||!!b}function m(a){return f[a]||a}function n(b,d,e,h,j,n){var o=g(b),p=c[o]||(c[o]=[]);k(d,e,function(c,d){var e=i(c);e.fn=d,e.sel=h,e.e in f&&(d=function(b){var c=b.relatedTarget;if(!c||c!==this&&!a.contains(this,c))return e.fn.apply(this,arguments)}),e.del=j&&j(d,c);var g=e.del||d;e.proxy=function(a){var c=g.apply(b,[a].concat(a.data));return c===!1&&(a.preventDefault(),a.stopPropagation()),c},e.i=p.length,p.push(e),b.addEventListener(m(e.e),e.proxy,l(e,n))})}function o(a,b,d,e,f){var i=g(a);k(b||"",d,function(b,d){h(a,b,d,e).forEach(function(b){delete c[i][b.i],a.removeEventListener(m(b.e),b.proxy,l(b,f))})})}function t(b){var c,d={originalEvent:b};for(c in b)!r.test(c)&&b[c]!==undefined&&(d[c]=b[c]);return a.each(s,function(a,c){d[a]=function(){return this[c]=p,b[a].apply(b,arguments)},d[c]=q}),d}function u(a){if(!("defaultPrevented"in a)){a.defaultPrevented=!1;var b=a.preventDefault;a.preventDefault=function(){this.defaultPrevented=!0,b.call(this)}}}var b=a.zepto.qsa,c={},d=1,e={},f={mouseenter:"mouseover",mouseleave:"mouseout"};e.click=e.mousedown=e.mouseup=e.mousemove="MouseEvents",a.event={add:n,remove:o},a.proxy=function(b,c){if(a.isFunction(b)){var d=function(){return b.apply(c,arguments)};return d._zid=g(b),d}if(typeof c=="string")return a.proxy(b[c],b);throw new TypeError("expected function")},a.fn.bind=function(a,b){return this.each(function(){n(this,a,b)})},a.fn.unbind=function(a,b){return this.each(function(){o(this,a,b)})},a.fn.one=function(a,b){return this.each(function(c,d){n(this,a,b,null,function(a,b){return function(){var c=a.apply(d,arguments);return o(d,b,a),c}})})};var p=function(){return!0},q=function(){return!1},r=/^([A-Z]|layer[XY]$)/,s={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};a.fn.delegate=function(b,c,d){return this.each(function(e,f){n(f,c,d,b,function(c){return function(d){var e,g=a(d.target).closest(b,f).get(0);if(g)return e=a.extend(t(d),{currentTarget:g,liveFired:f}),c.apply(g,[e].concat([].slice.call(arguments,1)))}})})},a.fn.undelegate=function(a,b,c){return this.each(function(){o(this,b,c,a)})},a.fn.live=function(b,c){return a(document.body).delegate(this.selector,b,c),this},a.fn.die=function(b,c){return a(document.body).undelegate(this.selector,b,c),this},a.fn.on=function(b,c,d){return!c||a.isFunction(c)?this.bind(b,c||d):this.delegate(c,b,d)},a.fn.off=function(b,c,d){return!c||a.isFunction(c)?this.unbind(b,c||d):this.undelegate(c,b,d)},a.fn.trigger=function(b,c){if(typeof b=="string"||a.isPlainObject(b))b=a.Event(b);return u(b),b.data=c,this.each(function(){"dispatchEvent"in this&&this.dispatchEvent(b)})},a.fn.triggerHandler=function(b,c){var d,e;return this.each(function(f,g){d=t(typeof b=="string"?a.Event(b):b),d.data=c,d.target=g,a.each(h(g,b.type||b),function(a,b){e=b.proxy(d);if(d.isImmediatePropagationStopped())return!1})}),e},"focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(b){a.fn[b]=function(a){return a?this.bind(b,a):this.trigger(b)}}),["focus","blur"].forEach(function(b){a.fn[b]=function(a){return a?this.bind(b,a):this.each(function(){try{this[b]()}catch(a){}}),this}}),a.Event=function(a,b){typeof a!="string"&&(b=a,a=b.type);var c=document.createEvent(e[a]||"Events"),d=!0;if(b)for(var f in b)f=="bubbles"?d=!!b[f]:c[f]=b[f];return c.initEvent(a,d,!0,null,null,null,null,null,null,null,null,null,null,null,null),c.isDefaultPrevented=function(){return this.defaultPrevented},c}}(Zepto),function($){function triggerAndReturn(a,b,c){var d=$.Event(b);return $(a).trigger(d,c),!d.defaultPrevented}function triggerGlobal(a,b,c,d){if(a.global)return triggerAndReturn(b||document,c,d)}function ajaxStart(a){a.global&&$.active++===0&&triggerGlobal(a,null,"ajaxStart")}function ajaxStop(a){a.global&&!--$.active&&triggerGlobal(a,null,"ajaxStop")}function ajaxBeforeSend(a,b){var c=b.context;if(b.beforeSend.call(c,a,b)===!1||triggerGlobal(b,c,"ajaxBeforeSend",[a,b])===!1)return!1;triggerGlobal(b,c,"ajaxSend",[a,b])}function ajaxSuccess(a,b,c){var d=c.context,e="success";c.success.call(d,a,e,b),triggerGlobal(c,d,"ajaxSuccess",[b,c,a]),ajaxComplete(e,b,c)}function ajaxError(a,b,c,d){var e=d.context;d.error.call(e,c,b,a),triggerGlobal(d,e,"ajaxError",[c,d,a]),ajaxComplete(b,c,d)}function ajaxComplete(a,b,c){var d=c.context;c.complete.call(d,b,a),triggerGlobal(c,d,"ajaxComplete",[b,c]),ajaxStop(c)}function empty(){}function mimeToDataType(a){return a&&(a=a.split(";",2)[0]),a&&(a==htmlType?"html":a==jsonType?"json":scriptTypeRE.test(a)?"script":xmlTypeRE.test(a)&&"xml")||"text"}function appendQuery(a,b){return(a+"&"+b).replace(/[&?]{1,2}/,"?")}function serializeData(a){a.processData&&a.data&&$.type(a.data)!="string"&&(a.data=$.param(a.data,a.traditional)),a.data&&(!a.type||a.type.toUpperCase()=="GET")&&(a.url=appendQuery(a.url,a.data))}function parseArguments(a,b,c,d){var e=!$.isFunction(b);return{url:a,data:e?b:undefined,success:e?$.isFunction(c)?c:undefined:b,dataType:e?d||c:c}}function serialize(a,b,c,d){var e,f=$.isArray(b);$.each(b,function(b,g){e=$.type(g),d&&(b=c?d:d+"["+(f?"":b)+"]"),!d&&f?a.add(g.name,g.value):e=="array"||!c&&e=="object"?serialize(a,g,c,b):a.add(b,g)})}var jsonpID=0,document=window.document,key,name,rscript=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,scriptTypeRE=/^(?:text|application)\/javascript/i,xmlTypeRE=/^(?:text|application)\/xml/i,jsonType="application/json",htmlType="text/html",blankRE=/^\s*$/;$.active=0,$.ajaxJSONP=function(a){if("type"in a){var b="jsonp"+ ++jsonpID,c=document.createElement("script"),d=function(){clearTimeout(g),$(c).remove(),delete window[b]},e=function(c){d();if(!c||c=="timeout")window[b]=empty;ajaxError(null,c||"abort",f,a)},f={abort:e},g;return ajaxBeforeSend(f,a)===!1?(e("abort"),!1):(window[b]=function(b){d(),ajaxSuccess(b,f,a)},c.onerror=function(){e("error")},c.src=a.url.replace(/=\?/,"="+b),$("head").append(c),a.timeout>0&&(g=setTimeout(function(){e("timeout")},a.timeout)),f)}return $.ajax(a)},$.ajaxSettings={type:"GET",beforeSend:empty,success:empty,error:empty,complete:empty,context:null,global:!0,xhr:function(){return new window.XMLHttpRequest},accepts:{script:"text/javascript, application/javascript",json:jsonType,xml:"application/xml, text/xml",html:htmlType,text:"text/plain"},crossDomain:!1,timeout:0,processData:!0,cache:!0},$.ajax=function(options){var settings=$.extend({},options||{});for(key in $.ajaxSettings)settings[key]===undefined&&(settings[key]=$.ajaxSettings[key]);ajaxStart(settings),settings.crossDomain||(settings.crossDomain=/^([\w-]+:)?\/\/([^\/]+)/.test(settings.url)&&RegExp.$2!=window.location.host),settings.url||(settings.url=window.location.toString()),serializeData(settings),settings.cache===!1&&(settings.url=appendQuery(settings.url,"_="+Date.now()));var dataType=settings.dataType,hasPlaceholder=/=\?/.test(settings.url);if(dataType=="jsonp"||hasPlaceholder)return hasPlaceholder||(settings.url=appendQuery(settings.url,"callback=?")),$.ajaxJSONP(settings);var mime=settings.accepts[dataType],baseHeaders={},protocol=/^([\w-]+:)\/\//.test(settings.url)?RegExp.$1:window.location.protocol,xhr=settings.xhr(),abortTimeout;settings.crossDomain||(baseHeaders["X-Requested-With"]="XMLHttpRequest"),mime&&(baseHeaders.Accept=mime,mime.indexOf(",")>-1&&(mime=mime.split(",",2)[0]),xhr.overrideMimeType&&xhr.overrideMimeType(mime));if(settings.contentType||settings.contentType!==!1&&settings.data&&settings.type.toUpperCase()!="GET")baseHeaders["Content-Type"]=settings.contentType||"application/x-www-form-urlencoded";settings.headers=$.extend(baseHeaders,settings.headers||{}),xhr.onreadystatechange=function(){if(xhr.readyState==4){xhr.onreadystatechange=empty,clearTimeout(abortTimeout);var result,error=!1;if(xhr.status>=200&&xhr.status<300||xhr.status==304||xhr.status==0&&protocol=="file:"){dataType=dataType||mimeToDataType(xhr.getResponseHeader("content-type")),result=xhr.responseText;try{dataType=="script"?(1,eval)(result):dataType=="xml"?result=xhr.responseXML:dataType=="json"&&(result=blankRE.test(result)?null:$.parseJSON(result))}catch(e){error=e}error?ajaxError(error,"parsererror",xhr,settings):ajaxSuccess(result,xhr,settings)}else ajaxError(null,xhr.status?"error":"abort",xhr,settings)}};var async="async"in settings?settings.async:!0;xhr.open(settings.type,settings.url,async);for(name in settings.headers)xhr.setRequestHeader(name,settings.headers[name]);return ajaxBeforeSend(xhr,settings)===!1?(xhr.abort(),!1):(settings.timeout>0&&(abortTimeout=setTimeout(function(){xhr.onreadystatechange=empty,xhr.abort(),ajaxError(null,"timeout",xhr,settings)},settings.timeout)),xhr.send(settings.data?settings.data:null),xhr)},$.get=function(a,b,c,d){return $.ajax(parseArguments.apply(null,arguments))},$.post=function(a,b,c,d){var e=parseArguments.apply(null,arguments);return e.type="POST",$.ajax(e)},$.getJSON=function(a,b,c){var d=parseArguments.apply(null,arguments);return d.dataType="json",$.ajax(d)},$.fn.load=function(a,b,c){if(!this.length)return this;var d=this,e=a.split(/\s/),f,g=parseArguments(a,b,c),h=g.success;return e.length>1&&(g.url=e[0],f=e[1]),g.success=function(a){d.html(f?$("<div>").html(a.replace(rscript,"")).find(f):a),h&&h.apply(d,arguments)},$.ajax(g),this};var escape=encodeURIComponent;$.param=function(a,b){var c=[];return c.add=function(a,b){this.push(escape(a)+"="+escape(b))},serialize(c,a,b),c.join("&").replace(/%20/g,"+")}}(Zepto),function(a){a.fn.serializeArray=function(){var b=[],c;return a(Array.prototype.slice.call(this.get(0).elements)).each(function(){c=a(this);var d=c.attr("type");this.nodeName.toLowerCase()!="fieldset"&&!this.disabled&&d!="submit"&&d!="reset"&&d!="button"&&(d!="radio"&&d!="checkbox"||this.checked)&&b.push({name:c.attr("name"),value:c.val()})}),b},a.fn.serialize=function(){var a=[];return this.serializeArray().forEach(function(b){a.push(encodeURIComponent(b.name)+"="+encodeURIComponent(b.value))}),a.join("&")},a.fn.submit=function(b){if(b)this.bind("submit",b);else if(this.length){var c=a.Event("submit");this.eq(0).trigger(c),c.defaultPrevented||this.get(0).submit()}return this}}(Zepto),function(a,b){function s(a){return t(a.replace(/([a-z])([A-Z])/,"$1-$2"))}function t(a){return a.toLowerCase()}function u(a){return d?d+a:t(a)}var c="",d,e,f,g={Webkit:"webkit",Moz:"",O:"o",ms:"MS"},h=window.document,i=h.createElement("div"),j=/^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i,k,l,m,n,o,p,q,r={};a.each(g,function(a,e){if(i.style[a+"TransitionProperty"]!==b)return c="-"+t(a)+"-",d=e,!1}),k=c+"transform",r[l=c+"transition-property"]=r[m=c+"transition-duration"]=r[n=c+"transition-timing-function"]=r[o=c+"animation-name"]=r[p=c+"animation-duration"]=r[q=c+"animation-timing-function"]="",a.fx={off:d===b&&i.style.transitionProperty===b,speeds:{_default:400,fast:200,slow:600},cssPrefix:c,transitionEnd:u("TransitionEnd"),animationEnd:u("AnimationEnd")},a.fn.animate=function(b,c,d,e){return a.isPlainObject(c)&&(d=c.easing,e=c.complete,c=c.duration),c&&(c=(typeof c=="number"?c:a.fx.speeds[c]||a.fx.speeds._default)/1e3),this.anim(b,c,d,e)},a.fn.anim=function(c,d,e,f){var g,h={},i,t="",u=this,v,w=a.fx.transitionEnd;d===b&&(d=.4),a.fx.off&&(d=0);if(typeof c=="string")h[o]=c,h[p]=d+"s",h[q]=e||"linear",w=a.fx.animationEnd;else{i=[];for(g in c)j.test(g)?t+=g+"("+c[g]+") ":(h[g]=c[g],i.push(s(g)));t&&(h[k]=t,i.push(k)),d>0&&typeof c=="object"&&(h[l]=i.join(", "),h[m]=d+"s",h[n]=e||"linear")}return v=function(b){if(typeof b!="undefined"){if(b.target!==b.currentTarget)return;a(b.target).unbind(w,v)}a(this).css(r),f&&f.call(this)},d>0&&this.bind(w,v),this.size()&&this.get(0).clientLeft,this.css(h),d<=0&&setTimeout(function(){u.each(function(){v.call(this)})},0),this},i=null}(Zepto) diff --git a/libraries/Bridge/examples/TimeCheck/TimeCheck.ino b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino new file mode 100644 index 0000000..848ff25 --- /dev/null +++ b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino @@ -0,0 +1,82 @@ + +/* + Time Check + + Gets the time from the linino processor via Bridge + then parses out hours, minutes and seconds for the Arduino + using an Arduino Yún. + + created 27 May 2013 + modified 21 June 2013 + By Tom Igoe + + This example code is in the public domain. + + */ + + +#include <Process.h> + +Process date; // process used to get the date +int hours, minutes, seconds; // for the results +int lastSecond = -1; // need an impossible value for comparison + +void setup() { + Bridge.begin(); // initialize Bridge + Serial.begin(9600); // initialize serial + + while(!Serial); // wait for Serial Monitor to open + Serial.println("Time Check"); // Title of sketch + + // run an initial date process. Should return: + // hh:mm:ss : + if (!date.running()) { + date.begin("date"); + date.addParameter("+%T"); + date.run(); + } +} + +void loop() { + + if(lastSecond != seconds) { // if a second has passed + // print the time: + if (hours <= 9) Serial.print("0"); // adjust for 0-9 + Serial.print(hours); + Serial.print(":"); + if (minutes <= 9) Serial.print("0"); // adjust for 0-9 + Serial.print(minutes); + Serial.print(":"); + if (seconds <= 9) Serial.print("0"); // adjust for 0-9 + Serial.println(seconds); + + // restart the date process: + if (!date.running()) { + date.begin("date"); + date.addParameter("+%T"); + date.run(); + } + } + + //if there's a result from the date process, parse it: + while (date.available()>0) { + // get the result of the date process (should be hh:mm:ss): + String timeString = date.readString(); + + // find the colons: + int firstColon = timeString.indexOf(":"); + int secondColon= timeString.lastIndexOf(":"); + + // get the substrings for hour, minute second: + String hourString = timeString.substring(0, firstColon); + String minString = timeString.substring(firstColon+1, secondColon); + String secString = timeString.substring(secondColon+1); + + // convert to ints,saving the previous second: + hours = hourString.toInt(); + minutes = minString.toInt(); + lastSecond = seconds; // save to do a time comparison + seconds = secString.toInt(); + } + +} diff --git a/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino b/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino new file mode 100644 index 0000000..5921b70 --- /dev/null +++ b/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino @@ -0,0 +1,50 @@ + +/* + WiFi Status + + This sketch runs a script called "pretty-wifi-info.lua" + installed on your Yún in folder /usr/bin. + It prints information about the status of your wifi connection. + + It uses Serial to print, so you need to connect your Yún to your + computer using a USB cable and select the appropriate port from + the Port menu + + created 18 June 2013 + By Federico Fissore + + This example code is in the public domain. + */ + +#include <Process.h> + +void setup() { + Serial.begin(9600); // initialize serial communication + while(!Serial); // do nothing until the serial monitor is opened + + Serial.println("Starting bridge...\n"); + pinMode(13,OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); // make contact with the linux processor + digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready + + delay(2000); // wait 2 seconds +} + +void loop() { + Process wifiCheck; // initialize a new process + + wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua"); // command you want to run + + // while there's any characters coming back from the + // process, print them to the serial monitor: + while (wifiCheck.available() > 0) { + char c = wifiCheck.read(); + Serial.print(c); + } + + Serial.println(); + + delay(5000); +} + diff --git a/libraries/Bridge/examples/XivelyClient/XivelyClient.ino b/libraries/Bridge/examples/XivelyClient/XivelyClient.ino new file mode 100644 index 0000000..69f979c --- /dev/null +++ b/libraries/Bridge/examples/XivelyClient/XivelyClient.ino @@ -0,0 +1,110 @@ +/* + Xively sensor client with Strings + + This sketch connects an analog sensor to Xively, + using an Arduino Yún. + + created 15 March 2010 + updated 27 May 2013 + by Tom Igoe + + */ + +// include all Libraries needed: +#include <Process.h> +#include "passwords.h" // contains my passwords, see below + +/* + NOTE: passwords.h is not included with this repo because it contains my passwords. + You need to create it for your own version of this application. To do so, make + a new tab in Arduino, call it passwords.h, and include the following variables and constants: + + #define APIKEY "foo" // replace your pachube api key here + #define FEEDID 0000 // replace your feed ID + #define USERAGENT "my-project" // user agent is the project name + */ + + +// set up net client info: +const unsigned long postingInterval = 60000; //delay between updates to xively.com +unsigned long lastRequest = 0; // when you last made a request +String dataString = ""; + +void setup() { + // start serial port: + Bridge.begin(); + Serial.begin(9600); + + while(!Serial); // wait for Network Serial to open + Serial.println("Xively client"); + + // Do a first update immediately + updateData(); + sendData(); + lastRequest = millis(); +} + +void loop() { + // get a timestamp so you can calculate reading and sending intervals: + long now = millis(); + + // if the sending interval has passed since your + // last connection, then connect again and send data: + if (now - lastRequest >= postingInterval) { + updateData(); + sendData(); + lastRequest = now; + } +} + +void updateData() { + // convert the readings to a String to send it: + dataString = "Temperature,"; + dataString += random(10) + 20; + // add pressure: + dataString += "\nPressure,"; + dataString += random(5) + 100; +} + +// this method makes a HTTP connection to the server: +void sendData() { + // form the string for the API header parameter: + String apiString = "X-ApiKey: "; + apiString += APIKEY; + + // form the string for the URL parameter: + String url = "https://api.xively.com/v2/feeds/"; + url += FEEDID; + url += ".csv"; + + // Send the HTTP PUT request + + // Is better to declare the Process here, so when the + // sendData function finishes the resources are immediately + // released. Declaring it global works too, BTW. + Process xively; + Serial.print("\n\nSending data... "); + xively.begin("curl"); + xively.addParameter("-k"); + xively.addParameter("--request"); + xively.addParameter("PUT"); + xively.addParameter("--data"); + xively.addParameter(dataString); + xively.addParameter("--header"); + xively.addParameter(apiString); + xively.addParameter(url); + xively.run(); + Serial.println("done!"); + + // If there's incoming data from the net connection, + // send it out the Serial: + while (xively.available()>0) { + char c = xively.read(); + Serial.write(c); + } + +} + + + + diff --git a/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino new file mode 100644 index 0000000..faffd93 --- /dev/null +++ b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino @@ -0,0 +1,78 @@ +/* + Arduino Yun USB-to-Serial + + Allows you to use the Yun's 32U4 processor as a + serial terminal for the linino processor. + + Upload this to an Arduino Yun via serial (not WiFi) + then open the serial monitor at 115200 to see the boot process + of the linino processor. You can also use the serial monitor + as a basic command line interface for the linino processor using + this sketch. + + From the serial monitor the following commands can be issued: + + '~' followed by '0' -> Set the UART speed to 57600 baud + '~' followed by '1' -> Set the UART speed to 115200 baud + '~' followed by '2' -> Set the UART speed to 250000 baud + '~' followed by '3' -> Set the UART speed to 500000 baud + '~' followeb by '~' -> Sends the bridge's shutdown command to + obtain the console. + + The circuit: + * Arduino Yun + + created March 2013 + by Massimo Banzi + modified by Cristian Maglie + + This example code is in the public domain. + */ + +long lininoBaud = 250000; + +void setup() { + Serial.begin(115200); // open serial connection via USB-Serial + Serial1.begin(lininoBaud); // open serial connection to Linino +} + +boolean commandMode = false; + +void loop() { + // copy from virtual serial line to uart and vice versa + if (Serial.available()) { // got anything from USB-Serial? + char c = (char)Serial.read(); // read from USB-serial + if (commandMode == false) { // if we aren't in command mode... + if (c == '~') { // Tilde '~' key pressed? + commandMode = true; // enter in command mode + } else { + Serial1.write(c); // otherwise write char to Linino + } + } else { // if we are in command mode... + if (c == '0') { // '0' key pressed? + Serial1.begin(57600); // set speed to 57600 + Serial.println("Speed set to 57600"); + } else if (c == '1') { // '1' key pressed? + Serial1.begin(115200); // set speed to 115200 + Serial.println("Speed set to 115200"); + } else if (c == '2') { // '2' key pressed? + Serial1.begin(250000); // set speed to 250000 + Serial.println("Speed set to 250000"); + } else if (c == '3') { // '3' key pressed? + Serial1.begin(500000); // set speed to 500000 + Serial.println("Speed set to 500000"); + } else if (c == '~') { + Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x0d\xaf", 11); + Serial.println("Sending bridge's shutdown command"); + } else { // any other key pressed? + Serial1.write('~'); // write '~' to Linino + Serial1.write(c); // write char to Linino + } + commandMode = false; // in all cases exit from command mode + } + } + if (Serial1.available()) { // got anything from Linino? + char c = (char)Serial1.read(); // read from Linino + Serial.write(c); // write to USB-serial + } +}
\ No newline at end of file |