Skip to content

Commit 46105a4

Browse files
authored
Merge pull request #6 from adafruit/groups
Groups
2 parents ef4bead + 970f0f4 commit 46105a4

25 files changed

+811
-141
lines changed

examples/adafruitio_06_digital_in/adafruitio_06_digital_in.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ AdafruitIO_Feed *digital = io.feed("digital");
3232
void setup() {
3333

3434
// set button pin as an input
35-
pinMode(BUTTON_PIN, INPUT_PULLUP);
35+
pinMode(BUTTON_PIN, INPUT);
3636

3737
// start the serial connection
3838
Serial.begin(115200);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Adafruit IO Group Publish Example
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 Todd Treece for Adafruit Industries
8+
// Copyright (c) 2016 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+
22+
// set up the group
23+
AdafruitIO_Group *group = io.group("example");
24+
25+
int count_1 = 0;
26+
int count_2 = 0;
27+
28+
void setup() {
29+
30+
// start the serial connection
31+
Serial.begin(115200);
32+
33+
// wait for serial monitor to open
34+
while(! Serial);
35+
36+
// connect to io.adafruit.com
37+
Serial.print("Connecting to Adafruit IO");
38+
io.connect();
39+
40+
// wait for a connection
41+
while(io.status() < AIO_CONNECTED) {
42+
Serial.print(".");
43+
delay(500);
44+
}
45+
46+
// we are connected
47+
Serial.println();
48+
Serial.println(io.statusText());
49+
50+
}
51+
52+
void loop() {
53+
54+
// io.run(); is required for all sketches.
55+
// it should always be present at the top of your loop
56+
// function. it keeps the client connected to
57+
// io.adafruit.com, and processes any incoming data.
58+
io.run();
59+
60+
group->set("count-1", count_1);
61+
group->set("count-2", count_2);
62+
group->save();
63+
64+
Serial.print("sending example.count-1 -> ");
65+
Serial.println(count_1);
66+
Serial.print("sending example.count-2 -> ");
67+
Serial.println(count_2);
68+
69+
// increment the count_1 by 1
70+
count_1 += 1;
71+
// increment the count_2 by 2
72+
count_2 *= 2;
73+
74+
// wait one second (1000 milliseconds == 1 second)
75+
delay(1000);
76+
}
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);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Adafruit IO Group Subscribe Example
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 Todd Treece for Adafruit Industries
8+
// Copyright (c) 2016 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+
22+
// set up the group
23+
AdafruitIO_Group *group = io.group("example");
24+
25+
void setup() {
26+
27+
// start the serial connection
28+
Serial.begin(115200);
29+
30+
// wait for serial monitor to open
31+
while(! Serial);
32+
33+
// connect to io.adafruit.com
34+
Serial.print("Connecting to Adafruit IO");
35+
io.connect();
36+
37+
group->onMessage("count-1", one);
38+
group->onMessage("count-2", two);
39+
40+
// wait for a connection
41+
while(io.status() < AIO_CONNECTED) {
42+
Serial.print(".");
43+
delay(500);
44+
}
45+
46+
// we are connected
47+
Serial.println();
48+
Serial.println(io.statusText());
49+
50+
}
51+
52+
void loop() {
53+
54+
// io.run(); is required for all sketches.
55+
// it should always be present at the top of your loop
56+
// function. it keeps the client connected to
57+
// io.adafruit.com, and processes any incoming data.
58+
io.run();
59+
60+
}
61+
62+
63+
// this function is called whenever a 'counter-1' message
64+
// is received from Adafruit IO. it was attached to
65+
// the counter-1 feed in the setup() function above.
66+
void one(AdafruitIO_Data *data) {
67+
Serial.print("received example.count-1 <- ");
68+
Serial.println(data->value());
69+
}
70+
71+
// this function is called whenever a 'counter-2' message
72+
// is received from Adafruit IO. it was attached to
73+
// the counter-2 feed in the setup() function above.
74+
void two(AdafruitIO_Data *data) {
75+
Serial.print("received example.count-2 <- ");
76+
Serial.println(data->value());
77+
}
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);

