Skip to content

Commit 2b4aa5e

Browse files
committed
add define to enable/disable connection handler
1 parent 00f785a commit 2b4aa5e

18 files changed

+154
-42
lines changed

extras/test/include/Arduino.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
******************************************************************************/
2424

2525
typedef std::string String;
26+
typedef struct {
27+
void * udp;
28+
} UDP;
2629

2730
/******************************************************************************
2831
FUNCTION PROTOTYPES

src/AIoTC_Config.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
* AUTOMATICALLY CONFIGURED DEFINES
5959
******************************************************************************/
6060

61+
#if defined(DEBUG_ERROR) || defined(DEBUG_WARNING) || defined(DEBUG_INFO) || defined(DEBUG_DEBUG) || defined(DEBUG_VERBOSE)
62+
#define DEBUG_ENABLED (1)
63+
#else
64+
#define DEBUG_ENABLED (0)
65+
#endif
66+
6167
#if !defined(HAS_NOTECARD)
6268

6369
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
@@ -148,8 +154,10 @@
148154
#define BOARD_STM32H7
149155
#endif
150156

151-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) \
152-
|| defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33)
157+
#define CONNECTION_HANDLER_ENABLED (1)
158+
159+
#if ((defined(BOARD_STM32H7) || defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33)) &&\
160+
(defined(CONNECTION_HANDLER_ENABLED) && (CONNECTION_HANDLER_ENABLED == 1)))
153161
#define NETWORK_CONFIGURATOR_ENABLED (1)
154162
#else
155163
#define NETWORK_CONFIGURATOR_ENABLED (0)

src/ArduinoIoTCloud.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
******************************************************************************/
2727

