Skip to content

Commit 81a3d9e

Browse files
committed
Added setting User-Agent header value
1 parent 8ffe10d commit 81a3d9e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/InfluxDbClient.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525
* SOFTWARE.
2626
*/
2727
#include "InfluxDbClient.h"
28+
#include <core_version.h>
29+
30+
#define STRHELPER(x) #x
31+
#define STR(x) STRHELPER(x) // stringifier
32+
33+
#define INFLUXDB_CLIENT_USER_AGENT "influxdb-client-arduino/" INFLUXDB_CLIENT_VERSION
34+
35+
#if defined(ESP8266)
36+
# define INFLUXDB_CLIENT_PLATFORM "ESP8266"
37+
# define INFLUXDB_CLIENT_PLATFORM_VERSION STR(ARDUINO_ESP8266_GIT_DESC)
38+
#elif defined(ESP32)
39+
# define INFLUXDB_CLIENT_PLATFORM "ESP32"
40+
# define INFLUXDB_CLIENT_PLATFORM_VERSION STR(ARDUINO_ESP32_GIT_DESC)
41+
#endif
42+
2843

2944
// Uncomment bellow in case of a problem and rebuild sketch
3045
//#define INFLUXDB_CLIENT_DEBUG
@@ -206,6 +221,9 @@ bool InfluxDBClient::init() {
206221
_wifiClient = new WiFiClient;
207222
}
208223
_httpClient.setReuse(false);
224+
225+
String userAgent(INFLUXDB_CLIENT_USER_AGENT " (" INFLUXDB_CLIENT_PLATFORM " " INFLUXDB_CLIENT_PLATFORM_VERSION ")");
226+
_httpClient.setUserAgent(userAgent);
209227
return true;
210228
}
211229

0 commit comments

Comments
 (0)