src/AdafruitIO.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,6 @@ AdafruitIO::AdafruitIO(const char *user, const char *key)
2727
_init();
2828
}
2929

30-
AdafruitIO::AdafruitIO(const __FlashStringHelper *user, const __FlashStringHelper *key)
31-
{
32-
_mqtt = 0;
33-
_http = 0;
34-
_username = (const char*)user;
35-
_key = (const char*)key;
36-
_err_topic = 0;
37-
_throttle_topic = 0;
38-
_err_sub = 0;
39-
_throttle_sub = 0;
40-
_packetread_timeout = 100;
41-
_user_agent = 0;
42-
43-
_init();
44-
}
45-
4630
void errorCallback(char *err, uint16_t len)
4731
{
4832
AIO_ERR_PRINTLN();
@@ -92,9 +76,9 @@ AdafruitIO_Feed* AdafruitIO::feed(const char* name)
9276
return new AdafruitIO_Feed(this, name);
9377
}
9478

95-
AdafruitIO_Feed* AdafruitIO::feed(const __FlashStringHelper *name)
79+
AdafruitIO_Group* AdafruitIO::group(const char* name)
9680
{
97-
return new AdafruitIO_Feed(this, name);
81+
return new AdafruitIO_Group(this, name);
9882
}
9983

10084
AdafruitIO_Dashboard* AdafruitIO::dashboard(const char* name)

src/AdafruitIO.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,37 @@
1616
#include "Adafruit_MQTT.h"
1717
#include "AdafruitIO_Definitions.h"
1818
#include "AdafruitIO_Feed.h"
19+
#include "AdafruitIO_Group.h"
1920
#include "AdafruitIO_Dashboard.h"
2021
#include "AdafruitIO_Data.h"
2122
#include "ArduinoHttpClient.h"
2223
#include "util/AdafruitIO_Board.h"
2324

2425
#ifndef ADAFRUIT_MQTT_VERSION_MAJOR
25-
#error "This sketch requires Adafruit MQTT Library v0.16.0 or higher. Please install or upgrade using the Library Manager."
26+
#error "This sketch requires Adafruit MQTT Library v0.17.0 or higher. Please install or upgrade using the Library Manager."
2627
#endif
2728

28-
#if ADAFRUIT_MQTT_VERSION_MAJOR == 0 && ADAFRUIT_MQTT_VERSION_MINOR < 16
29-
#error "This sketch requires Adafruit MQTT Library v0.16.0 or higher. Please install or upgrade using the Library Manager."
29+
#if ADAFRUIT_MQTT_VERSION_MAJOR == 0 && ADAFRUIT_MQTT_VERSION_MINOR < 17
30+
#error "This sketch requires Adafruit MQTT Library v0.17.0 or higher. Please install or upgrade using the Library Manager."
3031
#endif
3132

3233
class AdafruitIO {
3334

3435
friend class AdafruitIO_Feed;
36+
friend class AdafruitIO_Group;
3537
friend class AdafruitIO_Dashboard;
3638
friend class AdafruitIO_Block;
3739

3840
public:
3941
AdafruitIO(const char *user, const char *key);
40-
AdafruitIO(const __FlashStringHelper *user, const __FlashStringHelper *key);
4142
virtual ~AdafruitIO();
4243

4344
void connect();
4445

4546
void run(uint16_t busywait_ms = 0);
4647

4748
AdafruitIO_Feed* feed(const char *name);
48-
AdafruitIO_Feed* feed(const __FlashStringHelper *name);
49-
49+
AdafruitIO_Group* group(const char *name);
5050
AdafruitIO_Dashboard* dashboard(const char *name);
5151

5252
const __FlashStringHelper* statusText();

0 commit comments

Comments
 (0)