Hardware Reference
In-Depth Information
while(1);
}
In the loop() function of the sketch, we need to connect the CC3000 chip to your net-
work:
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
Then, we define the IP of the Xively server:
uint32_t ip = cc3000.IP2U32(216,52,233,120);
Then, we need to format the data. This is all defined inside the Xively documentation; that
said, you have to format data inside a JSON container:
int length = 0;
String data = "";
data = data + "\n" +
"{\"version\":\"1.0.0\",\"datastreams\" : [ {\"id\" :
\"Current\",\"current_value\" : \"" +
String((int)effective_value) + "\"}," + "{\"id\" :
\"Power\",\"current_value\" : \"" +
String((int)effective_power) + "\"}]}";
Serial.println(data);
length = data.length();
Once we have the data formatted in a string, we can send it to the Xively server along
with the API key:
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 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);
Search WWH ::




Custom Search