Skip to content

Commit 33571d0

Browse files
authored
Merge pull request #134 from bonitoo-io/fix/secure-doc-demos
fix: secure doc, demos
2 parents 3fd95d8 + bcb8086 commit 33571d0

File tree

9 files changed

+100
-55
lines changed

9 files changed

+100
-55
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Changelog
2+
## 3.x.x [in progress]
3+
### Documentation
4+
- [#134](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/134):
5+
- Added untrusted connection (skipping certificate validation) info to Readme
6+
- `SecureWrite` and `SecureBatchWrite` demos enhanced with example about using untrusted connection
7+
- Various fixes of typos
8+
29
## 3.7.0 [2020-12-24]
310
### Features
411
- [#125](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/124) - Added credentials to the InfluxDB 1.x validation endpoint (/ping). To leverage this, [enable ping authentication](https://docs.influxdata.com/influxdb/v1.8/administration/config/#ping-auth-enabled-false)
@@ -40,7 +47,7 @@
4047

4148
## 3.4.0 [2020-10-02]
4249
### Features
43-
- [#89](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/89) - ESP8266 only - Added Max Fragment Length Negotiation for TLS communicaton to reduce memory allocation. If server supports MFLN, it saves ~10kB. Standalone InfluxDB OSS server doesn't support MFLN, Cloud yes. To leverage MFLN for standalone OSS, a reverse proxy needs to be used.
50+
- [#89](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/89) - ESP8266 only - Added Max Fragment Length Negotiation for TLS communication to reduce memory allocation. If server supports MFLN, it saves ~10kB. Standalone InfluxDB OSS server doesn't support MFLN, Cloud yes. To leverage MFLN for standalone OSS, a reverse proxy needs to be used.
4451
- [#91](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/91) - Improved API for settings of write and HTTP options:
4552
- Introduced `WriteOptions` to wrap the write related options (write precision, batch-size, etc). It offers fluent style API allowing to change only the required options. `InfluxDBClient` has overloaded `setWriteOptions(const WriteOptions& writeOptions)` method.
4653
- Introduced `HTTPOptions` to wrap the HTTP related options (e.g. reusing connection). It offers fluent style API allowing to change only the required options. `InfluxDBClient` has `setHTTPOptions(const HTTPOptions& httpOptions)` method.
@@ -62,7 +69,7 @@
6269
- [NEW] Added possibility skip server certification validation (`setInsecure()` method)
6370
- [NEW] Added possibility to query flux on secured InfluxDB 1.8 using V1 approach
6471
- [NEW] `validateConnection()` can be used also for the [forward compatibility](https://docs.influxdata.com/influxdb/latest/tools/api/#influxdb-2-0-api-compatibility-endpoints) connection to InfluxDB 1.8
65-
- [FIX] More precice default timestamp generating, up to microseconds
72+
- [FIX] More precise default timestamp generating, up to microseconds
6673
- [FIX] Debug compilation error
6774
- [FIX] SecureBatchWrite compile error
6875

@@ -91,6 +98,6 @@
9198
## Version 3.0.0 (2020-02-11)
9299
- New API with similar keywords as other official InfluxDB clients
93100
- Richer set of data types for fields and timestamp methods
94-
- Advanced features, such as implicit batching, automatic retrying on server backpressure and connection failure, along with secured communication over TLS supported for both devices and authentication
101+
- Advanced features, such as implicit batching, automatic retrying on server back-pressure and connection failure, along with secured communication over TLS supported for both devices and authentication
95102
- Special characters escaping
96103
- Backward support for original API of V1/V2

README.md

Lines changed: 61 additions & 36 deletions
Large diffs are not rendered by default.

examples/BasicWrite/BasicWrite.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void setup() {
5353
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
5454
while (wifiMulti.run() != WL_CONNECTED) {
5555
Serial.print(".");
56-
delay(100);
56+
delay(500);
5757
}
5858
Serial.println();
5959

@@ -83,8 +83,9 @@ void loop() {
8383
Serial.print("Writing: ");
8484
Serial.println(client.pointToLineProtocol(sensor));
8585
// If no Wifi signal, try to reconnect it
86-
if ((WiFi.RSSI() == 0) && (wifiMulti.run() != WL_CONNECTED))
86+
if (wifiMulti.run() != WL_CONNECTED) {
8787
Serial.println("Wifi connection lost");
88+
}
8889
// Write point
8990
if (!client.writePoint(sensor)) {
9091
Serial.print("InfluxDB write failed: ");

examples/QueryAggregated/QueryAggregated.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* QueryAggregated Example code for InfluxDBClient library for Arduino.
33
*
4-
* This example demonstrates querying basic aggreagated statistic parameters of WiFi signal level measured and stored in BasicWrite and SecureWrite examples.
4+
* This example demonstrates querying basic aggregated statistic parameters of WiFi signal level measured and stored in BasicWrite and SecureWrite examples.
55
*
66
* Demonstrates connection to any InfluxDB instance accesible via:
77
* - unsecured http://...

examples/QueryTable/QueryTable.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void loop() {
119119
Serial.print(" ");
120120
// Print values of the row
121121
for(FluxValue &val: result.getValues()) {
122-
// Check wheter the value is null
122+
// Check whether the value is null
123123
if(!val.isNull()) {
124124
// Use raw string, unconverted value
125125
Serial.print(val.getRawValue());

examples/SecureBatchWrite/SecureBatchWrite.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ESP8266WiFiMulti wifiMulti;
4444
// Japanesse: "JST-9"
4545
// Central Europe: "CET-1CEST,M3.5.0,M10.5.0/3"
4646
#define TZ_INFO "CET-1CEST,M3.5.0,M10.5.0/3"
47-
// NTP servers the for time syncronozation.
47+
// NTP servers the for time synchronization.
4848
// For the fastest time sync find NTP servers in your area: https://www.pool.ntp.org/zone/
4949
#define NTP_SERVER1 "pool.ntp.org"
5050
#define NTP_SERVER2 "time.nis.gov"
@@ -54,6 +54,8 @@ ESP8266WiFiMulti wifiMulti;
5454

5555
// InfluxDB client instance with preconfigured InfluxCloud certificate
5656
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
57+
// InfluxDB client instance without preconfigured InfluxCloud certificate for insecure connection
58+
//InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN);
5759

5860
// Data point
5961
Point sensorStatus("wifi_status");
@@ -71,14 +73,17 @@ void setup() {
7173
Serial.print("Connecting to wifi");
7274
while (wifiMulti.run() != WL_CONNECTED) {
7375
Serial.print(".");
74-
delay(100);
76+
delay(500);
7577
}
7678
Serial.println();
7779

7880
// Add tags
7981
sensorStatus.addTag("device", DEVICE);
8082
sensorStatus.addTag("SSID", WiFi.SSID());
8183

84+
// Alternatively, set insecure connection to skip server certificate validation
85+
//client.setInsecure(true);
86+
8287
// Accurate time is necessary for certificate validation and writing in batches
8388
// Syncing progress and the time will be printed to Serial.
8489
timeSync(TZ_INFO, NTP_SERVER1, NTP_SERVER2);
@@ -143,8 +148,9 @@ void loop() {
143148
sensorStatus.clearFields();
144149

145150
// If no Wifi signal, try to reconnect it
146-
if ((WiFi.RSSI() == 0) && (wifiMulti.run() != WL_CONNECTED))
151+
if (wifiMulti.run() != WL_CONNECTED) {
147152
Serial.println("Wifi connection lost");
153+
}
148154

149155
// End of the iteration - force write of all the values into InfluxDB as single transaction
150156
Serial.println("Flushing data into InfluxDB");

examples/SecureWrite/SecureWrite.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ ESP8266WiFiMulti wifiMulti;
4747

4848
// InfluxDB client instance with preconfigured InfluxCloud certificate
4949
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
50+
// InfluxDB client instance without preconfigured InfluxCloud certificate for insecure connection
51+
//InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN);
5052

5153
// Data point
5254
Point sensor("wifi_status");
@@ -61,14 +63,17 @@ void setup() {
6163
Serial.print("Connecting to wifi");
6264
while (wifiMulti.run() != WL_CONNECTED) {
6365
Serial.print(".");
64-
delay(100);
66+
delay(500);
6567
}
6668
Serial.println();
6769

6870
// Add tags
6971
sensor.addTag("device", DEVICE);
7072
sensor.addTag("SSID", WiFi.SSID());
7173

74+
// Alternatively, set insecure connection to skip server certificate validation
75+
//client.setInsecure(true);
76+
7277
// Accurate time is necessary for certificate validation and writing in batches
7378
// For the fastest time sync find NTP servers in your area: https://www.pool.ntp.org/zone/
7479
// Syncing progress and the time will be printed to Serial.
@@ -93,8 +98,9 @@ void loop() {
9398
Serial.print("Writing: ");
9499
Serial.println(client.pointToLineProtocol(sensor));
95100
// If no Wifi signal, try to reconnect it
96-
if ((WiFi.RSSI() == 0) && (wifiMulti.run() != WL_CONNECTED))
101+
if (wifiMulti.run() != WL_CONNECTED) {
97102
Serial.println("Wifi connection lost");
103+
}
98104
// Write point
99105
if (!client.writePoint(sensor)) {
100106
Serial.print("InfluxDB write failed: ");

src/InfluxDbClient.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,21 @@ bool InfluxDBClient::init() {
131131
if(https) {
132132
#if defined(ESP8266)
133133
BearSSL::WiFiClientSecure *wifiClientSec = new BearSSL::WiFiClientSecure;
134-
if(_certInfo && strlen_P(_certInfo) > 0) {
134+
if (_insecure) {
135+
wifiClientSec->setInsecure();
136+
} else if(_certInfo && strlen_P(_certInfo) > 0) {
135137
if(strlen_P(_certInfo) > 60 ) { //differentiate fingerprint and cert
136138
_cert = new BearSSL::X509List(_certInfo);
137139
wifiClientSec->setTrustAnchors(_cert);
138140
} else {
139141
wifiClientSec->setFingerprint(_certInfo);
140142
}
141143
}
142-
if (_insecure) {
143-
wifiClientSec->setInsecure();
144-
}
144+
145145
checkMFLN(wifiClientSec, _serverUrl);
146146
#elif defined(ESP32)
147147
WiFiClientSecure *wifiClientSec = new WiFiClientSecure;
148-
if(_certInfo && strlen_P(_certInfo) > 0) {
148+
if(!_insecure && _certInfo && strlen_P(_certInfo) > 0) {
149149
wifiClientSec->setCACert(_certInfo);
150150
}
151151
#endif

src/InfluxDbClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class InfluxDBClient {
8181
InfluxDBClient(const char *serverUrl, const char *org, const char *bucket, const char *authToken, const char *certInfo);
8282
// Clears instance.
8383
~InfluxDBClient();
84-
// Allows insecure connection. setInsecure must be called before calling any method initiating a connection to server.
85-
// Works only on ESP8266. ESP32 allows unsecured connections by default (status for latest 1.0.4 ESP32 Arduino SDK).
84+
// Allows insecure connection by skiping server certificate validation.
85+
// setInsecure must be called before calling any method initiating a connection to server.
8686
void setInsecure(bool value);
8787
// precision - timestamp precision of written data
8888
// batchSize - number of points that will be written to the databases at once. Default 1 - writes immediately

0 commit comments

Comments
 (0)