|
1 | 1 | # ESP8266_Influx_DB
|
| 2 | + |
| 3 | +Library for NodeMcu / ESP8266 (and Arduino?) for sending measurements to an Influx database. |
| 4 | + |
| 5 | +## Initialization |
| 6 | +``` |
| 7 | + #define INFLUXDB_HOST "192.168.0.32" |
| 8 | + #define INFLUXDB_PORT "1337" |
| 9 | + #define INFLUXDB_DATABASE "test" |
| 10 | +
|
| 11 | + // TODO: connect to WiFi |
| 12 | +
|
| 13 | + Influxdb influx(INFLUXDB_HOST); // port defaults to 8086 |
| 14 | + // or |
| 15 | + Influxdb influx(INFLUXDB_HOST, INFLUXDB_PORT); |
| 16 | +
|
| 17 | + // set the target database |
| 18 | + influx.setDb(INFLUXDB_DATABASE); |
| 19 | +``` |
| 20 | + |
| 21 | +## Sending a single measurement |
| 22 | +**Using an InfluxData object:** |
| 23 | +``` |
| 24 | +// create a measurement object |
| 25 | +InfluxData measurement ("temperature"); |
| 26 | +measurement.addTag("device", d2); |
| 27 | +measurement.addTag("sensor", "dht11"); |
| 28 | +measurement.addValue("value", 24.0); |
| 29 | +
|
| 30 | +// write it into db |
| 31 | +influx.write(measurement); |
| 32 | +``` |
| 33 | + |
| 34 | +**Using raw-data** |
| 35 | +``` |
| 36 | + influx.write("temperature,device=d2,sensor=dht11 value=24.0") |
| 37 | +``` |
| 38 | + |
| 39 | +## Write multiple data points at once |
| 40 | +Batching measurements and send them with a single request will result in a much higher performance. |
| 41 | +``` |
| 42 | +
|
| 43 | +InfluxData measurement1 = readTemperature() |
| 44 | +influx.prepare(measurement1) |
| 45 | +
|
| 46 | +InfluxData measurement2 = readLight() |
| 47 | +influx.prepare(measurement2) |
| 48 | +
|
| 49 | +InfluxData measurement3 = readVoltage() |
| 50 | +influx.prepare(measurement3) |
| 51 | +
|
| 52 | +// writes all prepared measurements with a single request into db. |
| 53 | +boolean success = influx.write(); |
| 54 | +``` |
| 55 | + |
| 56 | +## Documentation |
| 57 | +For the documentation see [html/class_influxdb.html](html/class_influxdb.html) (only works locally). |
0 commit comments