Hardware Reference
In-Depth Information
Sending power consumption data to Xively
Let's now build the sketch that will upload the power measurement data to Xively. The
sketch is based on a test sketch, so I will only detail the new parts. We will now go through
the most important parts of the code for this section. To get the complete code, please refer
to the GitHub repository of this chapter.
It starts by importing the correct libraries:
#include <Adafruit_CC3000.h>
#include <SPI.h>
We then need to define the pins of the CC3000 chip:
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
After that, we need to declare the CC3000 instance:
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
Now, this is the part where you need to enter your information. First, you enter the SSID
and the password of your local Wi-Fi network:
#define WLAN_SSID "yourSSID"
#define WLAN_PASS "yourPassword"
#define WLAN_SECURITY WLAN_SEC_WPA2
We now have to enter the API key and the feed ID of your Xively device:
#define API_key "yourAPIKey"
#define feedID "yourFeedID"
In the setup() part of the sketch, we need to start the CC3000 chip:
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
Search WWH ::




Custom Search