//////////////////////// WiFi Definitions ////////////////////////const char WiFiSSID[] = "WiFi_Network";
const char WiFiPSK[] = "WiFi_Password";
/////////////////////// Pin Definitions ///////////////////////const int LED_PIN = 5; // Thing's onboard, green LEDconst int
ANALOG_PIN = A0; // The only analog pin on the Thingconst int DIGITAL_PIN = 12; // Digital pin to be read
////////////////// Phant Keys //////////////////const char PhantHost[] = "data.sparkfun.com";
const char PublicKey[] = "wpvZ9pE1qbFJAjaGd3bn";
const char PrivateKey[] = "wzeB1z0xWNt1YJX27xdg";
// Time to sleep (in seconds):const int sleepTimeS = 30;
void setup()
{
initHardware();
connectWiFi();
digitalWrite(LED_PIN, HIGH);
while (postToPhant() != 1)
{
delay(100);
}
digitalWrite(LED_PIN, LOW);
// deepSleep time is defined in microseconds. Multiply
// seconds by 1e6
ESP.deepSleep(sleepTimeS * 1000000);
}
void loop()
{
}
void connectWiFi()
{
byte ledStatus = LOW;
// Set WiFi mode to station (as opposed to AP or AP_STA)
WiFi.mode(WIFI_STA);
// WiFI.begin([ssid], [passkey]) initiates a WiFI connection
// to the stated [ssid], using the [passkey] as a WPA, WPA2,
// or WEP passphrase.
WiFi.begin(WiFiSSID, WiFiPSK);
// Use the WiFi.status() function to check if the ESP8266
// is connected to a WiFi network.
while (WiFi.status() != WL_CONNECTED)
{
// Blink the LED
digitalWrite(LED_PIN, ledStatus); // Write LED high/low
ledStatus = (ledStatus == HIGH) ? LOW : HIGH;
// Delays allow the ESP8266 to perform critical tasks
// defined outside of the sketch. These tasks include
// setting up, and maintaining, a WiFi connection.
delay(100);
// Potentially infinite loops are generally dangerous.
// Add delays -- allowing the processor to perform other
// tasks -- wherever possible.
}