I'm new to the Arduino and am trying to put a small web-based weather station together. My setup currently consists of a UNO, DHT11 sensor, and an ENC28J60 thernet module. I have independently tested each component and they all work correctly: I get good temp/humidity readings from the DHT11 and the rbbbServer sketch will serve the test web page correctly. My initial effort is a combination of the DHTtester and rbbbServer sketches. The web page loads, but the sensor data that is returned isn't right. Humidity shows '0' and temperature shows something like '17012'. The humidity doesn't change, but the 5 digit temperature value does fluctuate, if I blow on it or fan it. Can anyone provide some insight into this for me? All replies greatly appreciated.
Glenn
Code: Select all
#include <EtherCard.h>
#include <DHT.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 10, 58, 30, 122 };
byte Ethernet::buffer[500];
BufferFiller bfill;
#define DHTPIN 8 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
float rh, rt; // make global
DHT dht(DHTPIN, DHTTYPE);
void setup ()
{
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
ether.staticSetup(myip);
Serial.begin(9600);
dht.begin();
}
static word homePage()
{
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"<meta http-equiv='refresh' content='1'/>"
"<title>RBBB server</title>"
"<h1>Tiny Weather Server</h1>"
"<br>"
"<h2>Humidity: $D</h2>"
"<h2>Temperature: $D</h2>"),
rh, rt);
return bfill.position();
}
void loop ()
{
rh = dht.readHumidity();
rt = dht.readTemperature();
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (isnan(rt) || isnan(rh)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(rh);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(rt);
Serial.println(" *C");
}
if (pos) // check if valid tcp data is received
ether.httpServerReply(homePage()); // send web page data
}