Skip to content

Commit 2a54395

Browse files
committed
support v2 cloud https
1 parent bd4dad0 commit 2a54395

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

InfluxDb.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,26 @@ void Influxdb::setVersion(uint16_t version){
8181
begin();
8282
}
8383

84+
/**
85+
* Set servers finger print for HTTPS v2 Influx proto
86+
* @param version accepts 1 for version 1.x or 2 for version 2.x
87+
*/
88+
void Influxdb::setFingerPrint(char *fingerPrint){
89+
_fingerPrint = fingerPrint;
90+
begin();
91+
}
92+
8493
void Influxdb::begin() {
8594
// TODO: recreate HttpClient on db change?
8695
if(_db_v == 2){
87-
http.begin(_host, _port, "/api/v2/write?org=" + _org + "&bucket=" + _bucket);
96+
if (_port == 443) {
97+
if (_fingerPrint)
98+
client.setFingerprint(_fingerPrint);
99+
http.begin(client, _host, _port, "/api/v2/write?org=" + _org + "&bucket=" + _bucket,
100+
true);
101+
} else {
102+
http.begin(_host, _port, "/api/v2/write?org=" + _org + "&bucket=" + _bucket);
103+
}
88104
http.addHeader("Authorization", "Token " + _token);
89105
} else {
90106
if (_user && _pass) {

InfluxDb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
#if defined(ESP8266)
1010
#include <ESP8266HTTPClient.h>
11+
#include <WiFiClientSecure.h>
1112
#elif defined(ESP32)
1213
#include <WiFi.h>
1314
#include <HTTPClient.h>
@@ -30,6 +31,7 @@ class Influxdb {
3031
void setOrg(String org);
3132
void setToken(String token);
3233
void setPort(uint16_t port);
34+
void setFingerPrint(char *fingerPrint);
3335

3436
void prepare(InfluxData data);
3537
boolean write();
@@ -39,6 +41,7 @@ class Influxdb {
3941

4042
private:
4143
HTTPClient http;
44+
WiFiClientSecure client;
4245
String _host;
4346
uint16_t _port;
4447
String _db;
@@ -48,6 +51,7 @@ class Influxdb {
4851
String _org;
4952
String _token;
5053
uint16_t _db_v;
54+
char *_fingerPrint;
5155

5256
std::list<InfluxData> prepared;
5357

0 commit comments

Comments
 (0)