File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ AdafruitIO_Feed* AdafruitIO::feed(const __FlashStringHelper *name)
59
59
return new AdafruitIO_Feed (this , name);
60
60
}
61
61
62
+ void errorCallback (char *err, uint16_t len)
63
+ {
64
+ AIO_ERR_PRINTLN ();
65
+ AIO_ERR_PRINT (" ERROR: " );
66
+ AIO_ERR_PRINTLN (err);
67
+ AIO_ERR_PRINTLN ();
68
+ }
69
+
62
70
void AdafruitIO::_init ()
63
71
{
64
72
// we have never pinged, so set last ping to now
@@ -79,6 +87,7 @@ void AdafruitIO::_init()
79
87
// setup error sub
80
88
_err_sub = new Adafruit_MQTT_Subscribe (_mqtt, _err_topic);
81
89
_mqtt->subscribe (_err_sub);
90
+ _err_sub->setCallback (errorCallback);
82
91
83
92
} else {
84
93
@@ -99,6 +108,7 @@ void AdafruitIO::_init()
99
108
// setup throttle sub
100
109
_throttle_sub = new Adafruit_MQTT_Subscribe (_mqtt, _throttle_topic);
101
110
_mqtt->subscribe (_throttle_sub);
111
+ _throttle_sub->setCallback (errorCallback);
102
112
103
113
} else {
104
114
@@ -108,12 +118,6 @@ void AdafruitIO::_init()
108
118
}
109
119
}
110
120
111
- void AdafruitIO::setErrorHandler (SubscribeCallbackBufferType cb)
112
- {
113
- _err_sub->setCallback (cb);
114
- _throttle_sub->setCallback (cb);
115
- }
116
-
117
121
const __FlashStringHelper* AdafruitIO::statusText ()
118
122
{
119
123
switch (_status) {
Original file line number Diff line number Diff line change @@ -32,11 +32,12 @@ class AdafruitIO {
32
32
33
33
void connect (const char *user, const char *key);
34
34
void connect (const __FlashStringHelper *user, const __FlashStringHelper *key);
35
+
35
36
void run ();
36
- void setErrorHandler (SubscribeCallbackBufferType cb);
37
37
38
38
AdafruitIO_Feed* feed (const char *name);
39
39
AdafruitIO_Feed* feed (const __FlashStringHelper *name);
40
+
40
41
const __FlashStringHelper* statusText ();
41
42
42
43
aio_status_t status ();
Original file line number Diff line number Diff line change @@ -17,6 +17,22 @@ class AdafruitIO_Data;
17
17
18
18
typedef void (*AdafruitIODataCallbackType)(AdafruitIO_Data *data);
19
19
20
+ // uncomment/comment to turn on/off error output
21
+ #define AIO_ERROR
22
+
23
+ // where debug messages will be printed
24
+ #define AIO_PRINTER Serial
25
+
26
+ #ifdef AIO_ERROR
27
+ #define AIO_ERR_PRINT (...) { AIO_PRINTER.print (__VA_ARGS__); }
28
+ #define AIO_ERR_PRINTLN (...) { AIO_PRINTER.println (__VA_ARGS__); }
29
+ #define AIO_ERR_PRINTBUFFER (buffer, len ) { printBuffer (buffer, len); }
30
+ #else
31
+ #define AIO_ERR_PRINT (...) {}
32
+ #define AIO_ERR_PRINTLN (...) {}
33
+ #define AIO_ERR_PRINTBUFFER (buffer, len ) {}
34
+ #endif
35
+
20
36
#define AIO_PING_INTERVAL 60000
21
37
#define AIO_THROTTLE_RECONNECT_INTERVAL 60000
22
38
You can’t perform that action at this time.
0 commit comments