1
1
import { SFC } from 'react'
2
2
import {
3
+ ArduinoLogo ,
3
4
CSharpLogo ,
4
5
GoLogo ,
5
6
JavaLogo ,
@@ -18,6 +19,172 @@ export interface ClientLibrary {
18
19
image : SFC
19
20
}
20
21
22
+ export const clientArduinoLibrary = {
23
+ id : 'arduino' ,
24
+ name : 'Arduino' ,
25
+ url : 'https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino' ,
26
+ image : ArduinoLogo ,
27
+ installingLibraryManagerCodeSnippet : `1. Open the Arduino IDE and click to the "Sketch" menu and then Include Library > Manage Libraries.
28
+ 2. Type 'influxdb' in the search box
29
+ 3. Install the 'InfluxDBClient for Arduino' library` ,
30
+ installingManualCodeSnippet : `1. cd <arduino-sketch-location>/library.
31
+ 2. git clone <%= url %>
32
+ 3. Restart the Arduino IDE` ,
33
+ initializeClientCodeSnippet : `#if defined(ESP32)
34
+ #include <WiFiMulti.h>
35
+ WiFiMulti wifiMulti;
36
+ #define DEVICE "ESP32"
37
+ #elif defined(ESP8266)
38
+ #include <ESP8266WiFiMulti.h>
39
+ ESP8266WiFiMulti wifiMulti;
40
+ #define DEVICE "ESP8266"
41
+ #endif
42
+
43
+ #include <InfluxDbClient.h>
44
+ #include <InfluxDbCloud.h>
45
+
46
+ // WiFi AP SSID
47
+ #define WIFI_SSID "SSID"
48
+ // WiFi password
49
+ #define WIFI_PASSWORD "PASSWORD"
50
+ // InfluxDB v2 server url, e.g. https://eu-central-1-1.aws.cloud2.influxdata.com (Use: InfluxDB UI -> Load Data -> Client Libraries)
51
+ #define INFLUXDB_URL "<%= server %>"
52
+ // InfluxDB v2 server or cloud API authentication token (Use: InfluxDB UI -> Load Data -> Tokens -> <select token>)
53
+ #define INFLUXDB_TOKEN "<%= token %>"
54
+ // InfluxDB v2 organization id (Use: InfluxDB UI -> Settings -> Profile -> <name under tile> )
55
+ #define INFLUXDB_ORG "<%= org %>"
56
+ // InfluxDB v2 bucket name (Use: InfluxDB UI -> Load Data -> Buckets)
57
+ #define INFLUXDB_BUCKET "<%= bucket %>"
58
+
59
+ // Set timezone string according to https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
60
+ // Examples:
61
+ // Pacific Time: "PST8PDT"
62
+ // Eastern: "EST5EDT"
63
+ // Japanesse: "JST-9"
64
+ // Central Europe: "CET-1CEST,M3.5.0,M10.5.0/3"
65
+ #define TZ_INFO "CET-1CEST,M3.5.0,M10.5.0/3"
66
+
67
+ // InfluxDB client instance with preconfigured InfluxCloud certificate
68
+ InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
69
+
70
+ // Data point
71
+ Point sensor("wifi_status");
72
+
73
+ void setup() {
74
+ Serial.begin(115200);
75
+
76
+ // Setup wifi
77
+ WiFi.mode(WIFI_STA);
78
+ wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
79
+
80
+ Serial.print("Connecting to wifi");
81
+ while (wifiMulti.run() != WL_CONNECTED) {
82
+ Serial.print(".");
83
+ delay(100);
84
+ }
85
+ Serial.println();
86
+
87
+ // Add tags
88
+ sensor.addTag("device", DEVICE);
89
+ sensor.addTag("SSID", WiFi.SSID());
90
+
91
+ // Accurate time is necessary for certificate validation and writing in batches
92
+ // For the fastest time sync find NTP servers in your area: https://www.pool.ntp.org/zone/
93
+ // Syncing progress and the time will be printed to Serial.
94
+ timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
95
+
96
+ // Check server connection
97
+ if (client.validateConnection()) {
98
+ Serial.print("Connected to InfluxDB: ");
99
+ Serial.println(client.getServerUrl());
100
+ } else {
101
+ Serial.print("InfluxDB connection failed: ");
102
+ Serial.println(client.getLastErrorMessage());
103
+ }
104
+ }` ,
105
+ writingDataPointCodeSnippet : `void loop() {
106
+ // Clear fields for reusing the point. Tags will remain untouched
107
+ sensor.clearFields();
108
+
109
+ // Store measured value into point
110
+ // Report RSSI of currently connected network
111
+ sensor.addField("rssi", WiFi.RSSI());
112
+
113
+ // Print what are we exactly writing
114
+ Serial.print("Writing: ");
115
+ Serial.println(sensor.toLineProtocol());
116
+
117
+ // If no Wifi signal, try to reconnect it
118
+ if ((WiFi.RSSI() == 0) && (wifiMulti.run() != WL_CONNECTED)) {
119
+ Serial.println("Wifi connection lost");
120
+ }
121
+
122
+ // Write point
123
+ if (!client.writePoint(sensor)) {
124
+ Serial.print("InfluxDB write failed: ");
125
+ Serial.println(client.getLastErrorMessage());
126
+ }
127
+
128
+ //Wait 10s
129
+ Serial.println("Wait 10s");
130
+ delay(10000);
131
+ }` ,
132
+ executeQueryCodeSnippet : `void loop() {
133
+ // Construct a Flux query
134
+ // Query will find the worst RSSI for last hour for each connected WiFi network with this device
135
+ String query = "from(bucket: \\"" INFLUXDB_BUCKET "\\") |> range(start: -1h) |> filter(fn: (r) => r._measurement == \\"wifi_status\\" and r._field == \\"rssi\\"";
136
+ query += " and r.device == \\"" DEVICE "\\")";
137
+ query += "|> min()";
138
+
139
+ // Print ouput header
140
+ Serial.print("==== ");
141
+ Serial.print(selectorFunction);
142
+ Serial.println(" ====");
143
+
144
+ // Print composed query
145
+ Serial.print("Querying with: ");
146
+ Serial.println(query);
147
+
148
+ // Send query to the server and get result
149
+ FluxQueryResult result = client.query(query);
150
+
151
+ // Iterate over rows. Even there is just one row, next() must be called at least once.
152
+ while (result.next()) {
153
+ // Get converted value for flux result column 'SSID'
154
+ String ssid = result.getValueByName("SSID").getString();
155
+ Serial.print("SSID '");
156
+ Serial.print(ssid);
157
+
158
+ Serial.print("' with RSSI ");
159
+ // Get converted value for flux result column '_value' where there is RSSI value
160
+ long value = result.getValueByName("_value").getLong();
161
+ Serial.print(value);
162
+
163
+ // Get converted value for the _time column
164
+ FluxDateTime time = result.getValueByName("_time").getDateTime();
165
+
166
+ // Format date-time for printing
167
+ // Format string according to http://www.cplusplus.com/reference/ctime/strftime/
168
+ String timeStr = time.format("%F %T");
169
+
170
+ Serial.print(" at ");
171
+ Serial.print(timeStr);
172
+
173
+ Serial.println();
174
+ }
175
+
176
+ // Check if there was an error
177
+ if(result.getError() != "") {
178
+ Serial.print("Query result error: ");
179
+ Serial.println(result.getError());
180
+ }
181
+
182
+ // Close the result
183
+ result.close();
184
+ }
185
+ ` ,
186
+ }
187
+
21
188
export const clientCSharpLibrary = {
22
189
id : 'csharp' ,
23
190
name : 'C#' ,
@@ -512,6 +679,7 @@ system.terminate()`,
512
679
}
513
680
514
681
export const clientLibraries : ClientLibrary [ ] = [
682
+ clientArduinoLibrary ,
515
683
clientCSharpLibrary ,
516
684
clientGoLibrary ,
517
685
clientJavaLibrary ,
0 commit comments