forked from hwwong/ESP_influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESPinfluxdb.h
65 lines (46 loc) · 1007 Bytes
/
ESPinfluxdb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Influxdb library
MIT license
Written by HW Wong
*/
#ifndef INFLUXDB_H
#define INFLUXDB_H
#include "Arduino.h"
#if defined(ESP8266)
#include <ESP8266HTTPClient.h>
#elif defined(ESP32)
#include <HTTPClient.h>
#endif
enum DB_RESPONSE {DB_SUCCESS, DB_ERROR, DB_CONNECT_FAILED};
// Url encode function
String URLEncode(String msg);
class dbMeasurement
{
public:
dbMeasurement(String m);
String measurement;
void addField(String key, float value);
void addTag(String key, String value);
void empty();
String postString();
private:
String _data;
String _tag;
};
class Influxdb
{
public:
Influxdb(const char* host, uint16_t port);
DB_RESPONSE opendb(String db);
DB_RESPONSE opendb(String db, String user, String password);
DB_RESPONSE write(dbMeasurement data);
DB_RESPONSE write(String data);
DB_RESPONSE query(String sql);
//uint8_t createDatabase(char *dbname);
DB_RESPONSE response();
private:
String _port;
String _host;
String _db;
DB_RESPONSE _response = DB_ERROR;
};
#endif