Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2891|回復: 1
打印 上一主題 下一主題

arduino tcp/ip 範例一問

[複製鏈接]
跳轉到指定樓層
1#
發表於 2014-7-29 10:53:46 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
首先 我使用的板子是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個禮拜了
2#
發表於 2014-8-4 03:03:08 | 只看該作者
回復 1# l0921317

測試的話 可以使用Arduino自帶的Ethernet庫中的WebServer例子,從Arduino IDEFile->Examples->Ethernet功能表中選擇WebServer,打開相應的代碼:
課本的比較不準,
老師說的不見得是都對的,
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-9-30 18:19 , Processed in 0.255383 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表