128 lines
4.1 KiB
Markdown
128 lines
4.1 KiB
Markdown
|
## Server-Sensorik
|
||
|
|
||
|
Da der Server in einem feuchten Keller steht, gegen den wir ihn mit userem Spezialgehäuse schützen (Kühlschrank), ist eine Überwachung der Umwelteinflüsse wünschenswert.
|
||
|
Konkret möchten wir gerne Luftfeuchte und Temperatur im Auge behalten.
|
||
|
|
||
|
### Hardware
|
||
|
Die Temperatur lässt sich auch aus den Sensoren im Mainboard ablesen. Zusätzlich ist ein Pro Micro mit zwei DHT22 Sensoren und einem Auslenkungssensor verbunden.
|
||
|
Der DHT22 liefert Werte für Temperatur und Luftfeuchte. Einer ist im Kühlschrank und einer außen am Kühlschrank befestigt. Der Auslenkungssensor protokolliert die Türöffnung.
|
||
|
Für den Sensor sind angegeben
|
||
|
Messbereich: -40 - 80 °C, 0 - 100% RH
|
||
|
Genauigkeit: 0.5°C, 2% RH
|
||
|
|
||
|
### Sofware
|
||
|
#### Pro Micro
|
||
|
Auf dem Pro Micro läuft ein Arduino-Sketch[1]
|
||
|
Dieser liefert CSV-Werte:
|
||
|
```
|
||
|
86.10, 23.10, 14.20, 34.20, 0
|
||
|
|
||
|
86.00, 23.10, 14.10, 34.20, 0
|
||
|
|
||
|
86.10, 23.10, 14.20, 34.20, 0
|
||
|
|
||
|
86.20, 23.00, 14.20, 34.20, 0
|
||
|
```
|
||
|
|
||
|
#### Collectd und Facette
|
||
|
Damit die Werte in unseren schönen Facette-Graphen auftauchen, müssen wir zuerst collectd beibringen die Werte überhaupt zu sammeln.
|
||
|
Dazu lässt sich entweder das Plugin "Exec" verwenden, das ein Skipt ausführt und die Rückgabewerte protokolliert oder das Plugin "tail_CSV", welches
|
||
|
CSV Dateien einliest, sofern es aus einer seriellen Schnittstelle lesen kann.
|
||
|
|
||
|
|
||
|
|
||
|
### Dateien
|
||
|
[1] Das verwendete Arduino Programm:
|
||
|
```
|
||
|
// Based on "Example testing sketch for various DHT humidity/temperature sensors"
|
||
|
// from ladyada, public domain
|
||
|
//
|
||
|
|
||
|
#include "DHT.h"
|
||
|
|
||
|
#define DHTPIN1 21 // what digital pin we're connected to
|
||
|
#define DHTPIN2 20
|
||
|
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
|
||
|
|
||
|
|
||
|
// Connect pin 1 (on the left) of the sensor to +5V
|
||
|
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
|
||
|
// to 3.3V instead of 5V!
|
||
|
// Connect pin 2 of the sensor to whatever your DHTPIN is
|
||
|
// Connect pin 4 (on the right) of the sensor to GROUND
|
||
|
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
|
||
|
|
||
|
// Initialize DHT sensor.
|
||
|
// Note that older versions of this library took an optional third parameter to
|
||
|
// tweak the timings for faster processors. This parameter is no longer needed
|
||
|
// as the current DHT reading algorithm adjusts itself to work on faster procs.
|
||
|
DHT dht1(DHTPIN1, DHTTYPE);
|
||
|
DHT dht2(DHTPIN2, DHTTYPE);
|
||
|
int door=0;
|
||
|
int swtch=0;
|
||
|
int count=0;
|
||
|
|
||
|
|
||
|
void setup() {
|
||
|
Serial.begin(9600);
|
||
|
Serial.println("Humidity inside, humidity outside, temperature inside, temperature outside, door switch");
|
||
|
|
||
|
dht1.begin();
|
||
|
dht2.begin();
|
||
|
pinMode(19,INPUT_PULLUP);
|
||
|
}
|
||
|
|
||
|
|
||
|
void loop() {
|
||
|
swtch= digitalRead(19);
|
||
|
if (door != swtch || count > 100 ){
|
||
|
count=0;
|
||
|
door=swtch;
|
||
|
|
||
|
// Wait a few seconds between measurements.
|
||
|
// Reading temperature or humidity takes about 250 milliseconds!
|
||
|
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
||
|
// So keep in mind, that (maximum counts) * (delay) = (time between readouts)
|
||
|
delay(20);
|
||
|
|
||
|
float hin_raw = dht1.readHumidity();
|
||
|
float hout_raw = dht2.readHumidity();
|
||
|
// Read temperature as Celsius (the default)
|
||
|
float tin_raw = dht1.readTemperature();
|
||
|
float tout_raw = dht2.readTemperature();
|
||
|
|
||
|
// the DHT22 has an statistical error of 2% for humidity and 0.5°C for temperatur.
|
||
|
// so lets add some offset depending on our sensors, to get to comparable values
|
||
|
float hin = hin_raw + 3.6;
|
||
|
float tin = tin_raw - 0.3 ;
|
||
|
float hout = hout_raw ;//- 0.026;
|
||
|
float tout = tout_raw + 0;
|
||
|
|
||
|
|
||
|
// Check if any reads failed and exit early (to try again).
|
||
|
if (isnan(hin) || isnan(tin) || isnan(hout) || isnan(tout)) {
|
||
|
Serial.print("Failed to read from DHT sensor!");
|
||
|
Serial.print(", \t");
|
||
|
Serial.println(door);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// print the values if everything works fine
|
||
|
Serial.print(hin);
|
||
|
Serial.print(", \t");
|
||
|
Serial.print(hout);
|
||
|
Serial.print(", \t");
|
||
|
Serial.print(tin);
|
||
|
Serial.print(", \t");
|
||
|
Serial.print(tout);
|
||
|
Serial.print(", \t");
|
||
|
Serial.println(door);
|
||
|
}
|
||
|
else{
|
||
|
delay(20);
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|