Hardware Reference
In-Depth Information
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);
}
}
void loop() {
int lightValue = analogRead(lightPin);
datastreams[0].setFloat(lightValue);
Serial.print("Read light value ");
Serial.println(datastreams[0].getFloat());
int tempValue = analogRead(tempPin);
datastreams[1].setFloat(tempValue);
Serial.print("Read temp value ");
Serial.println(datastreams[1].getFloat());
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(15000);
First, note that all previous references to sensor have been updated to light .
Now that you are transmitting information from two sensors, it is good coding
practice to differentiate between them properly. A tempId[] data stream was
added and inserted into the datastreams[] object. The XivelyFeed object defi-
nition was updated to indicate that there are now two datastreams instead of
one. Within the loop() , the lines that were previously printing sensor informa-
tion about the light sensor have been duplicated to print the same information
about the temperature sensor. Note that the light information is listed first in
the datastreams object, so it is referenced as datastreams[0] . The temperature
information is listed second in the datastreams object, so it is referenced as
datastreams[1] .
When you run this code on your Arduino, the web interface automatically
updates itself to reflect your new datastreams. You might want to delete your
old sensor_reading datastream, as light_reading is now being updated
instead. After several minutes of updates, your graphs should look something
like FigureĀ 14-11.
Search WWH ::




Custom Search