File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Original file line number Diff line number Diff line change 1
1
#include " Arduino.h"
2
2
#include " InfluxDb.h"
3
3
4
- Influxdb::Influxdb (const char * host, uint16_t port)
4
+ Influxdb::Influxdb (String host, uint16_t port)
5
5
{
6
- _port = String ( port) ;
7
- _host = String ( host) ;
6
+ _port = port;
7
+ _host = host;
8
8
}
9
9
10
- void Influxdb::setDb (const char * db)
10
+ void Influxdb::setDb (String db)
11
11
{
12
12
_db = String (db);
13
13
}
14
14
15
+ // TODO: set db with user
16
+
17
+ /* *
18
+ * Send a single measurement to the InfluxDb.
19
+ **/
15
20
boolean Influxdb::post (InfluxData data)
16
21
{
17
22
return post (data.toString ());
@@ -22,16 +27,18 @@ boolean Influxdb::post(String data)
22
27
Serial.print (" write " );
23
28
Serial.println (data);
24
29
30
+ // TODO: check if the client can be reused
25
31
HTTPClient http;
26
- http.begin (" http:// " + _host + " : " + _port + " /write?db=" + _db);
32
+ http.begin (_host, _port, " /write?db=" + _db);
27
33
http.addHeader (" Content-Type" , " text/plain" );
34
+ //
28
35
29
36
int httpResponseCode = http.POST (data);
30
- Serial.print (" -> Response code " );
31
- Serial.println (httpResponseCode);
37
+ Serial.print (" -> Response: " );
38
+ Serial.print (httpResponseCode);
32
39
33
40
String response = http.getString ();
34
- Serial.println (" -> Response: \" " + response + " \" . " );
41
+ Serial.println (" -> \" " + response + " \" " );
35
42
36
43
boolean success;
37
44
if (httpResponseCode == 204 )
Original file line number Diff line number Diff line change 6
6
class Influxdb
7
7
{
8
8
public:
9
- Influxdb (const char * host, uint16_t port);
9
+ Influxdb (String host, uint16_t port);
10
10
11
- void setDb (const char * db);
11
+ void setDb (String db);
12
12
13
13
boolean post (InfluxData data);
14
14
boolean post (String data);
15
15
16
16
private:
17
- String _port;
18
17
String _host;
18
+ uint16_t _port;
19
19
String _db;
20
20
};
You can’t perform that action at this time.
0 commit comments