Hardware Reference
In-Depth Information
the code everywhere you see the first datastream. You may also choose to rename
to the datastream IDs to something more understandable, like light_reading
and temp_reading . The code in Listing 14-4 should resemble the code you used
before, but is now writing two datastreams. Note that you still need to enter
in your API key, Feed ID, and MAC address from your previous program into
this code; otherwise, it will not work.
Listing 14-4: Xively Datastream Upload Code Updated to Read Multiple Sensors—
xively2.ino
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
// MAC address for your Ethernet shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x4A, 0xE0 };
// Your Xively key to let you upload data
char xivelyKey[] = "qkjXS1oUKqbCG-hqh3fw4WIsdvOSAKx4ZXZYSWhGUWdxcz0g";
// Analog pin which we're monitoring (0 and 1 are used by the
// Ethernet shield)
int lightPin = 2; //Temperature sensor
int tempPin = 3; //Light sensor
// Define the strings for our datastream IDs
char lightId[] = "light_reading";
char tempId[] = "temp_reading";
XivelyDatastream datastreams[] = {
XivelyDatastream(lightId, strlen(lightId), DATASTREAM_FLOAT),
XivelyDatastream(tempId, strlen(tempId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(1242622121, datastreams, 2 /* number of datastreams */);
EthernetClient client;
XivelyClient xivelyclient(client);
void setup() {
// Put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Starting double datastream upload to Xively...");
Serial.println();
while (Ethernet.begin(mac) != 1)
Search WWH ::




Custom Search