Skip to content

Commit 70a3445

Browse files
authored
Update BleSensors.h
1 parent 7bad8e0 commit 70a3445

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

src/BleSensors/BleSensors.h

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212
// MIT License
1313
//
14-
// Copyright (c) 2023 Matthias Prinke
14+
// Copyright (c) 2025 Matthias Prinke
1515
//
1616
// Permission is hereby granted, free of charge, to any person obtaining a copy
1717
// of this software and associated documentation files (the "Software"), to deal
@@ -36,14 +36,20 @@
3636
//
3737
// 20230211 Created
3838
// 20240417 Added additional constructor and method setAddresses()
39-
// 20240427 Added paramter activeScan to getData()
39+
// 20240427 Added parameter activeScan to getData()
4040
// 20250121 Updated for NimBLE-Arduino v2.x
41+
// 20250808 Added specific logging macros in scan callback to avoid WDT reset
42+
// 20250926 Changed getData() to return number of known sensors found
4143
//
4244
// ToDo:
43-
// -
45+
// -
4446
//
4547
///////////////////////////////////////////////////////////////////////////////
4648

49+
/*! \file BleSensors.h
50+
* \brief Wrapper class for Theeengs Decoder (https://github.com/theengs/decoder)
51+
*/
52+
4753
#if !defined(BLE_SENSORS) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) \
4854
&& !defined(ARDUINO_ARCH_RP2040)
4955
#define BLE_SENSORS
@@ -52,6 +58,26 @@
5258
#include <NimBLEDevice.h> //!< https://github.com/h2zero/NimBLE-Arduino
5359
#include <decoder.h> //!< https://github.com/theengs/decoder
5460

61+
// Extensive logging in the callback may lead to a watchdog reset
62+
// see
63+
// https://github.com/h2zero/NimBLE-Arduino/issues/329
64+
// https://github.com/h2zero/NimBLE-Arduino/issues/351
65+
66+
//#define CB_LOGGING
67+
#if defined(CB_LOGGING)
68+
#define cb_log_i log_i //!< Info
69+
#define cb_log_w log_w //!< Warn
70+
#define cb_log_d log_d //!< Debug
71+
#define cb_log_e log_e //!< Error
72+
#define cb_log_v log_v //!< Verbose
73+
#else
74+
#define cb_log_i {} //!< Info
75+
#define cb_log_w {} //!< Warn
76+
#define cb_log_d {} //!< Debug
77+
#define cb_log_e {} //!< Error
78+
#define cb_log_v {} //!< Verbose
79+
#endif
80+
5581
/*!
5682
* \brief BLE sensor data
5783
*/
@@ -113,21 +139,23 @@ class BleSensors {
113139
*
114140
* \param duration Scan duration in seconds
115141
* \param activeScan 0: passive scan / 1: active scan
116-
*/
142+
*
143+
* \return Number of known sensors found (max. size of known_sensors vector)
144+
*/
117145
unsigned getData(uint32_t duration, bool activeScan = true);
118146

119147
/*!
120148
* \brief Set sensor data invalid.
121-
*/
149+
*/
122150
void resetData(void);
123151

124152
/*!
125153
* \brief Sensor data.
126154
*/
127-
std::vector<ble_sensors_t> data;
155+
std::vector<ble_sensors_t> data;
128156

129157
protected:
130158
std::vector<std::string> _known_sensors; /// MAC addresses of known sensors
131159
NimBLEScan* _pBLEScan; /// NimBLEScan object
132160
};
133-
#endif // !defined(BLE_SENSORS) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) && !defined(ARDUINO_ARCH_RP2040)
161+
#endif

0 commit comments

Comments
 (0)