Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
if (c=='?'){
Serial.print("Commando ? gesendet\n\n");
while (c!='\r')
{
cmd+=c;
// Serial.print(c);
c=client.read();
}
Serial.println(cmd);
if (cmd.startsWith("?cmd")) {
Serial.println("Kommando erkannt");
cmd_length=cmd.length();
Serial.println (cmd_length);
if (cmd.startsWith("?cmd=read_t0")){// Lese nur Temperatur des 1. Sensors aus (=t0)
Serial.println("Kommando lese T0");
sensors.requestTemperatures();
client.print(sensors.getTempCByIndex(0));
cmd="";
}
if (cmd.startsWith("?cmd=read_t1")){ // Lese nur Temperatur des 2. Sensors aus
Serial.println("Kommando lese T1");
sensors.requestTemperatures();
client.print(sensors.getTempCByIndex(1));
cmd="";
}
if (cmd.startsWith("?cmd=read_t2")){ // Lese nur Temperatur des 3. Sensors aus
Serial.println("Kommando lese T2");
sensors.requestTemperatures();
client.print(sensors.getTempCByIndex(2));
cmd="";
}
if (cmd.startsWith("?cmd=read_t")){ //Lese alle DS1820, zur Zeit 3 Stück und gebe die Werte aus
Serial.println("Kommando lese T1");
sensors.requestTemperatures();
client.print("T0: ");
client.print(sensors.getTempCByIndex(0));
client.print(" T1: ");
client.print(sensors.getTempCByIndex(1));
client.print(" T2: ");
client.print(sensors.getTempCByIndex(2));
cmd="";
}
if (cmd.startsWith("?cmd=read_dht11")) // Lese den DHT11 an DHT11PIN aus
{
Serial.println("Kommando lese DHT11");
#define DHT11PIN 3 // Der Sensor an PIN 3 wird gewählt
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);
Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
client.print("T: ");
client.print((float)DHT11.temperature, 2);
client.print(" H: ");
client.print((float)DHT11.humidity, 2);
client.print(" DP: ");
client.print(dewPointFast(DHT11.temperature, DHT11.humidity));
cmd="";
}
if (cmd.startsWith("?cmd=read_dht11_2"))
{
Serial.println("Kommando lese DHT11_2");
#define DHT11PIN 4 // Der Sensor an Pin 4 wird gewählt
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);
Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
client.print("T: ");
client.print((float)DHT11.temperature, 2);
client.print(" H: ");
client.print((float)DHT11.humidity, 2);
client.print(" DP: ");
client.print(dewPointFast(DHT11.temperature, DHT11.humidity));
cmd="";
}
}
else{
Serial.println("kein gueltiges Kommando erkannt");
client.println("Nicht gültig");
cmd="";
}
}
}
}
}
// give the web browser time to receive the data