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+ */
111
212class InfluxData {
313 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+ */
18#include " InfluxDb.h"
29#include " Arduino.h"
310
@@ -24,26 +31,33 @@ void Influxdb::setDb(String db) {
2431
2532// TODO: set db with user & password
2633
34+ /* *
35+ * Prepare a measurement to be sent.
36+ */
2737void Influxdb::prepare (InfluxData data) { prepared.push_back (data); }
2838
29- boolean Influxdb::post () {
39+ /* *
40+ * Write all prepared measurements into the db.
41+ */
42+ boolean Influxdb::write () {
3043 String data = " " ;
3144 for (auto const & i : prepared) {
3245 data = (data == " " ) ? (i.toString ()) : (data + " \n " + i.toString ());
3346 }
34- return post (data);
47+ prepared.clear ();
48+ return write (data);
3549}
3650
3751/* *
38- * Send a single measurement to the InfluxDb .
52+ * Write a single measurement into the db .
3953 */
40- boolean Influxdb::post (InfluxData data) { return post (data.toString ()); }
54+ boolean Influxdb::write (InfluxData data) { return write (data.toString ()); }
4155
4256/* *
4357 * Send raw data to InfluxDb.
4458 */
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 " );
4761 Serial.println (data);
4862
4963 int httpResponseCode = http.POST (data);
Original file line number Diff line number Diff line change 11
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+ */
39#include < ESP8266HTTPClient.h>
410#include < list>
11+ #include " Arduino.h"
512
613#include " InfluxData.h"
714
8- class Influxdb
9- {
10- public:
15+ class Influxdb {
16+ public:
1117 Influxdb (String host, uint16_t port = 8086 );
1218
1319 void setDb (String db);
1420
1521 void prepare (InfluxData data);
16- boolean post ();
22+ boolean write ();
1723
18- boolean post (InfluxData data);
19- boolean post (String data);
24+ boolean write (InfluxData data);
25+ boolean write (String data);
2026
21- private:
27+ private:
2228 HTTPClient http;
2329 String _host;
2430 uint16_t _port;
You can’t perform that action at this time.
0 commit comments