ESP32 / ESP8266 & BME280 / SHT2x sensor with InfluxDB support
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SimpleInflux.h 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SimpleInflux.h
  3. *
  4. * ESP8266 / ESP32 Environmental Sensor
  5. *
  6. * ----------------------------------------------------------------------------
  7. * "THE BEER-WARE LICENSE" (Revision 42):
  8. * <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  9. * you can do whatever you want with this stuff. If we meet some day, and you
  10. * think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  11. * ----------------------------------------------------------------------------
  12. */
  13. #ifndef __ESP_SIMPLE_INFLUX__
  14. #define __ESP_SIMPLE_INFLUX__
  15. #define SIMPLE_INFLUX_MAX_ELEMENTS 3
  16. class InfluxData {
  17. public:
  18. InfluxData(const char *name) : data_name(name), tag_count(0), value_count(0) { }
  19. void addTag(const char *name, const char *value);
  20. void addTag(const char *name, String &value) { addTag(name, value.c_str()); }
  21. void addValue(const char *name, double value);
  22. int tagCount() { return tag_count; }
  23. const char *tagName(int tag) { return tag_name[tag < tag_count ? tag : 0]; }
  24. const char *tagValue(int tag) { return tag_value[tag < tag_count ? tag : 0]; }
  25. int valueCount() { return value_count; }
  26. const char *valueName(int val) { return value_name[val < value_count ? val : 0]; }
  27. double valueValue(int val) { return value_value[val < value_count ? val : 0]; }
  28. const char *dataName() { return data_name; }
  29. void setName(const char *n) { data_name = n; }
  30. void clear() { tag_count = 0; value_count = 0;}
  31. private:
  32. const char *data_name;
  33. const char *tag_name[SIMPLE_INFLUX_MAX_ELEMENTS];
  34. const char *tag_value[SIMPLE_INFLUX_MAX_ELEMENTS];
  35. int tag_count;
  36. const char *value_name[SIMPLE_INFLUX_MAX_ELEMENTS];
  37. double value_value[SIMPLE_INFLUX_MAX_ELEMENTS];
  38. int value_count;
  39. };
  40. class Influxdb {
  41. public:
  42. Influxdb(const char *host, int port) : db_host(host), db_port(port) { }
  43. void setDb(const char *db) { db_name = db; }
  44. boolean write(InfluxData &data);
  45. private:
  46. const char *db_host;
  47. int db_port;
  48. const char *db_name;
  49. };
  50. #endif // __ESP_SIMPLE_INFLUX__