Offline
Newbie
Karma: 0
Posts: 3
|
 |
« on: January 19, 2013, 03:11:59 pm » |
Hello, i'm using standard EthernetShield on multiple arduino boards (diecimila, duemilanove with atmega328, uno, mega 2560) and experiencing strange problem. Example WebServer script works without problems, dhcp works, i can ping arduino but Web Client examples only works in local network, i don't get any response from servers outside it. I did manage to successfully run ArduinoCosm ( https://github.com/cosm/cosm-arduino) example, it posted values to Cosm. Tried all of the arduinos, tried connecting without router but nothing seems to help. Arduino get's ip from dhcp (tried manualy specifying ip, dns, gateway, netmask), makes request, but that's all). Any ideas? regards, Martin
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 37
Posts: 974
Get Bitlash: http://bitlash.net
|
 |
« Reply #1 on: January 19, 2013, 03:14:47 pm » |
Sounds like the gateway configuration needs checking. You'll get better help if you post your code.
-br
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6546
Arduino rocks
|
 |
« Reply #2 on: January 19, 2013, 03:24:41 pm » |
Web Client examples only works in local network, i don't get any response from servers outside it. Simple client test code you can try. //zoomkat 9-22-12 //simple client test //for use with IDE 1.0.1 //with DNS, DHCP, and Host //open serial monitor and send an e to test //for use with W5100 based ethernet shields
#include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "web.comporium.net"; // zoomkat's test web page server EthernetClient client;
//////////////////////
void setup(){
if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: while(true); }
Serial.begin(9600); Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded Serial.println("Send an e in serial monitor to test"); // what to do to test }
void loop(){ // check for serial input if (Serial.available() > 0) //if something in serial buffer { byte inChar; // sets inChar as a byte inChar = Serial.read(); //gets byte from buffer if(inChar == 'e') // checks to see byte is an e { sendGET(); // call sendGET function below when byte is an e } } }
//////////////////////////
void sendGET() //client function to send/receive GET request data. { if (client.connect(serverName, 80)) { //starts client connection, checks for connection Serial.println("connected"); client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text client.println("Host: web.comporium.net"); client.println(); //end of get request } else { Serial.println("connection failed"); //error message if no client connect Serial.println(); }
while(client.connected() && !client.available()) delay(1); //waits for data while (client.connected() || client.available()) { //connected or data available char c = client.read(); //gets byte from ethernet buffer Serial.print(c); //prints byte to serial monitor }
Serial.println(); Serial.println("disconnecting."); Serial.println("=================="); Serial.println(); client.stop(); //stop client
}
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 3
|
 |
« Reply #3 on: January 19, 2013, 04:24:28 pm » |
@billroy code was example from ethernet library, unmodifided. /* 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 modified 9 Apr 2012 by David A. Mellis */
#include <SPI.h> #include <Ethernet.h>
// 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 }; IPAddress server(173,194,33,104); // Google
// 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;
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: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: for(;;) ; } // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting...");
// if you get a connection, report back via serial: if (client.connect(server, 80)) { Serial.println("connected"); // Make a HTTP request: client.println("GET /search?q=arduino HTTP/1.0"); client.println(); } else { // kf you didn't get a connection to the server: Serial.println("connection failed"); } }
void loop() { // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { char c = client.read(); Serial.print(c); }
// if the server's disconnected, stop the client: if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop();
// do nothing forevermore: for(;;) ; } }
@zoomkat Output from posted code is: Better client test 9/22/12 Send an e in serial monitor to test connection failed
disconnecting. ================== But if i change serverName to IPAddress server(192,168,1,2); , i do get proper response. Tried even in 1.0.1 IDE, but that doesnt change anything. Will try to inspect raw tcp traffic. thanks, Martin
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 37
Posts: 974
Get Bitlash: http://bitlash.net
|
 |
« Reply #4 on: January 19, 2013, 04:42:00 pm » |
Still smells like a gateway configuration issue. A quick test might be to explicitly initialize the gateway using the "Ethernet.begin(mac, ip, dns, gateway); " form of the ethernet.begin call. http://arduino.cc/en/Reference/EthernetBegin-br
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 3
|
 |
« Reply #5 on: January 19, 2013, 04:55:15 pm » |
Tried that but doesn't change anything.
Looks like networking error to me too, but i don't now how to debug it on arduino.
thanks, Martin
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 37
Posts: 974
Get Bitlash: http://bitlash.net
|
 |
« Reply #6 on: January 19, 2013, 05:19:11 pm » |
Your earlier post about capturing the network traffic is a good next step. WireShark isn't too hard to set up if you have a PC on that network segment.
The ARP traffic should be highly revealing...
-br
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Sr. Member
Karma: 9
Posts: 351
|
 |
« Reply #7 on: January 19, 2013, 05:27:45 pm » |
@billroy code was example from ethernet library, unmodifided. // 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 }; You said unmodified, but you do realise you have to modify this part to set your device MAC address? The other thing is, might you have your router set for security where you need to specify allowed MAC addresses?
|
|
|
|
« Last Edit: January 19, 2013, 05:30:17 pm by tack »
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 37
Posts: 974
Get Bitlash: http://bitlash.net
|
 |
« Reply #8 on: January 19, 2013, 05:29:45 pm » |
The shield has always worked fine for me with the 0xDEADBEEF MAC address, as long as there's not another node on the same LAN with the same address.
-br
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6546
Arduino rocks
|
 |
« Reply #9 on: January 19, 2013, 06:15:07 pm » |
Client test code that allows for specifying ip addresses. //zoomkat 4-04-12 //simple client test //for use with IDE 1.0 //open serial monitor and send an e to test //for use with W5100 based ethernet shields //note that the below bug fix may be required // http://code.google.com/p/arduino/issues/detail?id=605 //the arduino lan IP address { 192, 168, 1, 102 } may need //to be modified modified to work with your router.
#include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address byte ip[] = { 192, 168, 1, 102 }; // ip in lan assigned to arduino //byte gateway[] = { 192, 168, 1, 1 }; // internet access via router //byte subnet[] = { 255, 255, 255, 0 }; //subnet mask byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address EthernetClient client; //////////////////////
void setup(){
Ethernet.begin(mac, ip); //Ethernet.begin(mac, ip, gateway, gateway, subnet); Serial.begin(9600); Serial.println("Better client test 4/04/12"); // so I can keep track of what is loaded Serial.println("Send an e in serial monitor to test"); // what to do to test }
void loop(){ // check for serial input if (Serial.available() > 0) //if something in serial buffer { byte inChar; // sets inChar as a byte inChar = Serial.read(); //gets byte from buffer if(inChar == 'e') // checks to see byte is an e { sendGET(); // call sendGET function below when byte is an e } } }
//////////////////////////
void sendGET() //client function to send/receive GET request data. { if (client.connect(myserver, 80)) { //starts client connection, checks for connection Serial.println("connected"); client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text client.println(); //end of get request } else { Serial.println("connection failed"); //error message if no client connect Serial.println(); }
while(client.connected() && !client.available()) delay(1); //waits for data while (client.connected() || client.available()) { //connected or data available char c = client.read(); //gets byte from ethernet buffer Serial.print(c); //prints byte to serial monitor }
Serial.println(); Serial.println("disconnecting."); Serial.println("=================="); Serial.println(); client.stop(); //stop client
}
|
|
|
|
|
Logged
|
|
|
|
|
|