关于Arduino+W5100+DHT11检测温湿度 中Arduino的编程问题 5C

下面是《完美图解物联网IOT实操》里面的示例代码

 #include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include "Streaming.h"   // 引用处理字符串的库(参阅下文说明)
#include "dht11.h"

dht11 DHT11;            // 声明 DHT11 程序对象
const byte dataPin = 2; // 声明 DHT11 模块的数据输入脚位

static byte mac[] = { 0xF0, 0x7B, 0xCB, 0x4B, 0x7C, 0x9F };
IPAddress ip(192, 168, 1, 25);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 1, 1);

WebServer webserver("", 80);

P(htmlHead) =
 "<!doctype html><html>"
 "<head><meta charset=\"utf-8\">"
 "      <meta http-equiv=\"refresh\" content=\"3\">"
 "<title>Arduino 温湿度计</title>"
 "</head><body>";

P(htmlFoot) = "</body></html>";

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  int chk = DHT11.read(dataPin);
  char buffer[5] = "";
  server.httpSuccess();

  if (type != WebServer::HEAD){
    server.printP(htmlHead);

    if (chk == 0) {
      server << "<h1>温湿度计</h1>";
      server << "<p>温度:" << dtostrf(DHT11.temperature, 5, 2, buffer)
             << "&deg;C</p>";
      server << "<p>湿度:" << dtostrf(DHT11.humidity, 5, 2, buffer) 
             << "%</p>";
    } else {
      server << "<h1>无法读取温湿度值</h1>";
    }
    server.printP(htmlFoot);
  }
}

void dht11Cmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  int chk = DHT11.read(dataPin);
  char buffer[5] = "";
  server.httpSuccess("text/plain");  // 设置返回「纯文本」内容类型

  if (type != WebServer::HEAD) {
    if (chk == 0) {
      server << dtostrf(DHT11.temperature, 5, 2, buffer);
    } else {
      server << "??";
    }
  }
}

void thCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  int chk = DHT11.read(dataPin);
  char buffer[5] = "";
  server.httpSuccess("text/javascript");

  if (type != WebServer::HEAD) {
    if (chk == 0) {
      server << "{\"t\":" << dtostrf(DHT11.temperature, 5, 2, buffer) 
             << ",\"h\":" << dtostrf(DHT11.humidity, 5, 2, buffer) 
             << "}";
    } else {
      server << "{\"t\":\"?\",\"h\":\"?\"}";
    }
  }
}

void setup() {  
  Ethernet.begin(mac, ip, gateway, subnet);
  webserver.setDefaultCommand(&defaultCmd);   // 处理「首页」请求
  webserver.addCommand("temp", &dht11Cmd);
  webserver.addCommand("th.json", &thCmd);
  webserver.begin();
}

void loop() {
  webserver.processConnection();
}

每次用Arduino编译都出现大量错误提示,如下错误信息:
![图片说明](https://img-ask.csdn.net/upload/201712/21/1513850894_797012.png)图片说明
^

2个回答

图片说明

全是这种类型的错误 我该怎么解决啊?图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