aboutsummaryrefslogtreecommitdiff
path: root/libraries/Bridge/examples/XivelyClient/XivelyClient.ino
diff options
context:
space:
mode:
authorFede85 <f.vanzati@gmail.com>2013-09-06 15:38:07 +0200
committerFede85 <f.vanzati@gmail.com>2013-09-06 15:38:07 +0200
commita3e2e68e2b7edb9f5434734bed4001df1e65451c (patch)
treed4ef938bd8179a15d41b19197c51ca0a7f93936f /libraries/Bridge/examples/XivelyClient/XivelyClient.ino
parent35f10e412f5d00027f9d7f2036243c681dbec406 (diff)
Bridge library to the 1.5 format
Diffstat (limited to 'libraries/Bridge/examples/XivelyClient/XivelyClient.ino')
-rw-r--r--libraries/Bridge/examples/XivelyClient/XivelyClient.ino110
1 files changed, 0 insertions, 110 deletions
diff --git a/libraries/Bridge/examples/XivelyClient/XivelyClient.ino b/libraries/Bridge/examples/XivelyClient/XivelyClient.ino
deleted file mode 100644
index 69f979c..0000000
--- a/libraries/Bridge/examples/XivelyClient/XivelyClient.ino
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- 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);
- }
-
-}
-
-
-
-