利用arduino W5100 DHT11实现web浏览温湿度(初级简单)
本帖最后由 zhaopengxslc 于 2014-9-4 22:23 编辑#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,177);
EthernetServer server(80);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
dht.begin();
}
void loop() {
delay(2000);
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// 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) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");// the connection will be closed after completion of the response
client.println("Refresh: 5");// refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
client.println("<head>");
client.println("</head>");
client.println("<body>");
float h=dht.readHumidity();
float t=dht.readTemperature();
if(isnan(h) || isnan(t))
{
client.println("Error!");
client.println("<br />");
return;
}
client.print("Humidity:");
client.println(h);
client.print("Temperture:");
client.print(t);
client.println("<br />");
client.println("<br />");
client.println("</body>");
client.println("</html>");
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;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
连接方式
DHT11
pin1 5V
pin2 D2
pin3 悬空
pin4 GND
W5100作为web服务器
是否将Arduino作为数据采集,W5100作为Server ,PC 浏览器作为Clint,在浏览器上打上IP地址,直接读数? 实验成功,但感觉刷新有点慢 温度,湿度变化本来就是慢变化特性,刷新慢些也无仿 林定祥 发表于 2014-9-5 09:14 static/image/common/back.gif
是否将Arduino作为数据采集,W5100作为Server ,PC 浏览器作为Clint,在浏览器上打上IP地址,直接读数?
可以呀 输入http://192.168.2.177就可以看到 504835618 发表于 2014-9-5 12:13 static/image/common/back.gif
实验成功,但感觉刷新有点慢
修改delay(2000)的数值 你好,请问下你的这个温湿度采集实验除了 arduino开发板,DHT11传感器,还需要哪些模块,可以看下你的硬件原理图不?
硬件连接图可以找来看看吗 zhaopengxslc 发表于 2014-9-6 22:45 static/image/common/back.gif
可以呀 输入http://192.168.2.177就可以看到
一定是192.168.2.177吗? suoma 发表于 2015-4-26 19:17 static/image/common/back.gif
一定是192.168.2.177吗?
只要和这个对应就行了“IPAddress ip(192,168,2,177);” 乘风破浪 发表于 2015-3-4 21:47 static/image/common/back.gif
你好,请问下你的这个温湿度采集实验除了 arduino开发板,DHT11传感器,还需要哪些模块,可以看下你的硬件原 ...
除了 arduino开发板,DHT11传感器,还需要一个w5100网络模块 13189359450 发表于 2015-8-5 21:44 static/image/common/back.gif
只要和这个对应就行了“IPAddress ip(192,168,2,177);”
O(∩_∩)O谢谢 504835618 发表于 2014-9-5 12:13 static/image/common/back.gif
实验成功,但感觉刷新有点慢
你好 问下W5100怎么连接网络的 必须通过路由器吗 爱上即可 发表于 2015-12-27 21:41 static/image/common/back.gif
你好 问下W5100怎么连接网络的 必须通过路由器吗
当然要通过路由器了 请问,这个温度和湿度显示实验, 是在哪个网站上显示的?????
页:
[1]
2