ARDUINO W5100 WebServer测试

1.直接下载官方的enternet->WebServer代码

/*
  Web Server
 
 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)
 
 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // 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
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");       
          }
          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();
    Serial.println("client disconnected");
  }
}

打开串口调试助手显示网页IP

 

在浏览器输入192.168.1.177

串口监视器会显示GET信息

转载于:https://www.cnblogs.com/Mysterious/p/5415809.html

如果您打算使用Arduino运行Web服务器,那么这里是您的理想选择。我们将在Web服务器上显示传感器数据。 硬件部件: Arduino UNO和Genuino UNO×1个 Arduino以太网修订版3×1个 跳线(通用)×1个 DHT22温度传感器×1个 软件应用程序和在线服务: Arduino IDE 仅作记录,Arduino本身不能充当Web服务器。与具有完整功能的嵌入式系统Raspberry Pi不同,Arduino需要以太网屏蔽才能连接到Internet或ESP8266芯片。 Arduino以太网屏蔽是一种电路板,可让Arduino连接到互联网。它基于Wiznet W5xxx系列以太网芯片。这些芯片具有能够同时使用TCP-IP和UDP的网络堆栈。但是,屏蔽层仅允许通过RJ45连接器进行有线连接。因此,如果您正在寻找无线互联网解决方案,则可以改用ESP8266开发板。Arduino以太网防护罩具有集成的microSD卡读卡器,可用于存储网页文件。 您仍然可以使用以太网屏蔽的母头引脚与Arduino的大多数引脚接口。只需将屏蔽罩和Arduino的引脚对齐,然后向下压直到它们舒适地合上即可。不能使用的引脚是引脚10 (SS),11 (MOSI),12 (MISO)和13 (SCK)。这些是SPI(串行外围设备接口)引脚,Arduino用来与以太网屏蔽进行通信。 准备硬件 对于此项目,我们将显示来自Arduino的DHT22温湿度传感器数据和与网络页面配对的以太网屏蔽,您可以在世界任何地方访问该页面。为此,请连接以下组件,如图2所示: 组装完组件后,将LAN电缆插入RJ45连接器。另一端必须在连接到互联网的路由器上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值