Robofun 機器人論壇

標題: arduino tcp/ip 範例一問 [打印本頁]

作者: l0921317    時間: 2014-7-29 10:53
標題: arduino tcp/ip 範例一問
首先 我使用的板子是W5100

這是課本的範例
/*
* Simple Web Client
* Arduino 1.0 version
*/

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };    // change to a valid address for your network
byte server[] = { 209,85,229,104  }; // Google
                                     // see text for more on IP addressing

EthernetClient client;

void setup()
{
  Serial.begin(9600);      // start the serial library:
  Ethernet.begin(mac,ip);
  delay(1000);             // give the ethernet hardware a second to initialize

  Serial.println("connecting...");

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0"); // the HTTP request
    client.println();
  }
  else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);  // echo all data received to the Serial Monitor
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}


但我使用都會顯示

connecting...
connection failed

disconnecting.

(IP啥的都有改確定可用的)

爬過許多文章 範例 也都會顯示差不多的問題

像是 Failed to configure Ethernet using DHCP 之類的

請問是哪邊出了問題?? 卡了1個禮拜了
作者: vegewell    時間: 2014-8-4 03:03
回復 1# l0921317

測試的話 可以使用Arduino自帶的Ethernet庫中的WebServer例子,從Arduino IDEFile->Examples->Ethernet功能表中選擇WebServer,打開相應的代碼:
課本的比較不準,
老師說的不見得是都對的,





歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/) Powered by Discuz! X3.2