-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathAdafruitIO_Definitions.h
More file actions
172 lines (147 loc) · 7.11 KB
/
AdafruitIO_Definitions.h
File metadata and controls
172 lines (147 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*!
* @file AdafruitIO_Definitions.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_DEFINITIONS_H_
#define ADAFRUITIO_DEFINITIONS_H_
#define ADAFRUITIO_VERSION_MAJOR 4 ///< Adafruit IO Arduino Major Semvar
#define ADAFRUITIO_VERSION_MINOR 2 ///< Adafruit IO Arduino Minor Semvar
#define ADAFRUITIO_VERSION_PATCH 1 ///< Adafruit IO Arduino Patch Semvar
// forward declaration
class AdafruitIO_Data;
typedef void (*AdafruitIODataCallbackType)(
AdafruitIO_Data *data); /*!< Data callback type */
/**************************************************************************/
/*!
@brief Class that contains methods for Adafruit IO MQTT callbacks.
*/
/**************************************************************************/
class AdafruitIOGroupCallback {
public:
/**************************************************************************/
/*!
@brief Sets up MQTT Group callbacks.
@param f
Valid Adafruit IO feed key.
@param cb
Adafruit IO MQTT callback.
*/
/**************************************************************************/
AdafruitIOGroupCallback(const char *f, AdafruitIODataCallbackType cb) {
feed = f;
dataCallback = cb;
next_cb = 0;
}
/**************************************************************************/
/*!
@brief Sets up MQTT Group callbacks.
@param cb
Adafruit IO MQTT callback.
*/
/**************************************************************************/
AdafruitIOGroupCallback(AdafruitIODataCallbackType cb) {
feed = 0;
dataCallback = cb;
next_cb = 0;
}
const char *feed; /*!< Adafruit IO feed name. */
AdafruitIODataCallbackType
dataCallback; /*!< data carried by an AdafruitIOGroupCallback. */
AdafruitIOGroupCallback *next_cb; /*!< Next callback number. */
};
// Uncomment/comment to turn on/off debug output messages.
// #define AIO_DEBUG
// Uncomment/comment to turn on/off error output
// #define AIO_ERROR
// note: if you're using something like Zero or Due, change the below to
// SerialUSB
#define AIO_PRINTER Serial ///< Where debug messages will be printed
// Define actual debug output functions when necessary.
#ifdef AIO_DEBUG
#define AIO_DEBUG_PRINT(...) \
{ AIO_PRINTER.print(__VA_ARGS__); } ///< Prints debug output.
#define AIO_DEBUG_PRINTLN(...) \
{ AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from debug output.
#else
#define AIO_DEBUG_PRINT(...) \
{} ///< Prints debug output
#define AIO_DEBUG_PRINTLN(...) \
{} ///< Prints line from debug output.
#endif
// Define actual error output functions when necessary.
#ifdef AIO_ERROR
#define AIO_ERROR_PRINT(...) \
{ AIO_PRINTER.print(__VA_ARGS__); } ///< Prints error output
#define AIO_ERROR_PRINTLN(...) \
{ AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from error output
#else
#define AIO_ERROR_PRINT(...) \
{} ///< Prints error output.
#define AIO_ERROR_PRINTLN(...) \
{} ///< Prints line from error output.
#endif
#define AIO_PING_INTERVAL 60000 ///< Adafruit IO Ping Interval, in milliseconds
#define AIO_THROTTLE_RECONNECT_INTERVAL \
60000 ///< Time to wait between re-connecting to Adafruit IO after throttled
#define AIO_MQTT_CONNECTION_TIMEOUT \
60000 ///< Time to wait for a successful reconnection after MQTT disconnect
#define AIO_NET_CONNECTION_TIMEOUT \
60000 ///< Time to wait for a successful reconnection after network disconnect
#define AIO_NET_DISCONNECT_WAIT \
300 ///< Time to wait for a net disconnect to take effect
#define AIO_ERROR_TOPIC "/errors" ///< Adafruit IO Error MQTT Topic
#define AIO_THROTTLE_TOPIC "/throttle" ///< Adafruit IO Throttle MQTT Topic
/* NB: io.adafruit.com TLS/SSL certificate changes every 6months, and pinning
certificates is no longer recommended. Migrate to a larger MCU like ESP32
which can accomodate root certificates and verify chains of trust. */
/* For older devices like ESP8266 you can generate the latest fingerprint with:
echo | openssl s_client -connect io.adafruit.com:443 | openssl x509 -fingerprint -noout
*/
#define AIO_SSL_FINGERPRINT \
"47 D2 CB 14 DF 38 97 59 C6 65 1A 1F 3E 00 1E 53 CC A5 17 E0" ///< Latest
///< Adafruit IO
///< SSL
///< Fingerprint
#define AIO_FEED_NAME_LENGTH \
258 ///< Maximum length of an Adafruit IO Feed: Name; 128 + 1 + 128 for the
///< group, a dot, and actual feed name.
#define AIO_DATA_LENGTH \
45 ///< Maximum length of data sent/recieved from Adafruit IO
#define AIO_CSV_LENGTH \
AIO_FEED_NAME_LENGTH + \
4 ///< Maximum comma-separated-value length from Adafruit IO
/** aio_status_t offers 13 status states */
typedef enum {
AIO_IDLE = 0, // Waiting for connection establishement
AIO_NET_DISCONNECTED = 1, // Network disconnected
AIO_DISCONNECTED = 2, // Disconnected from Adafruit IO
AIO_FINGERPRINT_UNKOWN = 3, // Unknown AIO_SSL_FINGERPRINT
AIO_NET_CONNECT_FAILED = 10, // Failed to connect to network
AIO_CONNECT_FAILED = 11, // Failed to connect to Adafruit IO
AIO_FINGERPRINT_INVALID = 12, // Unknown AIO_SSL_FINGERPRINT
AIO_AUTH_FAILED = 13, // Invalid Adafruit IO login credentials provided.
AIO_SSID_INVALID =
14, // SSID is "" or otherwise invalid, connection not attempted
AIO_NET_CONNECTED = 20, // Connected to Adafruit IO
AIO_CONNECTED = 21, // Connected to network
AIO_CONNECTED_INSECURE = 22, // Insecurely (non-SSL) connected to network
AIO_FINGERPRINT_UNSUPPORTED = 23, // Unsupported AIO_SSL_FINGERPRINT
AIO_FINGERPRINT_VALID = 24 // Valid AIO_SSL_FINGERPRINT
} aio_status_t;
/** Three different types of MQTT time feeds from IO */
typedef enum {
AIO_TIME_SECONDS = 0, // Seconds MQTT feed
AIO_TIME_MILLIS = 1, // Milisecond MQTT feed
AIO_TIME_ISO = 2 // ISO8601 MQTT Feed
} aio_time_format_t;
#endif /* ADAFRUITIO_DEFINITIONS_H_ */