3 #include <HttpClient.h>
6 char ssid[] = "YourNetwork"; // your network SSID (name)
7 char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
8 int keyIndex = 0; // your network key Index number (needed only for WEP)
10 int status = WL_IDLE_STATUS;
12 // Your Xively key to let you upload data
13 char xivelyKey[] = "YOUR_API_KEY";
15 // Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
18 // Define the strings for our datastream IDs
19 char sensorId[] = "sensor_reading";
20 char bufferId[] = "info_message";
21 String stringId("random_string");
22 const int bufferSize = 140;
23 char bufferValue[bufferSize]; // enough space to store the string we're going to send
24 XivelyDatastream datastreams[] = {
25 XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
26 XivelyDatastream(bufferId, strlen(bufferId), DATASTREAM_BUFFER, bufferValue, bufferSize),
27 XivelyDatastream(stringId, DATASTREAM_STRING)
29 // Finally, wrap the datastreams into a feed
30 XivelyFeed feed(15552, datastreams, 3 /* number of datastreams */);
33 XivelyClient xivelyclient(client);
35 void printWifiStatus() {
36 // print the SSID of the network you're attached to:
37 Serial.print("SSID: ");
38 Serial.println(WiFi.SSID());
40 // print your WiFi shield's IP address:
41 IPAddress ip = WiFi.localIP();
42 Serial.print("IP Address: ");
45 // print the received signal strength:
46 long rssi = WiFi.RSSI();
47 Serial.print("signal strength (RSSI):");
49 Serial.println(" dBm");
53 // put your setup code here, to run once:
56 Serial.println("Starting multiple datastream upload to Xively...");
59 // attempt to connect to Wifi network:
60 while ( status != WL_CONNECTED) {
61 Serial.print("Attempting to connect to SSID: ");
63 status = WiFi.begin(ssid, pass);
64 // wait 10 seconds for connection:
67 Serial.println("Connected to wifi");
72 int sensorValue = analogRead(sensorPin);
73 datastreams[0].setFloat(sensorValue);
75 Serial.print("Read sensor value ");
76 Serial.println(datastreams[0].getFloat());
78 datastreams[1].setBuffer("a message to upload");
79 Serial.print("Setting buffer value to:\n ");
80 Serial.println(datastreams[1].getBuffer());
82 // Pick a random number to send up in a string
83 String stringValue(random(100));
84 stringValue += " is a random number";
85 datastreams[2].setString(stringValue);
86 Serial.print("Setting string value to:\n ");
87 Serial.println(datastreams[2].getString());
89 Serial.println("Uploading it to Xively");
90 int ret = xivelyclient.put(feed, xivelyKey);
91 Serial.print("xivelyclient.put returned ");