|
@@ -89,29 +89,35 @@ static boolean writeMeasurement(InfluxData &measurement) {
|
89
|
89
|
return success;
|
90
|
90
|
}
|
91
|
91
|
|
92
|
|
-void writeDatabase() {
|
93
|
|
-#ifndef USE_INFLUXDB_LIB
|
94
|
|
- InfluxData measurement("");
|
|
92
|
+static void addTagsGeneric(InfluxData &measurement) {
|
|
93
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
|
94
|
+ measurement.addTag("location-id", SENSOR_ID);
|
|
95
|
+
|
|
96
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
97
|
+ measurement.addTag("device", WiFi.macAddress().c_str());
|
95
|
98
|
#endif
|
|
99
|
+}
|
96
|
100
|
|
97
|
|
-#ifdef ENABLE_BME280
|
|
101
|
+static void addTagsSensor(InfluxData &measurement, String sensor, String placement) {
|
|
102
|
+ addTagsGeneric(measurement);
|
|
103
|
+ measurement.addTag("sensor", sensor);
|
|
104
|
+ measurement.addTag("placement", placement);
|
|
105
|
+}
|
98
|
106
|
|
99
|
|
- if (found_bme1) {
|
100
|
|
-#ifndef USE_INFLUXDB_LIB
|
101
|
|
- measurement.clear();
|
102
|
|
- measurement.setName("environment");
|
103
|
|
-#else
|
104
|
|
- InfluxData measurement("environment");
|
|
107
|
+#ifdef FEATURE_RELAIS
|
|
108
|
+static void addTagsRelais(InfluxData &measurement, String id, String name) {
|
|
109
|
+ addTagsGeneric(measurement);
|
|
110
|
+ measurement.addTag("id", id);
|
|
111
|
+ measurement.addTag("name", name);
|
|
112
|
+}
|
105
|
113
|
#endif
|
106
|
114
|
|
107
|
|
- measurement.addTag("location", SENSOR_LOCATION);
|
108
|
|
- measurement.addTag("location-id", SENSOR_ID);
|
109
|
|
- measurement.addTag("placement", "1");
|
110
|
|
- measurement.addTag("sensor", "bme280");
|
|
115
|
+void writeDatabase() {
|
|
116
|
+#ifdef ENABLE_BME280
|
111
|
117
|
|
112
|
|
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
113
|
|
- measurement.addTag("device", WiFi.macAddress().c_str());
|
114
|
|
-#endif
|
|
118
|
+ if (found_bme1) {
|
|
119
|
+ InfluxData measurement("environment");
|
|
120
|
+ addTagsSensor(measurement, F("bme280"), F("1"));
|
115
|
121
|
|
116
|
122
|
measurement.addValue("temperature", bme1_temp());
|
117
|
123
|
measurement.addValue("pressure", bme1_pressure());
|
|
@@ -123,21 +129,8 @@ void writeDatabase() {
|
123
|
129
|
}
|
124
|
130
|
|
125
|
131
|
if (found_bme2) {
|
126
|
|
-#ifndef USE_INFLUXDB_LIB
|
127
|
|
- measurement.clear();
|
128
|
|
- measurement.setName("environment");
|
129
|
|
-#else
|
130
|
132
|
InfluxData measurement("environment");
|
131
|
|
-#endif
|
132
|
|
-
|
133
|
|
- measurement.addTag("location", SENSOR_LOCATION);
|
134
|
|
- measurement.addTag("location-id", SENSOR_ID);
|
135
|
|
- measurement.addTag("placement", "2");
|
136
|
|
- measurement.addTag("sensor", "bme280");
|
137
|
|
-
|
138
|
|
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
139
|
|
- measurement.addTag("device", WiFi.macAddress().c_str());
|
140
|
|
-#endif
|
|
133
|
+ addTagsSensor(measurement, F("bme280"), F("2"));
|
141
|
134
|
|
142
|
135
|
measurement.addValue("temperature", bme2_temp());
|
143
|
136
|
measurement.addValue("pressure", bme2_pressure());
|
|
@@ -151,20 +144,8 @@ void writeDatabase() {
|
151
|
144
|
#endif // ENABLE_BME280
|
152
|
145
|
|
153
|
146
|
if (found_sht) {
|
154
|
|
-#ifndef USE_INFLUXDB_LIB
|
155
|
|
- measurement.clear();
|
156
|
|
- measurement.setName("environment");
|
157
|
|
-#else
|
158
|
147
|
InfluxData measurement("environment");
|
159
|
|
-#endif
|
160
|
|
-
|
161
|
|
- measurement.addTag("location", SENSOR_LOCATION);
|
162
|
|
- measurement.addTag("location-id", SENSOR_ID);
|
163
|
|
- measurement.addTag("sensor", "sht21");
|
164
|
|
-
|
165
|
|
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
166
|
|
- measurement.addTag("device", WiFi.macAddress().c_str());
|
167
|
|
-#endif
|
|
148
|
+ addTagsSensor(measurement, F("sht21"), F("1"));
|
168
|
149
|
|
169
|
150
|
measurement.addValue("temperature", sht_temp());
|
170
|
151
|
measurement.addValue("humidity", sht_humid());
|
|
@@ -177,25 +158,12 @@ void writeDatabase() {
|
177
|
158
|
#ifdef ENABLE_CCS811
|
178
|
159
|
|
179
|
160
|
if (found_ccs1) {
|
180
|
|
-#ifndef USE_INFLUXDB_LIB
|
181
|
|
- measurement.clear();
|
182
|
|
- measurement.setName("environment");
|
183
|
|
-#else
|
184
|
161
|
InfluxData measurement("environment");
|
185
|
|
-#endif
|
186
|
|
-
|
187
|
|
- measurement.addTag("location", SENSOR_LOCATION);
|
188
|
|
- measurement.addTag("location-id", SENSOR_ID);
|
189
|
|
- measurement.addTag("placement", "1");
|
190
|
|
- measurement.addTag("sensor", "ccs811");
|
|
162
|
+ addTagsSensor(measurement, F("ccs811"), F("1"));
|
191
|
163
|
|
192
|
164
|
String err(ccs1_error_code);
|
193
|
165
|
measurement.addTag("error", err);
|
194
|
166
|
|
195
|
|
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
196
|
|
- measurement.addTag("device", WiFi.macAddress().c_str());
|
197
|
|
-#endif
|
198
|
|
-
|
199
|
167
|
measurement.addValue("eco2", ccs1_eco2());
|
200
|
168
|
measurement.addValue("tvoc", ccs1_tvoc());
|
201
|
169
|
|
|
@@ -205,25 +173,12 @@ void writeDatabase() {
|
205
|
173
|
}
|
206
|
174
|
|
207
|
175
|
if (found_ccs2) {
|
208
|
|
-#ifndef USE_INFLUXDB_LIB
|
209
|
|
- measurement.clear();
|
210
|
|
- measurement.setName("environment");
|
211
|
|
-#else
|
212
|
176
|
InfluxData measurement("environment");
|
213
|
|
-#endif
|
214
|
|
-
|
215
|
|
- measurement.addTag("location", SENSOR_LOCATION);
|
216
|
|
- measurement.addTag("location-id", SENSOR_ID);
|
217
|
|
- measurement.addTag("placement", "2");
|
218
|
|
- measurement.addTag("sensor", "ccs811");
|
|
177
|
+ addTagsSensor(measurement, F("ccs811"), F("2"));
|
219
|
178
|
|
220
|
179
|
String err(ccs2_error_code);
|
221
|
180
|
measurement.addTag("error", err);
|
222
|
181
|
|
223
|
|
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
224
|
|
- measurement.addTag("device", WiFi.macAddress().c_str());
|
225
|
|
-#endif
|
226
|
|
-
|
227
|
182
|
measurement.addValue("eco2", ccs2_eco2());
|
228
|
183
|
measurement.addValue("tvoc", ccs2_tvoc());
|
229
|
184
|
|
|
@@ -238,21 +193,9 @@ void writeDatabase() {
|
238
|
193
|
for (int i = 0; i < moisture_count(); i++) {
|
239
|
194
|
int moisture = moisture_read(i);
|
240
|
195
|
if (moisture < moisture_max()) {
|
241
|
|
-#ifndef USE_INFLUXDB_LIB
|
242
|
|
- measurement.clear();
|
243
|
|
- measurement.setName("moisture");
|
244
|
|
-#else
|
245
|
|
- InfluxData measurement("moisture");
|
246
|
|
-#endif
|
247
|
|
-
|
248
|
|
- measurement.addTag("location", SENSOR_LOCATION);
|
249
|
|
- measurement.addTag("location-id", SENSOR_ID);
|
250
|
196
|
String sensor(i + 1, DEC);
|
251
|
|
- measurement.addTag("sensor", sensor);
|
252
|
|
-
|
253
|
|
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
254
|
|
- measurement.addTag("device", WiFi.macAddress().c_str());
|
255
|
|
-#endif
|
|
197
|
+ InfluxData measurement("moisture");
|
|
198
|
+ addTagsSensor(measurement, sensor, sensor);
|
256
|
199
|
|
257
|
200
|
measurement.addValue("value", moisture);
|
258
|
201
|
measurement.addValue("maximum", moisture_max());
|
|
@@ -268,17 +211,14 @@ void writeDatabase() {
|
268
|
211
|
#ifdef FEATURE_RELAIS
|
269
|
212
|
for (int i = 0; i < relais_count(); i++) {
|
270
|
213
|
InfluxData measurement("relais");
|
271
|
|
- measurement.addTag("location", SENSOR_LOCATION);
|
272
|
|
- measurement.addTag("location-id", SENSOR_ID);
|
273
|
|
- measurement.addTag("id", String(i));
|
274
|
|
- measurement.addTag("name", relais_name(i));
|
275
|
|
-
|
276
|
|
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
277
|
|
- measurement.addTag("device", WiFi.macAddress().c_str());
|
278
|
|
-#endif
|
|
214
|
+ addTagsRelais(measurement, String(i), relais_name(i));
|
279
|
215
|
|
280
|
216
|
measurement.addValue("state", relais_get(i));
|
|
217
|
+
|
|
218
|
+ debug.print(F("Writing relais "));
|
|
219
|
+ debug.println(i);
|
281
|
220
|
writeMeasurement(measurement);
|
|
221
|
+ debug.println(F("Done!"));
|
282
|
222
|
}
|
283
|
223
|
#endif // FEATURE_RELAIS
|
284
|
224
|
}
|