@@ -19,9 +19,10 @@ String chipId = String(ESP.getChipId());
1919String deviceName = " ESP8266" ;
2020#endif
2121
22- #define INFLUXDB_CLIENT_TESTING_URL " http://192.168.88.36 :999"
22+ #define INFLUXDB_CLIENT_TESTING_URL " http://192.168.88.142 :999"
2323#define INFLUXDB_CLIENT_TESTING_ORG " my-org"
2424#define INFLUXDB_CLIENT_TESTING_BUC " my-bucket"
25+ #define INFLUXDB_CLIENT_TESTING_DB " my-db"
2526#define INFLUXDB_CLIENT_TESTING_TOK " 1234567890"
2627#define INFLUXDB_CLIENT_TESTING_SSID " SSID"
2728#define INFLUXDB_CLIENT_TESTING_PASS " password"
@@ -30,6 +31,7 @@ String deviceName = "ESP8266";
3031int failures = 0 ;
3132
3233#include " TestSupport.h"
34+ #include < core_version.h>
3335
3436void setup () {
3537 Serial.begin (115200 );
@@ -46,8 +48,10 @@ void setup() {
4648
4749 // tests
4850 testPoint ();
49- testInit ();
5051 testBasicFunction ();
52+ testInit ();
53+ testV1 ();
54+ testUserAgent ();
5155 testFailedWrites ();
5256 testTimestamp ();
5357 testRetryOnFailedConnection ();
@@ -206,6 +210,34 @@ void testInit() {
206210 deleteAll (INFLUXDB_CLIENT_TESTING_URL);
207211}
208212
213+ #define STRHELPER (x ) #x
214+ #define STR (x ) STRHELPER(x) // stringifier
215+
216+ #if defined(ESP8266)
217+ # define INFLUXDB_CLIENT_PLATFORM " ESP8266"
218+ # define INFLUXDB_CLIENT_PLATFORM_VERSION STR (ARDUINO_ESP8266_GIT_DESC)
219+ #elif defined(ESP32)
220+ # define INFLUXDB_CLIENT_PLATFORM " ESP32"
221+ # define INFLUXDB_CLIENT_PLATFORM_VERSION STR (ARDUINO_ESP32_GIT_DESC)
222+ #endif
223+
224+
225+ void testUserAgent () {
226+ TEST_INIT (" testUserAgent" );
227+
228+ InfluxDBClient client (INFLUXDB_CLIENT_TESTING_URL, INFLUXDB_CLIENT_TESTING_ORG, INFLUXDB_CLIENT_TESTING_BUC, INFLUXDB_CLIENT_TESTING_TOK);
229+ TEST_ASSERT (client.validateConnection ());
230+ String url = INFLUXDB_CLIENT_TESTING_URL " /test/user-agent" ;
231+ HTTPClient http;
232+ TEST_ASSERT (http.begin (url));
233+ TEST_ASSERT (http.GET () == 200 );
234+ String agent = " influxdb-client-arduino/" INFLUXDB_CLIENT_VERSION " (" INFLUXDB_CLIENT_PLATFORM " " INFLUXDB_CLIENT_PLATFORM_VERSION " )" ;
235+ String data = http.getString ();
236+ TEST_ASSERTM (data == agent, data);
237+ http.end ();
238+ TEST_END ();
239+ }
240+
209241void testRetryOnFailedConnection () {
210242 TEST_INIT (" testRetryOnFailedConnection" );
211243
@@ -704,6 +736,41 @@ void testTimestamp() {
704736 deleteAll (INFLUXDB_CLIENT_TESTING_URL);
705737}
706738
739+ void testV1 () {
740+
741+ TEST_INIT (" testV1" );
742+ InfluxDBClient client (INFLUXDB_CLIENT_TESTING_URL, INFLUXDB_CLIENT_TESTING_DB);
743+
744+ TEST_ASSERT (client.validateConnection ());
745+ // test with no batching
746+ for (int i = 0 ; i < 20 ; i++) {
747+ Point *p = createPoint (" test1" );
748+ p->addField (" index" , i);
749+ TEST_ASSERTM (client.writePoint (*p), String (" i=" ) + i);
750+ delete p;
751+ }
752+ String query = " select" ;
753+ String q = queryFlux (client.getServerUrl (),INFLUXDB_CLIENT_TESTING_TOK, INFLUXDB_CLIENT_TESTING_ORG, query);
754+ int count;
755+ String *lines = getLines (q, count);
756+ TEST_ASSERT (count == 21 );
757+ deleteAll (INFLUXDB_CLIENT_TESTING_URL);
758+
759+ // test with w/ batching 5
760+ client.setWriteOptions (WritePrecision::NoTime, 5 );
761+
762+ for (int i = 0 ; i < 15 ; i++) {
763+ Point *p = createPoint (" test1" );
764+ p->addField (" index" , i);
765+ TEST_ASSERTM (client.writePoint (*p), String (" i=" ) + i);
766+ delete p;
767+ }
768+ q = queryFlux (client.getServerUrl (),INFLUXDB_CLIENT_TESTING_TOK, INFLUXDB_CLIENT_TESTING_ORG, query);
769+ lines = getLines (q, count);
770+ TEST_ASSERT (count == 16 );
771+ TEST_END ();
772+ deleteAll (INFLUXDB_CLIENT_TESTING_URL);
773+ }
707774Point *createPoint (String measurement) {
708775 Point *point = new Point (measurement);
709776 point->addTag (" SSID" , WiFi.SSID ());
0 commit comments