Hi!
I’m using an Arduino Uno with an enc28j60 and a dht11 sensor. I’m trying to show in a browser what I’m getting from the sensor.
I’m getting an odd response…my humidity is shown twice and the temperature once and a strange symbol that should not be there.
#include <EtherCard.h>
#include <DHT.h>
#include <stdlib.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01};
static byte myip[] = {192,168,1,10};
byte Ethernet::buffer[700];
void setup () {
Serial.begin(57600);
Serial.println("Temperatura demo");
dht.begin();
if (ether.begin(sizeof Ethernet::buffer, mymac, 8) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.staticSetup(myip))
Serial.println("Failed to set IP address");
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
char temp[6];
dtostrf(t, 6, 2, temp);
char umid[6];
dtostrf(h, 6, 2, umid);
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(pos) {
Serial.println("---------------------------------------- NEW PACKET ----------------------------------------");
Serial.println((char *)Ethernet::buffer + pos);
Serial.println("--------------------------------------------------------------------------------------------");
Serial.println();
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
BufferFiller bfill = ether.tcpOffset();
bfill.emit_p(PSTR("<html><body>"
"<h1>Temperatura: $S *C</h1>
"
"<h1>Umiditatea: $S %</h1>
"
"</body></html>"),temp, umid);
ether.httpServerReply(bfill.position());
}
}
and a printscreen:
http://speedy.sh/uT8fp/web.jpg