Hello,
I've been strugling with a project for a while. I wanted to make a DHT22 web server and I managed it with a minor problem. I'm using the libraries;
#include <EtherCard.h>
#include <DHT.h>
#include <DHT_U.h>
and the sensors are;
DHT22 (for temperature and humidity)
ENC28J60 module (for LAN connection)
The problem is that a weird "Â" appers next to the printed value and the temperature is not printed, but humidity is printed fine and also the felt temperature is printed with this "Â" next to it.
Could someone help me to resolve this problem?
Besides, I would like an explanation about something in the code (becase this part, I took it almost copy-paste).
At line 96 after the CSS stylization there is this; $D$D:$D$D:$D$D:$D$D and at the lines 97, 98 and 99 there is $S.
What do they mean? It seems like at C, where if you want to print a float value you say %d.
How many of there arguments are valid in arduino?
To solve this problem I tried 2 different techniques;
- I printed the values as floats but in the webpage I could see only "Â" without values (the referrence in the HTML was $T in this case)
- I converted the floats to strings and I print them with the referrence of $S (like you will see in the code) and the problem is shown in the photo above.
I'm using Arduino UNO
My code is here;
https://www.mediafire.com/file/aq7nnmxn6r3di5s/sketch_jul03a.ino/file
#include <EtherCard.h>
#include <DHT.h>
#include <DHT_U.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,1,8 };
byte Ethernet::buffer[500];
BufferFiller bfill;
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float temp;
float hum;
float felt_temp;
char t_str[6];
char h_str[6];
char ft_str[6];
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
Serial.println("ENC28J60 Ethernet Server Test");
Serial.println("DHT22 Temperature/Humidity Sensor");
dht.begin();
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println(F("Failed to access Ethernet controller"));
ether.staticSetup(myip);
ether.printIp("Local IP: ", ether.myip);
ether.printIp("Gateway: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop() {
// put your main code here, to run repeatedly:
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) {
ether.httpServerReply(homePage());
//return;
}
float temp = dht.readTemperature();
float hum = dht.readHumidity();
dtostrf(temp, 5, 3, t_str);
dtostrf(hum, 5, 3, h_str);
if (!isnan(temp) && !isnan(hum)) {
float felt_temp = dht.computeHeatIndex(temp, hum, false);
dtostrf(felt_temp, 5, 2, ft_str);
Serial.println("Temperature :");
Serial.println(hum);
Serial.println("Humidity :");
Serial.println(hum);
Serial.println("Felt as: ");
Serial.println(felt_temp);
//return;
}
else {
if (isnan(temp)) {
Serial.println("Temperature fail");
//return;
}
else {
Serial.println("Humidity fail");
//return;
}
//return;
}
}
static word homePage() {
long t = millis() / 1000;
word h = t / 3600;
byte m = (t / 60) % 60;
byte s = t % 60;
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>DHT22 server</title>"
"<h1>DHT Temperature / Humidity Server<br></h1>"
"<h1><font color=black>$D$D:$D$D:$D$D<br></h1>"
"<h1><font color=red>Temperature: $S °C<br></h1>"
"<h1><font color=green>Humidity: $S %<br></h1>"
"<h1><font color=blue>Felt as: $S °C<br></h1>"),
h/10, h%10, m/10, m%10, s/10, s%10, t_str, h_str, ft_str);
return bfill.position();
}
If I forgot something, tell me to add it
Thanks in advance!