@@ -19,9 +19,10 @@ String chipId = String(ESP.getChipId());
19
19
String deviceName = " ESP8266" ;
20
20
#endif
21
21
22
- #define INFLUXDB_CLIENT_TESTING_URL " http://192.168.88.36 :999"
22
+ #define INFLUXDB_CLIENT_TESTING_URL " http://192.168.88.142 :999"
23
23
#define INFLUXDB_CLIENT_TESTING_ORG " my-org"
24
24
#define INFLUXDB_CLIENT_TESTING_BUC " my-bucket"
25
+ #define INFLUXDB_CLIENT_TESTING_DB " my-db"
25
26
#define INFLUXDB_CLIENT_TESTING_TOK " 1234567890"
26
27
#define INFLUXDB_CLIENT_TESTING_SSID " SSID"
27
28
#define INFLUXDB_CLIENT_TESTING_PASS " password"
@@ -30,6 +31,7 @@ String deviceName = "ESP8266";
30
31
int failures = 0 ;
31
32
32
33
#include " TestSupport.h"
34
+ #include < core_version.h>
33
35
34
36
void setup () {
35
37
Serial.begin (115200 );
@@ -46,8 +48,10 @@ void setup() {
46
48
47
49
// tests
48
50
testPoint ();
49
- testInit ();
50
51
testBasicFunction ();
52
+ testInit ();
53
+ testV1 ();
54
+ testUserAgent ();
51
55
testFailedWrites ();
52
56
testTimestamp ();
53
57
testRetryOnFailedConnection ();
@@ -206,6 +210,34 @@ void testInit() {
206
210
deleteAll (INFLUXDB_CLIENT_TESTING_URL);
207
211
}
208
212
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
+
209
241
void testRetryOnFailedConnection () {
210
242
TEST_INIT (" testRetryOnFailedConnection" );
211
243
@@ -704,6 +736,41 @@ void testTimestamp() {
704
736
deleteAll (INFLUXDB_CLIENT_TESTING_URL);
705
737
}
706
738
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
+ }
707
774
Point *createPoint (String measurement) {
708
775
Point *point = new Point (measurement);
709
776
point->addTag (" SSID" , WiFi.SSID ());
0 commit comments