Skip to content

Commit 0074998

Browse files
committed
switch to Definitions-based debug + error logging, normalize macro names
1 parent cc0d9fc commit 0074998

File tree

4 files changed

+32
-44
lines changed

4 files changed

+32
-44
lines changed

src/AdafruitIO.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ AdafruitIO::AdafruitIO(const char *user, const char *key)
2929

3030
void errorCallback(char *err, uint16_t len)
3131
{
32-
AIO_ERR_PRINTLN();
33-
AIO_ERR_PRINT("ERROR: ");
34-
AIO_ERR_PRINTLN(err);
35-
AIO_ERR_PRINTLN();
32+
AIO_ERROR_PRINTLN();
33+
AIO_ERROR_PRINT("ERROR: ");
34+
AIO_ERROR_PRINTLN(err);
35+
AIO_ERROR_PRINTLN();
3636
}
3737

3838
void AdafruitIO::connect()
3939
{
4040

41+
AIO_DEBUG_PRINTLN("AdafruitIO::connect()");
42+
4143
if(_err_sub) {
4244
// setup error sub
4345
_err_sub = new Adafruit_MQTT_Subscribe(_mqtt, _err_topic);
@@ -221,7 +223,11 @@ aio_status_t AdafruitIO::mqttStatus()
221223
// if the connection failed,
222224
// return so we don't hammer IO
223225
if(_status == AIO_CONNECT_FAILED)
226+
{
227+
AIO_ERROR_PRINT("mqttStatus() failed to connect");
228+
AIO_ERROR_PRINTLN(_mqtt->connectErrorString(_status));
224229
return _status;
230+
}
225231

226232
if(_mqtt->connected())
227233
return AIO_CONNECTED;

src/AdafruitIO.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,6 @@
3030
#error "This sketch requires Adafruit MQTT Library v0.17.0 or higher. Please install or upgrade using the Library Manager."
3131
#endif
3232

33-
// Uncomment/comment to turn on/off debug output messages.
34-
// #define IO_DEBUG
35-
// Uncomment/comment to turn on/off error output messages.
36-
#define IO_ERROR
37-
38-
// Set where debug messages will be printed.
39-
#define IO_DEBUG_PRINTER Serial
40-
// If using something like Zero or Due, change the above to SerialUSB
41-
42-
// Define actual debug output functions when necessary.
43-
#ifdef IO_DEBUG
44-
#define IO_DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
45-
#define IO_DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
46-
#define IO_DEBUG_PRINTBUFFER(buffer, len) { printBuffer(buffer, len); }
47-
#else
48-
#define IO_DEBUG_PRINT(...) {}
49-
#define IO_DEBUG_PRINTLN(...) {}
50-
#define IO_DEBUG_PRINTBUFFER(buffer, len) {}
51-
#endif
52-
53-
#ifdef IO_ERROR
54-
#define IO_ERROR_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
55-
#define IO_ERROR_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
56-
#define IO_ERROR_PRINTBUFFER(buffer, len) { printBuffer(buffer, len); }
57-
#else
58-
#define IO_ERROR_PRINT(...) {}
59-
#define IO_ERROR_PRINTLN(...) {}
60-
#define IO_ERROR_PRINTBUFFER(buffer, len) {}
61-
#endif
62-
6333

6434
class AdafruitIO {
6535

src/AdafruitIO_Definitions.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,30 @@ class AdafruitIOGroupCallback {
4141

4242
};
4343

44+
// Uncomment/comment to turn on/off debug output messages.
45+
#define AIO_DEBUG
4446
// uncomment/comment to turn on/off error output
4547
#define AIO_ERROR
4648

4749
// where debug messages will be printed
4850
#define AIO_PRINTER Serial
51+
// If using something like Zero or Due, change the above to SerialUSB
52+
53+
// Define actual debug output functions when necessary.
54+
#ifdef AIO_DEBUG
55+
#define AIO_DEBUG_PRINT(...) { AIO_PRINTER.print(__VA_ARGS__); }
56+
#define AIO_DEBUG_PRINTLN(...) { AIO_PRINTER.println(__VA_ARGS__); }
57+
#else
58+
#define AIO_DEBUG_PRINT(...) {}
59+
#define AIO_DEBUG_PRINTLN(...) {}
60+
#endif
4961

5062
#ifdef AIO_ERROR
51-
#define AIO_ERR_PRINT(...) { AIO_PRINTER.print(__VA_ARGS__); }
52-
#define AIO_ERR_PRINTLN(...) { AIO_PRINTER.println(__VA_ARGS__); }
63+
#define AIO_ERROR_PRINT(...) { AIO_PRINTER.print(__VA_ARGS__); }
64+
#define AIO_ERROR_PRINTLN(...) { AIO_PRINTER.println(__VA_ARGS__); }
5365
#else
54-
#define AIO_ERR_PRINT(...) {}
55-
#define AIO_ERR_PRINTLN(...) {}
66+
#define AIO_ERROR_PRINT(...) {}
67+
#define AIO_ERROR_PRINTLN(...) {}
5668
#endif
5769

5870
#define AIO_PING_INTERVAL 60000

src/AdafruitIO_Feed.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ AdafruitIO_Data* AdafruitIO_Feed::lastValue()
152152
url += name;
153153
url += "/data/retain";
154154

155-
IO_DEBUG_PRINT("lastValue get ");
156-
IO_DEBUG_PRINTLN(url);
155+
AIO_DEBUG_PRINT("lastValue get ");
156+
AIO_DEBUG_PRINTLN(url);
157157

158158
_io->_http->beginRequest();
159159
_io->_http->get(url.c_str());
@@ -171,10 +171,10 @@ AdafruitIO_Data* AdafruitIO_Feed::lastValue()
171171

172172
} else {
173173

174-
IO_ERROR_PRINT("error retrieving lastValue, status: ");
175-
IO_ERROR_PRINTLN(status);
176-
IO_ERROR_PRINT("response body: ");
177-
IO_ERROR_PRINTLN(_io->_http->responseBody());
174+
AIO_ERROR_PRINT("error retrieving lastValue, status: ");
175+
AIO_ERROR_PRINTLN(status);
176+
AIO_ERROR_PRINT("response body: ");
177+
AIO_ERROR_PRINTLN(_io->_http->responseBody());
178178

179179
return NULL;
180180

0 commit comments

Comments
 (0)