Browse Source

Make influxdb and serial feature configurable

Florian Eitel 1 year ago
parent
commit
ed913d740e
No account linked to committer's email address
3 changed files with 38 additions and 25 deletions
  1. 2
    0
      firmware/config_user.h.example
  2. 24
    19
      firmware/firmware.ino
  3. 12
    6
      firmware/influxdb.ino

+ 2
- 0
firmware/config_user.h.example View File

@@ -9,6 +9,8 @@
9 9
 
10 10
 // Enable/Disable features
11 11
 //#define WEBUPDATER_FEATURE
12
+#define INFLUXDB_FEATURE
13
+#define SERIAL_FEATURE
12 14
 #define BATTERY_POWERED
13 15
 #define SENSOR_WIND
14 16
 #define SENSOR_APDS9960

+ 24
- 19
firmware/firmware.ino View File

@@ -17,7 +17,6 @@
17 17
 // folder in order to use the libs. (File -> Preferences -> Sketchbook Location)
18 18
 #include <WiFiClient.h>          // WiFiClient
19 19
 #include <WiFiManager.h>         // WiFiManager
20
-#include <ESP8266Influxdb.h>     // https://github.com/hwwong/ESP8266Influxdb auchecken und den ordner in das arduino\library verzeichnis kopieren
21 20
 
22 21
 // Project includes
23 22
 #include "config.h"
@@ -55,7 +54,6 @@ uint16_t update_sensor_cnt      = 0;
55 54
 uint16_t update_webserver_cnt   = 0;
56 55
 
57 56
 WiFiManager wifiManager;
58
-Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
59 57
 
60 58
 #ifdef WEBUPDATER_FEATURE
61 59
 String localIP = "127.0.0.1";
@@ -76,7 +74,7 @@ void setup() {
76 74
   //delay(2000);
77 75
   //ESP.reset();
78 76
 
79
-#ifdef DEBUG
77
+#if defined(DEBUG) || defined(SERIAL_FEATURE)
80 78
   Serial.begin(115200);
81 79
 #endif
82 80
 
@@ -108,8 +106,9 @@ void setup() {
108 106
 
109 107
   debug("Connected!");
110 108
 
111
-  // Init variables to influxdb config - doesn't talk to database
112
-  influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS);
109
+#ifdef INFLUXDB_FEATURE
110
+  influxdb_begin();
111
+#endif
113 112
 
114 113
   // Initialize and configure the sensors
115 114
 #ifdef SENSOR_APDS9930
@@ -242,24 +241,30 @@ void _loop() {
242 241
     }
243 242
   }
244 243
 
245
-    debug("");
246
-    debug("Current readings:");
247
-    debug("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C");
248
-    debug("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + " %");
249
-    debug("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lux");
250
-    debug("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " km/h");
251
-    debug("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
252
-    debug("Bat Voltage: " + String(currentSensorData[SENSOR_BAT_VOLTAGE]) + " V");
253
-    debug("Bat charge state: " + String(currentSensorData[SENSOR_BATCHARGESTATE]));
254
-    debug("Energy saving: " + String(currentSensorData[SENSOR_ESAVEMODE]));
244
+#ifdef SERIAL_FEATURE
245
+  logToSerial(currentSensorData);
246
+#endif
255 247
 
256
-    delay(100);
248
+  delay(100);
257 249
 
258
-    pushToInfluxDB(DEVICE_NAME, currentSensorData);
250
+#ifdef INFLUXDB_FEATURE
251
+  pushToInfluxDB(DEVICE_NAME, currentSensorData);
252
+#endif
259 253
 
260 254
 #ifdef WEBUPDATER_FEATURE
261
-    setSensorData(DEVICE_NAME, localIP, currentSensorData);
255
+  setSensorData(DEVICE_NAME, localIP, currentSensorData);
262 256
 #endif
263 257
 }
264 258
 
265
-//*************************************************************************//
259
+void logToSerial(float sensorValues[]) {
260
+  Serial.println("");
261
+  Serial.println("Current readings:");
262
+  Serial.println("Temperature: " + String(sensorValues[SENSOR_TEMPERATURE]) + " °C");
263
+  Serial.println("Humidity: " + String(sensorValues[SENSOR_HUMIDITY]) + " %");
264
+  Serial.println("Light: " + String(sensorValues[SENSOR_LIGHT]) + " Lux");
265
+  Serial.println("Windspeed: " + String(sensorValues[SENSOR_WINDSPEED]) + " km/h");
266
+  Serial.println("Pressure: " + String(sensorValues[SENSOR_PRESSURE]) + " hPa");
267
+  Serial.println("Bat Voltage: " + String(sensorValues[SENSOR_BAT_VOLTAGE]) + " V");
268
+  Serial.println("Bat charge state: " + String(sensorValues[SENSOR_BATCHARGESTATE]));
269
+  Serial.println("Energy saving: " + String(sensorValues[SENSOR_ESAVEMODE]));
270
+}

+ 12
- 6
firmware/influxdb.ino View File

@@ -1,5 +1,13 @@
1
-void pushToInfluxDB(String device, float sensorValues[]) {
1
+#include <ESP8266Influxdb.h>     // https://github.com/hwwong/ESP8266Influxdb
2
+
3
+Influxdb _influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
2 4
 
5
+void influxdb_begin() {
6
+  // Init variables to influxdb config - doesn't talk to database
7
+  _influxdb.opendb(INFLUXDB_DB, INFLUXDB_USER, INFLUXDB_PASS);
8
+}
9
+
10
+void pushToInfluxDB(String device, float sensorValues[]) {
3 11
   uint8_t tries = 0;
4 12
   boolean addComma = false;
5 13
 
@@ -59,12 +67,10 @@ void pushToInfluxDB(String device, float sensorValues[]) {
59 67
     addComma = true;
60 68
   }
61 69
 
62
-#ifdef DEBUG
63
-  Serial.println(msg);
64
-#endif
70
+  debug(msg);
65 71
 
66 72
   do {
67 73
     tries++;
68
-    influxdb.write(msg);
69
-  } while (influxdb.response() != DB_SUCCESS and tries < 5);
74
+    _influxdb.write(msg);
75
+  } while (_influxdb.response() != DB_SUCCESS and tries < 5);
70 76
 }

Loading…
Cancel
Save