@@ -67,6 +67,7 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
67
67
, _messageTopicIn(" " )
68
68
, _dataTopicOut(" " )
69
69
, _dataTopicIn(" " )
70
+ , _authMode(ArduinoIoTAuthenticationMode::CERTIFICATE)
70
71
#if OTA_ENABLED
71
72
, _ota(&_message_stream)
72
73
, _get_ota_confirmation{nullptr }
@@ -84,20 +85,24 @@ int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, bool const enable_
84
85
_connection = &connection;
85
86
_brokerAddress = brokerAddress;
86
87
88
+ #if defined (BOARD_HAS_SECRET_KEY)
89
+ /* If board supports and sketch is configured for username and password login */
90
+ if (_password.length ()) {
91
+ _authMode = ArduinoIoTAuthenticationMode::PASSWORD;
92
+ }
93
+ #endif
94
+
87
95
/* Setup broker TLS client */
88
- _brokerClient.begin (connection);
96
+ _brokerClient.begin (connection, _authMode );
89
97
90
98
#if OTA_ENABLED
91
99
/* Setup OTA TLS client */
92
100
_otaClient.begin (connection);
93
101
#endif
94
102
95
- #if defined (BOARD_HAS_SECRET_KEY)
96
- /* If board is not configured for username and password login */
97
- if (!_password.length ())
103
+ /* If board is configured for certificate authentication and mTLS */
104
+ if (_authMode == ArduinoIoTAuthenticationMode::CERTIFICATE)
98
105
{
99
- #endif
100
-
101
106
#if defined(BOARD_HAS_SECURE_ELEMENT)
102
107
if (!_selement.begin ())
103
108
{
@@ -130,14 +135,11 @@ int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, bool const enable_
130
135
#endif
131
136
_brokerPort = (brokerPort == DEFAULT_BROKER_PORT_AUTO) ? mqttPort () : brokerPort;
132
137
#endif
133
-
134
- #if defined(BOARD_HAS_SECRET_KEY)
135
138
}
136
139
else
137
140
{
138
141
_brokerPort = (brokerPort == DEFAULT_BROKER_PORT_AUTO) ? DEFAULT_BROKER_PORT_USER_PASS_AUTH : brokerPort;
139
142
}
140
- #endif
141
143
142
144
/* Setup TimeService */
143
145
_time_service.begin (_connection);
0 commit comments