Adafruit IO Arduino Library
AdafruitIO_Group.h
1 //
2 // Adafruit invests time and resources providing this open source code.
3 // Please support Adafruit and open source hardware by purchasing
4 // products from Adafruit!
5 //
6 // Copyright (c) 2015-2016 Adafruit Industries
7 // Author: Todd Treece
8 // Licensed under the MIT license.
9 //
10 // All text above must be included in any redistribution.
11 //
12 #ifndef ADAFRUITIO_GROUP_H
13 #define ADAFRUITIO_GROUP_H
14 
15 #include "AdafruitIO_Data.h"
16 #include "AdafruitIO_Definitions.h"
17 #include "AdafruitIO_MQTT.h"
18 #include "Adafruit_MQTT.h"
19 #include "Arduino.h"
20 
21 // forward declaration
22 class AdafruitIO;
23 
24 /**************************************************************************/
29 /**************************************************************************/
31 
32 public:
33  AdafruitIO_Group(AdafruitIO *io, const char *name);
35 
36  void set(const char *feed, char *value);
37  void set(const char *feed, bool value);
38  void set(const char *feed, String value);
39  void set(const char *feed, int value);
40  void set(const char *feed, unsigned int value);
41  void set(const char *feed, long value);
42  void set(const char *feed, unsigned long value);
43  void set(const char *feed, float value);
44  void set(const char *feed, double value);
45 
46  bool save();
47  bool get();
48 
49  void setLocation(double lat = 0, double lon = 0, double ele = 0);
50 
51  bool exists();
52  bool create();
53 
55  void onMessage(const char *feed, AdafruitIODataCallbackType cb);
56 
57  void subCallback(char *val, uint16_t len);
58  void call(AdafruitIO_Data *d);
59 
60  const char *name;
61  const char *owner;
64  AdafruitIO_Data *getFeed(const char *feed);
65 
66 private:
67  void _init();
68 
69  char *_topic;
70  char *_get_topic;
71  char *_create_url;
72  char *_group_url;
74  Adafruit_MQTT_Subscribe *_sub;
75  Adafruit_MQTT_Publish *_pub;
76  Adafruit_MQTT_Publish *_get_pub;
78  AdafruitIO *_io;
79  AdafruitIOGroupCallback *_groupCallback =
80  NULL;
82  double _lat, _lon, _ele;
83 };
84 
85 #endif // ADAFRUITIO_GROUP_H
Class for interacting with Adafruit IO.
Definition: AdafruitIO.h:45
bool create()
Creates new Adafruit IO Group. https://io.adafruit.com/api/docs/#create-group.
Definition: AdafruitIO_Group.cpp:454
~AdafruitIO_Group()
Adafruit IO Group destructor.
Definition: AdafruitIO_Group.cpp:42
void setLocation(double lat=0, double lon=0, double ele=0)
Sets up locational metadata.
Definition: AdafruitIO_Group.cpp:414
friend class AdafruitIO_Group
AdafruitIO_Group addition.
Definition: AdafruitIO.h:56
const char * name
Definition: AdafruitIO_Group.h:60
Class that contains MQTT subscription callbacks.
Definition: AdafruitIO_MQTT.h:25
void(* AdafruitIODataCallbackType)(AdafruitIO_Data *data)
Definition: AdafruitIO_Definitions.h:26
AdafruitIO_Data * getFeed(const char *feed)
Obtains data from feed within group.
Definition: AdafruitIO_Group.cpp:244
AdafruitIO_Data * data
Definition: AdafruitIO_Group.h:63
void onMessage(AdafruitIODataCallbackType cb)
Sets up Adafruit IO callback to monitor incoming new data in group.
Definition: AdafruitIO_Group.cpp:277
Class that contains methods for Adafruit IO MQTT callbacks.
Definition: AdafruitIO_Definitions.h:34
bool exists()
Checks if Adafruit IO Group exists. https://io.adafruit.com/api/docs/#get-group.
Definition: AdafruitIO_Group.cpp:436
const char * owner
Definition: AdafruitIO_Group.h:61
void call(AdafruitIO_Data *d)
Adafruit IO Group subscription function callback.
Definition: AdafruitIO_Group.cpp:337
Class for interacting with Adafruit IO Data Records. https://io.adafruit.com/api/docs/#data.
Definition: AdafruitIO_Data.h:30
Class for interacting with Adafruit IO Grouped Feeds https://io.adafruit.com/api/docs/mqtt.html#group-topics.
Definition: AdafruitIO_Group.h:30
bool save()
Updates value of Adafruit IO Group.
Definition: AdafruitIO_Group.cpp:201
void subCallback(char *val, uint16_t len)
Checks for new value within Adafruit IO group.
Definition: AdafruitIO_Group.cpp:365