2828
ArduinoIoTCloudClass::ArduinoIoTCloudClass()
29-
: _connection{nullptr}
29+
: _time_service(TimeService)
30+
#if CONNECTION_HANDLER_ENABLED
31+
,_connection{nullptr}
32+
#endif
3033
#if NETWORK_CONFIGURATOR_ENABLED
3134
, _configurator{nullptr}
3235
#endif
33-
, _time_service(TimeService)
3436
, _thing_id{"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
3537
, _lib_version{AIOT_CONFIG_LIB_VERSION}
3638
, _device_id{"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}

src/ArduinoIoTCloud.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424

2525
#include <AIoTC_Config.h>
2626

27-
#include <Arduino_ConnectionHandler.h>
27+
#if CONNECTION_HANDLER_ENABLED
28+
#include <Arduino_ConnectionHandler.h>
29+
#endif
30+
2831
#if NETWORK_CONFIGURATOR_ENABLED
2932
#include <Arduino_NetworkConfigurator.h>
3033
#endif
3134

32-
#if defined(DEBUG_ERROR) || defined(DEBUG_WARNING) || defined(DEBUG_INFO) || defined(DEBUG_DEBUG) || defined(DEBUG_VERBOSE)
35+
#if DEBUG_ENABLED
3336
#include <Arduino_DebugUtils.h>
3437
#endif
3538

@@ -99,14 +102,16 @@ class ArduinoIoTCloudClass
99102
inline void setDeviceId(String const device_id) { _device_id = device_id; };
100103
inline String & getDeviceId() { return _device_id; };
101104

105+
#if CONNECTION_HANDLER_ENABLED
102106
inline ConnectionHandler * getConnection() { return _connection; }
107+
#endif
103108

104109
inline unsigned long getInternalTime() { return _time_service.getTime(); }
105110
inline unsigned long getLocalTime() { return _time_service.getLocalTime(); }
106111

107-
#if NETWORK_CONFIGURATOR_ENABLED
112+
#if NETWORK_CONFIGURATOR_ENABLED
108113
inline void setConfigurator(NetworkConfiguratorClass & configurator) { _configurator = &configurator; }
109-
#endif
114+
#endif
110115
void addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
111116

112117
#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
@@ -151,11 +156,13 @@ class ArduinoIoTCloudClass
151156

152157
protected:
153158

159+
TimeServiceClass & _time_service;
160+
#if CONNECTION_HANDLER_ENABLED
154161
ConnectionHandler * _connection;
155-
#if NETWORK_CONFIGURATOR_ENABLED
162+
#endif
163+
#if NETWORK_CONFIGURATOR_ENABLED
156164
NetworkConfiguratorClass * _configurator;
157-
#endif
158-
TimeServiceClass & _time_service;
165+
#endif
159166
String _thing_id;
160167
String _lib_version;
161168

src/ArduinoIoTCloudDevice.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "ArduinoIoTCloudDevice.h"
2020
#include "interfaces/CloudProcess.h"
2121

22+
#if DEBUG_ENABLED
23+
#include <Arduino_DebugUtils.h>
24+
#endif
25+
2226
/******************************************************************************
2327
CTOR/DTOR
2428
******************************************************************************/

src/ArduinoIoTCloudTCP.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
8080
* PUBLIC MEMBER FUNCTIONS
8181
******************************************************************************/
8282

83+
#if CONNECTION_HANDLER_ENABLED
8384
int ArduinoIoTCloudTCP::begin(ConnectionHandler& connection, bool const enableWatchdog, String brokerAddress, uint16_t brokerPort, bool autoReconnect)
8485
{
8586
_connection = &connection;
@@ -89,6 +90,7 @@ int ArduinoIoTCloudTCP::begin(ConnectionHandler& connection, bool const enableWa
8990
return begin(_connection->getClient(), _connection->getUDP(), enableWatchdog, brokerAddress, brokerPort, autoReconnect);
9091
#endif
9192
}
93+
#endif
9294

9395
int ArduinoIoTCloudTCP::begin(Client& brokerClient, Client& otaClient, UDP& ntpClient, bool const enableWatchdog, String brokerAddress, uint16_t brokerPort, bool autoReconnect)
9496
{
@@ -342,8 +344,13 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Init()
342344
_otaTLSClient.begin(_otaClient);
343345
#endif
344346

347+
#if CONNECTION_HANDLER_ENABLED
345348
/* Setup TimeService */
346-
_time_service.begin(_connection);
349+
if (_connection != nullptr) {
350+
_time_service.begin(_connection);
351+
} else
352+
#endif
353+
_time_service.begin(_ntpClient);
347354

348355
/* Since we do not control what code the user inserts
349356
* between ArduinoIoTCloudTCP::begin() and the first
@@ -354,8 +361,12 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Init()
354361
if (_enableWatchdog) {
355362
/* Initialize watchdog hardware */
356363
watchdog_enable();
357-
/* Setup callbacks to feed the watchdog during offloaded network operations (connection/download)*/
358-
watchdog_enable_network_feed(_connection->getInterface());
364+
#if CONNECTION_HANDLER_ENABLED
365+
if (_connection != nullptr) {
366+
/* Setup callbacks to feed the watchdog during offloaded network operations (connection/download)*/
367+
watchdog_enable_network_feed(_connection->getInterface());
368+
}
369+
#endif
359370
}
360371
#endif
361372

@@ -364,13 +375,20 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Init()
364375

365376
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectPhy()
366377
{
367-
if (_connection->check() == NetworkConnectionState::CONNECTED)
368-
{
369-
if (!_connection_attempt.isRetry() || (_connection_attempt.isRetry() && _connection_attempt.isExpired()))
370-
return State::SyncTime;
378+
#if CONNECTION_HANDLER_ENABLED
379+
if (_connection == nullptr) {
380+
return State::SyncTime;
371381
}
372382

383+
if (_connection->check() == NetworkConnectionState::CONNECTED) {
384+
if (!_connection_attempt.isRetry() || (_connection_attempt.isRetry() && _connection_attempt.isExpired())) {
385+
return State::SyncTime;
386+
}
387+
}
373388
return State::ConnectPhy;
389+
#else
390+
return State::SyncTime;
391+
#endif
374392
}
375393

376394
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SyncTime()

src/ArduinoIoTCloudTCP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
7474
virtual void printDebugInfo() override;
7575
virtual void disconnect () override;
7676

77+
#if CONNECTION_HANDLER_ENABLED
7778
int begin(ConnectionHandler& connection, bool const enableWatchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS, uint16_t brokerPort = DEFAULT_BROKER_PORT_AUTO, bool autoReconnect = true);
79+
#endif
7880
int begin(Client& brokerClient, Client& otaClient, UDP& ntpClient, bool const enableWatchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS, uint16_t brokerPort = DEFAULT_BROKER_PORT_AUTO, bool autoReconnect = true);
7981
int begin(Client& brokerClient, UDP& ntpClient, bool const enableWatchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS, uint16_t brokerPort = DEFAULT_BROKER_PORT_AUTO, bool autoReconnect = true);
8082

src/ArduinoIoTCloudThing.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include "property/types/CloudWrapperInt.h"
2323
#include "property/types/CloudWrapperUnsignedInt.h"
2424

25+
#if DEBUG_ENABLED
26+
#include <Arduino_DebugUtils.h>
27+
#endif
28+
2529
/******************************************************************************
2630
* CTOR/DTOR
2731
******************************************************************************/

src/ota/implementation/OTANanoRP2040.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#if defined(ARDUINO_NANO_RP2040_CONNECT) && OTA_ENABLED
1414
#include <SFU.h>
1515
#include "OTANanoRP2040.h"
16-
#include <Arduino_DebugUtils.h>
16+
#if DEBUG_ENABLED
17+
#include <Arduino_DebugUtils.h>
18+
#endif
1719
#include "mbed.h"
1820
#include "utility/watchdog/Watchdog.h"
1921

src/ota/implementation/OTASamd.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#if defined(ARDUINO_ARCH_SAMD) && OTA_ENABLED
1414
#include "OTASamd.h"
1515

16-
#include <Arduino_DebugUtils.h>
16+
#if DEBUG_ENABLED
17+
#include <Arduino_DebugUtils.h>
18+
#endif
1719
#if OTA_STORAGE_SNU
1820
# include <SNU.h>
1921
# include <WiFiNINA.h> /* WiFiStorage */

src/ota/implementation/OTAUnoR4.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#if defined(ARDUINO_UNOR4_WIFI) && OTA_ENABLED
1414
#include "OTAUnoR4.h"
1515

16-
#include <Arduino_DebugUtils.h>
16+
#if DEBUG_ENABLED
17+
#include <Arduino_DebugUtils.h>
18+
#endif
1719
#include "fsp_common_api.h"
1820
#include "r_flash_lp.h"
1921
#include "WiFi.h"

src/ota/interface/OTAInterface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include <Arduino_SHA256.h>
2222

2323
#include <interfaces/CloudProcess.h>
24-
#include <Arduino_DebugUtils.h>
24+
#if DEBUG_ENABLED
25+
#include <Arduino_DebugUtils.h>
26+
#endif
2527

2628
/******************************************************************************
2729
* CLASS DECLARATION

src/tls/utility/TLSClientBroker.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
#pragma once
1212

13-
#include <Arduino_ConnectionHandler.h>
1413
#include <AIoTC_Config.h>
14+
#if CONNECTION_HANDLER_ENABLED
15+
#include <Arduino_ConnectionHandler.h>
16+
#endif
1517

1618
enum class ArduinoIoTAuthenticationMode
1719
{

src/tls/utility/TLSClientOta.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
#pragma once
1212

13-
#include <Arduino_ConnectionHandler.h>
1413
#include <AIoTC_Config.h>
14+
#if CONNECTION_HANDLER_ENABLED
15+
#include <Arduino_ConnectionHandler.h>
16+
#endif
17+
1518

1619
#if defined(BOARD_HAS_OFFLOADED_ECCX08)
1720
/*
@@ -69,6 +72,7 @@
6972
public:
7073
void begin(Client* client);
7174

75+
#if CONNECTION_HANDLER_ENABLED
7276
static inline Client& getNewClient(NetworkAdapter net) {
7377
switch(net) {
7478
#ifdef BOARD_HAS_WIFI
@@ -97,4 +101,5 @@
97101
#endif // BOARD_HAS_CELLULAR
98102
}
99103
}
104+
#endif // CONNECTION_HANDLER_ENABLED
100105
};

0 commit comments

Comments
 (0)