Make influxdb and serial feature configurable
This commit is contained in:
parent
be334245ff
commit
ed913d740e
3 changed files with 38 additions and 25 deletions
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
// Enable/Disable features
|
// Enable/Disable features
|
||||||
//#define WEBUPDATER_FEATURE
|
//#define WEBUPDATER_FEATURE
|
||||||
|
#define INFLUXDB_FEATURE
|
||||||
|
#define SERIAL_FEATURE
|
||||||
#define BATTERY_POWERED
|
#define BATTERY_POWERED
|
||||||
#define SENSOR_WIND
|
#define SENSOR_WIND
|
||||||
#define SENSOR_APDS9960
|
#define SENSOR_APDS9960
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
// folder in order to use the libs. (File -> Preferences -> Sketchbook Location)
|
// folder in order to use the libs. (File -> Preferences -> Sketchbook Location)
|
||||||
#include <WiFiClient.h> // WiFiClient
|
#include <WiFiClient.h> // WiFiClient
|
||||||
#include <WiFiManager.h> // WiFiManager
|
#include <WiFiManager.h> // WiFiManager
|
||||||
#include <ESP8266Influxdb.h> // https://github.com/hwwong/ESP8266Influxdb auchecken und den ordner in das arduino\library verzeichnis kopieren
|
|
||||||
|
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -55,7 +54,6 @@ uint16_t update_sensor_cnt = 0;
|
||||||
uint16_t update_webserver_cnt = 0;
|
uint16_t update_webserver_cnt = 0;
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
|
||||||
|
|
||||||
#ifdef WEBUPDATER_FEATURE
|
#ifdef WEBUPDATER_FEATURE
|
||||||
String localIP = "127.0.0.1";
|
String localIP = "127.0.0.1";
|
||||||
|
@ -76,7 +74,7 @@ void setup() {
|
||||||
//delay(2000);
|
//delay(2000);
|
||||||
//ESP.reset();
|
//ESP.reset();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#if defined(DEBUG) || defined(SERIAL_FEATURE)
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -108,8 +106,9 @@ void setup() {
|
||||||
|
|
||||||
debug("Connected!");
|
debug("Connected!");
|
||||||
|
|
||||||
// Init variables to influxdb config - doesn't talk to database
|
#ifdef INFLUXDB_FEATURE
|
||||||
influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS);
|
influxdb_begin();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialize and configure the sensors
|
// Initialize and configure the sensors
|
||||||
#ifdef SENSOR_APDS9930
|
#ifdef SENSOR_APDS9930
|
||||||
|
@ -242,24 +241,30 @@ void _loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("");
|
#ifdef SERIAL_FEATURE
|
||||||
debug("Current readings:");
|
logToSerial(currentSensorData);
|
||||||
debug("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C");
|
#endif
|
||||||
debug("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + " %");
|
|
||||||
debug("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lux");
|
|
||||||
debug("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " km/h");
|
|
||||||
debug("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
|
|
||||||
debug("Bat Voltage: " + String(currentSensorData[SENSOR_BAT_VOLTAGE]) + " V");
|
|
||||||
debug("Bat charge state: " + String(currentSensorData[SENSOR_BATCHARGESTATE]));
|
|
||||||
debug("Energy saving: " + String(currentSensorData[SENSOR_ESAVEMODE]));
|
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
#ifdef INFLUXDB_FEATURE
|
||||||
|
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WEBUPDATER_FEATURE
|
#ifdef WEBUPDATER_FEATURE
|
||||||
setSensorData(DEVICE_NAME, localIP, currentSensorData);
|
setSensorData(DEVICE_NAME, localIP, currentSensorData);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************//
|
void logToSerial(float sensorValues[]) {
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println("Current readings:");
|
||||||
|
Serial.println("Temperature: " + String(sensorValues[SENSOR_TEMPERATURE]) + " °C");
|
||||||
|
Serial.println("Humidity: " + String(sensorValues[SENSOR_HUMIDITY]) + " %");
|
||||||
|
Serial.println("Light: " + String(sensorValues[SENSOR_LIGHT]) + " Lux");
|
||||||
|
Serial.println("Windspeed: " + String(sensorValues[SENSOR_WINDSPEED]) + " km/h");
|
||||||
|
Serial.println("Pressure: " + String(sensorValues[SENSOR_PRESSURE]) + " hPa");
|
||||||
|
Serial.println("Bat Voltage: " + String(sensorValues[SENSOR_BAT_VOLTAGE]) + " V");
|
||||||
|
Serial.println("Bat charge state: " + String(sensorValues[SENSOR_BATCHARGESTATE]));
|
||||||
|
Serial.println("Energy saving: " + String(sensorValues[SENSOR_ESAVEMODE]));
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
void pushToInfluxDB(String device, float sensorValues[]) {
|
#include <ESP8266Influxdb.h> // https://github.com/hwwong/ESP8266Influxdb
|
||||||
|
|
||||||
|
Influxdb _influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
||||||
|
|
||||||
|
void influxdb_begin() {
|
||||||
|
// Init variables to influxdb config - doesn't talk to database
|
||||||
|
_influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pushToInfluxDB(String device, float sensorValues[]) {
|
||||||
uint8_t tries = 0;
|
uint8_t tries = 0;
|
||||||
boolean addComma = false;
|
boolean addComma = false;
|
||||||
|
|
||||||
|
@ -59,12 +67,10 @@ void pushToInfluxDB(String device, float sensorValues[]) {
|
||||||
addComma = true;
|
addComma = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
debug(msg);
|
||||||
Serial.println(msg);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tries++;
|
tries++;
|
||||||
influxdb.write(msg);
|
_influxdb.write(msg);
|
||||||
} while (influxdb.response() != DB_SUCCESS and tries < 5);
|
} while (_influxdb.response() != DB_SUCCESS and tries < 5);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue