Skip to content

Commit 6b73798

Browse files
committed
feat: added insecure setting example
1 parent 62bf88c commit 6b73798

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

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: ");

0 commit comments

Comments
 (0)