FHEM: DHT22

// A web server to control the arduino via FHEM
#include "etherShield.h"
#include "ETHER_28J60.h"
#include "DHT.h"

#define DHTPIN 9
#define DHTTYPE DHT22 //DHT11, DHT21, DHT22

int sensorValue = 0;
int sensorVal = 0;

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {192, 168, 200, 211}; // the IP address for your board. Check your home hub
// to find an IP address not in use and pick that
// this or 10.0.0.15 are likely formats for an address
// that will work.

static uint16_t port = 80; // Use port 80 - the standard for HTTP

ETHER_28J60 e;

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
e.setup(mac, ip, port);
dht.begin();
}

void loop()
{
float h = dht.readHumidity(); //Luftfeuchte auslesen
float t = dht.readTemperature(); //Temperatur auslesen

char* params;
if (params = e.serviceRequest())
{
// Prüfen ob eine gültige Zahl zurückgegeben wird. Wenn NaN (not a number) zurückgegeben wird, dann Fehler ausgeben.
if (isnan(t) || isnan(h))
{
e.print("DHT22 konnte nicht ausgelesen werden");
}
else
{
e.print("Luftfeuchte: ");
e.print(h);
e.print(" %\t");
e.print("Temperatur: ");
e.print(t);
e.print(" C");
}
}
}