]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/xively/examples/DatastreamDownload/DatastreamDownload.ino
first commit
[arduino] / books / pdummies / Libraries / xively / examples / DatastreamDownload / DatastreamDownload.ino
1 #include <SPI.h>
2 #include <Ethernet.h>
3 #include <HttpClient.h>
4 #include <Xively.h>
5
6 // MAC address for your Ethernet shield
7 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
8
9 // Your Xively key to let you upload data
10 char xivelyKey[] = "YOUR_XIVELY_API_KEY";
11
12 // Define the string for our datastream ID
13 char temperatureId[] = "temperature";
14
15 XivelyDatastream datastreams[] = {
16   XivelyDatastream(temperatureId, strlen(temperatureId), DATASTREAM_FLOAT),
17 };
18 // Finally, wrap the datastreams into a feed
19 XivelyFeed feed(15552, datastreams, 1 /* number of datastreams */);
20
21 EthernetClient client;
22 XivelyClient xivelyclient(client);
23
24 void setup() {
25   // put your setup code here, to run once:
26   Serial.begin(9600);
27   
28   Serial.println("Reading from Xively example");
29   Serial.println();
30
31   while (Ethernet.begin(mac) != 1)
32   {
33     Serial.println("Error getting IP address via DHCP, trying again...");
34     delay(15000);
35   }
36 }
37
38 void loop() {
39   int ret = xivelyclient.get(feed, xivelyKey);
40   Serial.print("xivelyclient.get returned ");
41   Serial.println(ret);
42
43   if (ret > 0)
44   {
45     Serial.println("Datastream is...");
46     Serial.println(feed[0]);
47
48     Serial.print("Temperature is: ");
49     Serial.println(feed[0].getFloat());
50   }
51
52   Serial.println();
53   delay(15000UL);
54 }
55