Skip to content

Instantly share code, notes, and snippets.

@dt
Created August 31, 2012 18:50
Show Gist options
  • Save dt/3557272 to your computer and use it in GitHub Desktop.
Save dt/3557272 to your computer and use it in GitHub Desktop.
Temp Server
#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
dht11 DHT11 = dht11(D1, BUSA)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(80);
void setup() {
delay(1000);
if (Ethernet.begin(mac) == 0) {
for(;;)
;
}
server.begin();
/*for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}*/
}
void loop() {
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<meta http-equiv=\"refresh\" content=\"60\">");
int chk = DHT11.read();
client.print("Read sensor: ");
switch (chk)
{
case 0: client.println("OK"); break;
case -1: client.println("Checksum error"); break;
case -2: client.println("Time out error"); break;
default: client.println("Unknown error"); break;
}
client.println("<br />");
client.print("Humidity (%): ");
client.print((float)DHT11.humidity, DEC);
client.println("<br />");
client.print("Temperature (?F): ");
client.print(DHT11.fahrenheit(), DEC);
client.println("<br />");
client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(10);
client.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment