รบกวนสอบถามหน่อยครับว่า W5100 ที่ผมซื้อมา มัน Fix Ipaddress ไปแล้ว เครื่องในวงแลน ping หาเจอ แต่ W5100 ติดต่อกับ webserver ไม่ได้ ทั้งที่ webserver อยู่ในวงแลนเดียวกันและใช้ example ของโปรแกรม Arduino ในการ Compile ขอบคุณครับ
ถ้า ping เห็นอุปกรณ์แล้ว w5100 น่าจะทำงานได้ปกติ
อาจเป็นที่ network ติด firewall หรือบางจุด ถ้ามีเราเตอร์ลองต่อโดยตรงกับ w5100 แล้วทดลองใหม่ครับ
#include "SPI.h"
#include "Ethernet.h"
/*
Web client
This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen
*/
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x76, 0x09 };
//byte mac[] = { 0x00, 0x19, 0xE0, 0x60, 0x02, 0xAD };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//char server[] = "www.google.com"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress server(192,168,2,29); // numeric IP for Google (no DNS)
//char server[] = "banmihospital.moph.go.th";
//IPAddress server(172, 217, 31, 99);
IPAddress ip(192, 168, 2, 30);
//byte ip[] = { 192, 168, 0, 30 };
IPAddress nsk(255, 255, 252, 0);
IPAddress gw(192, 168, 2, 40);
//byte gw[] = { 192, 168, 2, 40 };
IPAddress d(8, 8, 4, 4);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
int port = 80;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start the Ethernet connection:
/*
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac,ip,d,gw,nsk);
}
*/
Ethernet.begin(mac,ip,gw,nsk);
// give the Ethernet shield a second to initialize:
delay(1000);
//Serial.println(Ethernet.localIP());
Serial.println("connecting...");
/*
Serial.println(ip);
Serial.println(nsk);
Serial.println(gw);
*/
}
void loop() {
//Serial.println(client.connect(server,80));
Serial.println(client.status());
if (client.connect(server, port)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /program/cc/arduinopj/index.php HTTP/1.1");
//client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: bmh_arduino_project");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
Serial.println("<<goto Exit>>");
client.stop();
delay(2000);
}
เครีื่อง pc เข้าใชงานหน้าเว็บได้ อ่ะครับ ไม่ทราบว่าผม Code ตรงไหนผิดหรือเปล่าครับ
โคดไม่น่าผิด มีตัวอย่างในหน้าบทความ
น่าจะผิดที่เครือข่ายหรือ firewall ตรงนี้ต้องเช็คที่หน้างานครับ
ออครับ รบกวนถามอีกเรื่อง พอดีผมเปลี่ยนมารับ ip จาก Router แล้วพอเปิด serial.print ดูพบว่าไม่มีอะไรเกิดขึ้นเลยครับ สาย lan อันใหม่ครับ ส่วน Router แจก ip ให้กับ pc ได้ตามปกติครับ
ได้ซื้อกับทางร้านมั้ยครับ ขอเลขที่สั่งซื้อด้วย จะได้ตรวจสอบได้ครับ