Hardware Reference
In-Depth Information
String((int)humidity) + "\"}]}";
Serial.println(data);
length = data.length();
You will note that we also get the length of the string that we will also need in order to
send the data to the Xively server. Also, we are using backslashes before quotations marks
to indicate that we want to transmit quotation marks and not the end of the string.
Then, we will actually connect to the Xively server and send the data. This is done by us-
ing a PUT request and sending a JSON file to the Xively server. In the header of the re-
quest, we define the feed ID of the Xively device and we also transmit your Xively API
key.
We also need to send the data we defined before in the body of the request. This is done
using the following piece of code:
if (client.connect(server, 80)) {
if (client.connected()) {
Serial.println("connected");
client.println("PUT /v2/feeds/" + String(feedID) +
".json HTTP/1.1");
client.println("Host: api.xively.com");
client.println("X-ApiKey: " + String(API_key));
client.println("Content-Length: " + String(length));
client.print("Connection: close");
client.println();
client.print(data);
client.println();
} else {
Serial.println(F("Connection failed"));
return;
}
Then, after the data is sent, we read back the data coming from the server and print the an-
swer on the Serial Monitor for debugging purposes, using the following piece of code:
while (client.connected()) {
while (client.available()) {
char c = client.read();
Serial.print(c);
Search WWH ::




Custom Search