Skip to content

Commit 0c1ac69

Browse files
committed
add basic_publish example
1 parent 73fa37b commit 0c1ac69

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// Adafruit IO Basic Publish Example
3+
//
4+
// ▄████
5+
// ▄███████
6+
// █████████▌
7+
// ███████████
8+
// ████████████▌
9+
// ███████████████▄ ████████████▌
10+
// █████████████████████▀▀█████ ▄▄▄▄▄▄▄
11+
// ▐██████████████████ █████████████████▄▄
12+
// ▀█████████ ▀▀███ ██████████████████████
13+
// █████████▄▄ ▐████▀ ▐█████████████▀
14+
// ▀▀███████████████▄▄█████████████▀
15+
// ▄███████ ██ ▀████████████▀
16+
// ███████▀ ▄████ ▐█████▄
17+
// █████████████████▄▄██████▄
18+
// ███████████████████████████
19+
// ██████████████ ▐████████████▌
20+
// ▐██████████▀▀ ▀███████████▌
21+
// █████▀▀ ▀█████████▌
22+
// ▀██████
23+
// ▀███
24+
//
25+
//
26+
// Written by Todd Treece for Adafruit Industries
27+
// Copyright (c) 2016 Adafruit Industries
28+
// Licensed under the MIT license.
29+
//
30+
// All text above must be included in any redistribution.
31+
//
32+
33+
/************************* WiFi Access Point *********************************/
34+
35+
#define WIFI_SSID "your_ssid"
36+
#define WIFI_PASS "your_pass"
37+
38+
/************************* Adafruit IO Setup ********************************/
39+
40+
#define IO_USERNAME "your_username"
41+
#define IO_KEY "your_key"
42+
43+
/*************************** Client Setup ***********************************/
44+
45+
// The Adafruit IO WiFi client will work with the following boards:
46+
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
47+
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
48+
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
49+
// - Feather WICED -> https://www.adafruit.com/products/3056
50+
51+
// set up the wifi client using the supplied ssid & pass:
52+
#include "AdafruitIO_WiFi.h"
53+
AdafruitIO_WiFi io(WIFI_SSID, WIFI_PASS);
54+
55+
/************************ Example Starts Here *******************************/
56+
57+
// this int will hold the current count for our sketch
58+
int count = 0;
59+
60+
// set up the 'counter' feed
61+
AdafruitIO_Feed *counter = io.feed("counter");
62+
63+
void setup() {
64+
65+
// start the serial connection
66+
Serial.begin(115200);
67+
68+
// wait for serial monitor to open
69+
while(! Serial);
70+
71+
Serial.print("Connecting to Adafruit IO");
72+
73+
// connect to io.adafruit.com
74+
io.connect(IO_USERNAME, IO_KEY);
75+
76+
// wait for a connection
77+
while(io.status() < AIO_CONNECTED) {
78+
Serial.print(".");
79+
delay(500);
80+
}
81+
82+
// we are connected
83+
Serial.println();
84+
Serial.println(io.statusText());
85+
86+
}
87+
88+
void loop() {
89+
90+
// io.run(); is required for all sketches.
91+
// it should always be present at the top of your loop
92+
// function. it keeps the client connected to
93+
// io.adafruit.com, and processes any incoming data.
94+
io.run();
95+
96+
// save count to the 'counter' feed on Adafruit IO
97+
Serial.print("sending -> ");
98+
Serial.println(count);
99+
counter->save(count);
100+
101+
// increment the count by 1
102+
count++;
103+
104+
// wait one second (1000 milliseconds == 1 second)
105+
delay(1000);
106+
107+
}

0 commit comments

Comments
 (0)