Adafruit IO Arduino Library
AdafruitIO.h
Go to the documentation of this file.
1 
16 #ifndef ADAFRUITIO_H
17 #define ADAFRUITIO_H
18 
19 #include "AdafruitIO_Dashboard.h"
20 #include "AdafruitIO_Data.h"
21 #include "AdafruitIO_Definitions.h"
22 #include "AdafruitIO_Feed.h"
23 #include "AdafruitIO_Group.h"
24 #include "AdafruitIO_Time.h"
25 #include "Adafruit_MQTT.h"
26 #include "Arduino.h"
27 #include "ArduinoHttpClient.h"
28 #include "util/AdafruitIO_Board.h"
29 
30 #ifndef ADAFRUIT_MQTT_VERSION_MAJOR
31 #error \
32  "This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
33 #endif
34 
35 #if ADAFRUIT_MQTT_VERSION_MAJOR == 1 && ADAFRUIT_MQTT_VERSION_MINOR < 0
36 #error \
37  "This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
38 #endif
39 
40 /**************************************************************************/
44 /**************************************************************************/
45 class AdafruitIO {
50  friend class AdafruitIO_Feed;
51 
56  friend class AdafruitIO_Group;
57 
62  friend class AdafruitIO_Dashboard;
63 
68  friend class AdafruitIO_Block;
69 
74  friend class AdafruitIO_Time;
75 
76 public:
77  AdafruitIO(const char *user, const char *key);
78  virtual ~AdafruitIO();
79 
80  void connect();
81  void wifi_disconnect();
82  aio_status_t run(uint16_t busywait_ms = 0, bool fail_fast = false);
83 
84  AdafruitIO_Feed *feed(const char *name);
85  AdafruitIO_Feed *feed(const char *name, const char *owner);
86  AdafruitIO_Group *group(const char *name);
87  AdafruitIO_Dashboard *dashboard(const char *name);
89 
90  const __FlashStringHelper *statusText();
91 
93  /********************************************************************/
98  /*******************************************************************/
99  virtual aio_status_t networkStatus() = 0;
100 
101  /********************************************************************/
105  /*******************************************************************/
106  aio_status_t mqttStatus(bool fail_fast = false);
107 
108  char *boardID();
109  const char *boardType();
110  char *version();
111  char *userAgent();
112 
113  /********************************************************************/
118  /*******************************************************************/
119  virtual const char *connectionType() = 0;
120 
121 protected:
122  /********************************************************************/
127  /*******************************************************************/
128  virtual void _connect() = 0;
129 
130  /******************************************************/
135  /*****************************************************/
136  virtual void _disconnect() = 0;
137 
138  aio_status_t _status = AIO_IDLE;
139  uint32_t _last_ping =
140  0;
141  uint32_t _last_mqtt_connect = 0;
144  Adafruit_MQTT *_mqtt;
145  HttpClient *_http;
147  char _version[10];
149  const char *_host = "io.adafruit.com";
150  uint16_t _mqtt_port = 8883;
151  uint16_t _mqtt_eth_port =
152  1883;
153  uint16_t _http_port = 443;
158  const char *_username;
159  const char *_key;
161  char *_err_topic;
163  char *_user_agent;
165  Adafruit_MQTT_Subscribe
167  Adafruit_MQTT_Subscribe
170 private:
171  void _init();
172 };
173 
174 #endif // ADAFRUITIO_H
void wifi_disconnect()
Disconnects from WiFi.
Definition: AdafruitIO.cpp:176
virtual void _connect()=0
Establishes a connection with the Adafruit IO MQTT broker.
Class for interacting with Adafruit IO.
Definition: AdafruitIO.h:45
uint16_t _mqtt_port
Definition: AdafruitIO.h:150
const char * _username
Definition: AdafruitIO.h:158
AdafruitIO_Dashboard * dashboard(const char *name)
Create a new AIO dashboard.
Definition: AdafruitIO.cpp:242
aio_status_t _status
Definition: AdafruitIO.h:138
uint16_t _http_port
Definition: AdafruitIO.h:153
virtual void _disconnect()=0
Disconnects from the Adafruit IO MQTT broker.
void connect()
Connects to AIO, setting up using parameters set when the class is instantiated.
Definition: AdafruitIO.cpp:146
uint16_t _mqtt_eth_port
Definition: AdafruitIO.h:151
aio_status_t status()
Status check.
Definition: AdafruitIO.cpp:356
Class for interacting with Adafruit IO Dashboards. https://io.adafruit.com/api/docs/#dashboards.
Definition: AdafruitIO_Dashboard.h:41
char * _throttle_topic
Definition: AdafruitIO.h:162
aio_time_format_t format
Definition: AdafruitIO_Time.h:44
aio_status_t run(uint16_t busywait_ms=0, bool fail_fast=false)
Must be called frequently to keep AIO connections alive. When called with no arguments run() will try...
Definition: AdafruitIO.cpp:309
aio_time_format_t
Definition: AdafruitIO_Definitions.h:165
AdafruitIO_Group * group(const char *name)
Create a new AIO group.
Definition: AdafruitIO.cpp:230
Class that provides methods for interfacing with Adafruit IO feed topics. https://io.adafruit.com/api/docs/mqtt.html#mqtt-topics.
Definition: AdafruitIO_Feed.h:34
char * _user_agent
Definition: AdafruitIO.h:163
aio_status_t mqttStatus(bool fail_fast=false)
Returns MQTT connection status.
Definition: AdafruitIO.cpp:428
char * userAgent()
Identify the user agent.
Definition: AdafruitIO.cpp:404
AdafruitIO(const char *user, const char *key)
Instantiate the AIO object.
Definition: AdafruitIO.cpp:47
Adafruit_MQTT * _mqtt
Definition: AdafruitIO.h:144
uint32_t _last_mqtt_connect
Definition: AdafruitIO.h:141
uint16_t _packetread_timeout
Definition: AdafruitIO.h:155
Class that contains functions for interacting with the Adafruit IO Time Service.
Definition: AdafruitIO_Time.h:36
char _version[10]
Definition: AdafruitIO.h:147
friend class AdafruitIO_Block
AdafruitIO_Block addition.
Definition: AdafruitIO.h:68
const char * boardType()
Identify the board type.
Definition: AdafruitIO.cpp:384
uint32_t _last_ping
Definition: AdafruitIO.h:139
char * _err_topic
Definition: AdafruitIO.h:161
AdafruitIO_Time * time(aio_time_format_t format)
Create a new AIO time.
Definition: AdafruitIO.cpp:218
AdafruitIO_Feed * feed(const char *name)
Create a new AIO feed.
Definition: AdafruitIO.cpp:191
virtual const char * connectionType()=0
Returns the Adafruit IO network module connection type.
virtual aio_status_t networkStatus()=0
Returns network module status.
const __FlashStringHelper * statusText()
Provide status explanation strings.
Definition: AdafruitIO.cpp:253
Class for interacting with Adafruit IO Grouped Feeds https://io.adafruit.com/api/docs/mqtt.html#group-topics.
Definition: AdafruitIO_Group.h:30
const char * _host
Definition: AdafruitIO.h:149
char * boardID()
Identify the board.
Definition: AdafruitIO.cpp:376
aio_status_t
Definition: AdafruitIO_Definitions.h:142
const char * _key
Definition: AdafruitIO.h:159
HttpClient * _http
Definition: AdafruitIO.h:145
Adafruit_MQTT_Subscribe * _err_sub
Definition: AdafruitIO.h:166
Adafruit_MQTT_Subscribe * _throttle_sub
Definition: AdafruitIO.h:168
char * version()
Identify the software version.
Definition: AdafruitIO.cpp:392
virtual ~AdafruitIO()
Destructor to end the AIO object.
Definition: AdafruitIO.cpp:110