@@ -252,18 +252,12 @@ void InfluxDBClient::setUrls() {
252
252
_queryUrl += " /api/v2/query?org=" ;
253
253
_queryUrl += urlEncode (_org.c_str ());
254
254
INFLUXDB_CLIENT_DEBUG (" [D] queryUrl: %s\n " , _queryUrl.c_str ());
255
- _validateUrl = _serverUrl;
256
- _validateUrl += " /health" ;
257
- INFLUXDB_CLIENT_DEBUG (" [D] validateUrl: %s\n " , _validateUrl.c_str ());
258
255
} else {
259
256
_writeUrl = _serverUrl;
260
257
_writeUrl += " /write?db=" ;
261
258
_writeUrl += urlEncode (_bucket.c_str ());
262
259
_queryUrl = _serverUrl;
263
260
_queryUrl += " /api/v2/query" ;
264
- // on version 1.x /ping will by default return status code 204, without verbose
265
- _validateUrl = _serverUrl;
266
- _validateUrl += " /ping?verbose=true" ;
267
261
if (_user.length () > 0 && _password.length () > 0 ) {
268
262
String auth = " &u=" ;
269
263
auth += urlEncode (_user.c_str ());
@@ -272,11 +266,9 @@ void InfluxDBClient::setUrls() {
272
266
_writeUrl += auth;
273
267
_queryUrl += " ?" ;
274
268
_queryUrl += auth;
275
- _validateUrl += auth;
276
269
}
277
270
INFLUXDB_CLIENT_DEBUG (" [D] writeUrl: %s\n " , _writeUrl.c_str ());
278
271
INFLUXDB_CLIENT_DEBUG (" [D] queryUrl: %s\n " , _queryUrl.c_str ());
279
- INFLUXDB_CLIENT_DEBUG (" [D] validateUrl: %s\n " , _validateUrl.c_str ());
280
272
}
281
273
if (_writeOptions._writePrecision != WritePrecision::NoTime) {
282
274
_writeUrl += " &precision=" ;
@@ -551,9 +543,17 @@ bool InfluxDBClient::validateConnection() {
551
543
_lastErrorResponse = FPSTR (UninitializedMessage);
552
544
return false ;
553
545
}
554
- INFLUXDB_CLIENT_DEBUG (" [D] Validating connection to %s\n " , _serverUrl.c_str ());
546
+ // on version 1.x /ping will by default return status code 204, without verbose
547
+ String url = _serverUrl + (_dbVersion==2 ?" /health" :" /ping?verbose=true" );
548
+ if (_dbVersion==1 && _user.length () > 0 && _password.length () > 0 ) {
549
+ url += " &u=" ;
550
+ url += urlEncode (_user.c_str ());
551
+ url += " &p=" ;
552
+ url += urlEncode (_password.c_str ());
553
+ }
554
+ INFLUXDB_CLIENT_DEBUG (" [D] Validating connection to %s\n " , url.c_str ());
555
555
556
- if (!_httpClient->begin (*_wifiClient, _validateUrl )) {
556
+ if (!_httpClient->begin (*_wifiClient, url )) {
557
557
INFLUXDB_CLIENT_DEBUG (" [E] begin failed\n " );
558
558
return false ;
559
559
}
0 commit comments