Skip to content

Commit 5d06e4e

Browse files
author
brentru
committed
adding ESP8266 DeepSleep Example
1 parent f1d9f08 commit 5d06e4e

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

examples/adafruitio_18_device_info/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// visit io.adafruit.com if you need to create an account,
44
// or if you need your Adafruit IO key.
5-
#define IO_USERNAME "your_username"
6-
#define IO_KEY "your_key"
5+
#define IO_USERNAME "AIO_USERNAME"
6+
#define IO_KEY "AIO_KEY"
77

88
/******************************* WIFI **************************************/
99

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Adafruit IO DeepSleep Example (HUZZAH8266)
2+
//
3+
// Adafruit invests time and resources providing this open source code.
4+
// Please support Adafruit and open source hardware by purchasing
5+
// products from Adafruit!
6+
//
7+
// Written by Brent Rubell for Adafruit Industries
8+
// Copyright (c) 2018 Adafruit Industries
9+
// Licensed under the MIT license.
10+
//
11+
// All text above must be included in any redistribution.
12+
13+
/************************** Configuration ***********************************/
14+
15+
// edit the config.h tab and enter your Adafruit IO credentials
16+
// and any additional configuration needed for WiFi, cellular,
17+
// or ethernet clients.
18+
#include "config.h"
19+
20+
/************************ Example Starts Here *******************************/
21+
#define DEEPSLEEP_DURATION 20e4
22+
23+
void setup() {
24+
// start the serial connection
25+
Serial.begin(115200);
26+
27+
// wait for serial monitor to open
28+
while (!Serial);
29+
Serial.println("Adafruit IO + DeepSleep");
30+
31+
// connect to the Adafruit IO Library
32+
connectAIO();
33+
34+
// set up and write to deepsleep feed
35+
feedWrite();
36+
37+
// let's go back to sleep for DEEPSLEEP_DURATION seconds...
38+
Serial.println("sleeping...");
39+
// Put the Huzzah into deepsleep for DEEPSLEEP_DURATION
40+
// NOTE: Make sure Pin 16 is connected to
41+
ESP.deepSleep(DEEPSLEEP_DURATION);
42+
}
43+
44+
// NOOP
45+
void loop() {
46+
}
47+
48+
49+
void feedWrite(){
50+
// set up `deepsleep` feed
51+
AdafruitIO_Feed *deepsleep = io.feed("deepsleep");
52+
Serial.println("sending value to feed 'deepsleep");
53+
// send data to deepsleep feed
54+
deepsleep->save(1);
55+
// write data to AIO
56+
io.run();
57+
}
58+
void connectAIO() {
59+
Serial.println("Connecting to Adafruit IO...");
60+
io.connect();
61+
62+
// wait for a connection
63+
while (io.status() < AIO_CONNECTED) {
64+
Serial.print(".");
65+
delay(500);
66+
}
67+
68+
// we are connected
69+
Serial.println();
70+
Serial.println(io.statusText());
71+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/************************ Adafruit IO Config *******************************/
2+
3+
// visit io.adafruit.com if you need to create an account,
4+
// or if you need your Adafruit IO key.
5+
#define IO_USERNAME "your_username"
6+
#define IO_KEY "your_key"
7+
8+
/******************************* WIFI **************************************/
9+
10+
// the AdafruitIO_WiFi client will work with the following boards:
11+
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
12+
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
13+
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
14+
// - Feather WICED -> https://www.adafruit.com/products/3056
15+
16+
#define WIFI_SSID "your_ssid"
17+
#define WIFI_PASS "your_pass"
18+
19+
// comment out the following two lines if you are using fona or ethernet
20+
#include "AdafruitIO_WiFi.h"
21+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
22+
23+
24+
/******************************* FONA **************************************/
25+
26+
// the AdafruitIO_FONA client will work with the following boards:
27+
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
28+
29+
// uncomment the following two lines for 32u4 FONA,
30+
// and comment out the AdafruitIO_WiFi client in the WIFI section
31+
// #include "AdafruitIO_FONA.h"
32+
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
33+
34+
35+
/**************************** ETHERNET ************************************/
36+
37+
// the AdafruitIO_Ethernet client will work with the following boards:
38+
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
39+
40+
// uncomment the following two lines for ethernet,
41+
// and comment out the AdafruitIO_WiFi client in the WIFI section
42+
// #include "AdafruitIO_Ethernet.h"
43+
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

0 commit comments

Comments
 (0)