Skip to content

Commit e9d9833

Browse files
committed
Let HTTPClient construct the url.
1 parent c0a7927 commit e9d9833

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

InfluxDb.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#include "Arduino.h"
22
#include "InfluxDb.h"
33

4-
Influxdb::Influxdb(const char *host, uint16_t port)
4+
Influxdb::Influxdb(String host, uint16_t port)
55
{
6-
_port = String(port);
7-
_host = String(host);
6+
_port = port;
7+
_host = host;
88
}
99

10-
void Influxdb::setDb(const char *db)
10+
void Influxdb::setDb(String db)
1111
{
1212
_db = String(db);
1313
}
1414

15+
// TODO: set db with user
16+
17+
/**
18+
* Send a single measurement to the InfluxDb.
19+
**/
1520
boolean Influxdb::post(InfluxData data)
1621
{
1722
return post(data.toString());
@@ -22,16 +27,18 @@ boolean Influxdb::post(String data)
2227
Serial.print("write ");
2328
Serial.println(data);
2429

30+
// TODO: check if the client can be reused
2531
HTTPClient http;
26-
http.begin("http://" + _host + ":" + _port + "/write?db=" + _db);
32+
http.begin(_host, _port, "/write?db=" + _db);
2733
http.addHeader("Content-Type", "text/plain");
34+
//
2835

2936
int httpResponseCode = http.POST(data);
30-
Serial.print(" -> Response code ");
31-
Serial.println(httpResponseCode);
37+
Serial.print(" -> Response: ");
38+
Serial.print(httpResponseCode);
3239

3340
String response = http.getString();
34-
Serial.println(" -> Response: \"" + response + "\".");
41+
Serial.println(" -> \"" + response + "\"");
3542

3643
boolean success;
3744
if (httpResponseCode == 204)

InfluxDb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
class Influxdb
77
{
88
public:
9-
Influxdb(const char *host, uint16_t port);
9+
Influxdb(String host, uint16_t port);
1010

11-
void setDb(const char *db);
11+
void setDb(String db);
1212

1313
boolean post(InfluxData data);
1414
boolean post(String data);
1515

1616
private:
17-
String _port;
1817
String _host;
18+
uint16_t _port;
1919
String _db;
2020
};

0 commit comments

Comments
 (0)