Arduino influxdb

Iš Žinynas.
Jump to navigation Jump to search
/* Legacy protocol v1 implementation (c) e1z0 */
#include <InfluxDb.h>
#define TZ_INFO "EET-2EEST,M3.5.0/3,M10.5.0/4" // time zone Europe/Vilnius https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
Influxdb influx(INFLUXDB_HOST, INFLUXDB_PORT);
InfluxData measurement ("ltlhs");

void setup() {
    configTzTime(TZ_INFO "192.168.13.254","pool.ntp.org", "time.nis.gov");
    influx.setDbAuth(INFLUXDB_DB_NAME, INFLUXDB_USER, INFLUXDB_PASS);
    // Check server connection
    if (influx.validateConnection()) {
        Serial.print("Connected to InfluxDB: ");
        Serial.println(influx.getServerUrl());
    } else {
        Serial.print("InfluxDB connection failed: ");
        Serial.println(influx.getLastErrorMessage());
     }
}

void loop() {
    measurement.clearFields();
    measurement.clearTags();
    measurement.addTag("device", DEV_ID);
    measurement.addValue("battery_level",bat_perc);
    measurement.addValue("battery_voltage",bat_vol);
    measurement.addValue("sol_voltage",sol_vol);
    measurement.addValue("temp", temperature);
    measurement.addValue("humidity",humidity);
    if (!influx.writePoint(measurement)) {
        Serial.print("InfluxDB write failed: ");
        Serial.println(influx.getLastErrorMessage());
    }
    influx.flushBuffer();
}