File tree Expand file tree Collapse file tree 3 files changed +44
-14
lines changed Expand file tree Collapse file tree 3 files changed +44
-14
lines changed Original file line number Diff line number Diff line change
1
+ /* *
2
+ ESP8266 InfluxDb: InfluxData
3
+
4
+ Purpose: Holds the data of a single measurement.
5
+
6
+ @see
7
+ https://docs.influxdata.com/influxdb/v1.5/concepts/glossary/#measurement
8
+
9
+ @author Tobias Schürg
10
+ */
1
11
2
12
class InfluxData {
3
13
public:
Original file line number Diff line number Diff line change
1
+ /* *
2
+ ESP8266 InfluxDb: Influxdb.cpp
3
+
4
+ Purpose: Helps with sending measurements to an Influx database.
5
+
6
+ @author Tobias Schürg
7
+ */
1
8
#include " InfluxDb.h"
2
9
#include " Arduino.h"
3
10
@@ -24,26 +31,33 @@ void Influxdb::setDb(String db) {
24
31
25
32
// TODO: set db with user & password
26
33
34
+ /* *
35
+ * Prepare a measurement to be sent.
36
+ */
27
37
void Influxdb::prepare (InfluxData data) { prepared.push_back (data); }
28
38
29
- boolean Influxdb::post () {
39
+ /* *
40
+ * Write all prepared measurements into the db.
41
+ */
42
+ boolean Influxdb::write () {
30
43
String data = " " ;
31
44
for (auto const & i : prepared) {
32
45
data = (data == " " ) ? (i.toString ()) : (data + " \n " + i.toString ());
33
46
}
34
- return post (data);
47
+ prepared.clear ();
48
+ return write (data);
35
49
}
36
50
37
51
/* *
38
- * Send a single measurement to the InfluxDb .
52
+ * Write a single measurement into the db .
39
53
*/
40
- boolean Influxdb::post (InfluxData data) { return post (data.toString ()); }
54
+ boolean Influxdb::write (InfluxData data) { return write (data.toString ()); }
41
55
42
56
/* *
43
57
* Send raw data to InfluxDb.
44
58
*/
45
- boolean Influxdb::post (String data) {
46
- Serial.print (" -> writing to " + _db + " : " );
59
+ boolean Influxdb::write (String data) {
60
+ Serial.print (" -> writing to " + _db + " :\n " );
47
61
Serial.println (data);
48
62
49
63
int httpResponseCode = http.POST (data);
Original file line number Diff line number Diff line change 1
1
2
- #include " Arduino.h"
2
+ /* *
3
+ ESP8266 InfluxDb: Influxdb.h
4
+
5
+ Purpose: Helps with sending measurements to an Influx database.
6
+
7
+ @author Tobias Schürg
8
+ */
3
9
#include < ESP8266HTTPClient.h>
4
10
#include < list>
11
+ #include " Arduino.h"
5
12
6
13
#include " InfluxData.h"
7
14
8
- class Influxdb
9
- {
10
- public:
15
+ class Influxdb {
16
+ public:
11
17
Influxdb (String host, uint16_t port = 8086 );
12
18
13
19
void setDb (String db);
14
20
15
21
void prepare (InfluxData data);
16
- boolean post ();
22
+ boolean write ();
17
23
18
- boolean post (InfluxData data);
19
- boolean post (String data);
24
+ boolean write (InfluxData data);
25
+ boolean write (String data);
20
26
21
- private:
27
+ private:
22
28
HTTPClient http;
23
29
String _host;
24
30
uint16_t _port;
You can’t perform that action at this time.
0 commit comments