Offline
Newbie
Karma: 0
Posts: 8
|
 |
« on: January 23, 2012, 02:24:24 pm » |
Hello to everyone. I have a an Arduino board (Rev.3), an ethernet shield and I use the IDE 1.0 in Ubuntu 11.10 My problem is sending HTTP requests that arrive badly formatted to the web server (apache2): 192.168.1.69 - - [21/Jan/2012:13:42:28 +0100] "GET /arduino/ HTTP/1.0ogle.com" 200 285 "-" "-" 192.168.1.69 - - [21/Jan/2012:13:42:37 +0100] "GET /arduino/ HTTP/1.0://wGET /arduino/ HTTP/1.0" 200 285 "-" "-"192.168.1.69 - - [21/Jan/2012:13:42:28 +0100] "GET /arduino/ HTTP/1.0ogle.com" 200 285 "-" "-" 192.168.1.69 - - [21/Jan/2012:13:42:37 +0100] "GET /arduino/ HTTP/1.0://wGET /arduino/ HTTP/1.0" 200 285 "-" "-" 192.168.1.69 - - [21/Jan/2012:13:43:44 +0100] "\xf8\x1bF\x13J" 400 301 "-" "-"
I think it's a problem of buffer, but I can not understand how to solve. A snippet of code: byte server[]= {192,168,1,51}; byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xFF, 0xF3}; byte ip[]= {192,168,1,69}; byte gateway[] = { 192, 168, 1, 1 }; ////////////////////////////////////////////////////////////////////////
EthernetClient client;
void setup(){ Ethernet.begin(mac,ip,gateway); Serial.begin(9600); if (client.connect(server, 80)) { client.println("GET /arduino/ HTTP/1.0"); client.println(); } }
Thank you very much
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 59
Posts: 3547
|
 |
« Reply #1 on: January 23, 2012, 02:47:56 pm » |
Why just a snippet? Let's see it all! 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #2 on: January 23, 2012, 04:26:05 pm » |
Hi, thanks for your reply. I have simply modified this example http://bildr.org/2011/06/arduino-ethernet-client/ (Unfortunately it does not work) I don't understand what's the problem. Please help me 
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 59
Posts: 3547
|
 |
« Reply #3 on: January 23, 2012, 04:42:40 pm » |
"does not work" is very vague. I recommend trying the example in the IDE Examples folder. Under Ethernet, there is a web client. Probably more help available for that code.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 58
Posts: 6774
Arduino rocks
|
 |
« Reply #4 on: January 23, 2012, 11:27:44 pm » |
Client test code you can try. //zoomkat 12-08-11 //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
#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, subnet, gateway); Serial.begin(9600); Serial.println("Better client test 12/01/11"); // 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
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #5 on: January 24, 2012, 05:50:58 pm » |
Thanks zoomkat, I will try your code as soon as possible. Thank you very much 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #6 on: January 26, 2012, 04:02:51 pm » |
Hi zoomkat, unfortunately your code doesn't work in my installation I have also tried the bottom code but a "Malformed Packet Exception" occurred (I attach the packet detected with wireshark) /* 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 */
#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[] = {0x90, 0xA2, 0xDA, 0x00, 0xFF, 0xF3}; IPAddress server(173,194,35,56); // 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() { // start the serial library: Serial.begin(9600); // 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(;;) ; } }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 58
Posts: 6774
Arduino rocks
|
 |
« Reply #7 on: January 26, 2012, 08:35:18 pm » |
Below is what I get when I run my test code. My ISP is running an apache server, so perhaps your issue is with your apache setup. Better client test 12/01/11 Send an e in serial monitor to test connected HTTP/1.1 200 OK Date: Fri, 27 Jan 2012 01:33:24 GMT Server: Apache Last-Modified: Sat, 13 Nov 2010 16:31:40 GMT Accept-Ranges: bytes Content-Length: 51 Connection: close Content-Type: text/plain; charset=UTF-8
Woohoo! Your arduino ethernet client works! zoomkat disconnecting. ==================
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #8 on: January 27, 2012, 06:14:31 am » |
Sorry, I don't understand. In my last example I have tried to contact the google server. But beyond this, my ethernet shield doesn't acquire a good ip address. A "Malformed Packet Exception" occurred during DHCP discovery
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 59
Posts: 3547
|
 |
« Reply #9 on: January 27, 2012, 07:52:42 am » |
Hi zoomkat, unfortunately your code doesn't work in my installation "doesn't work" is still vague. Doesn't compile? Doesn't run? Where does zoomkat's code stop in "your installation"? What is the last message?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #10 on: January 27, 2012, 08:51:21 am » |
Hi ST,
my scketch is correctly compiled. It runs but It has the same problem of my first post: 1. the "get request" is badly formatted ("GET /arduino/ HTTP/1.0ogle.com" 200 285 "-" "-") 2. my serial monitor displays random characters without stopping
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 59
Posts: 3547
|
 |
« Reply #11 on: January 27, 2012, 09:00:08 am » |
OK. Then we will start with the stuff that causes interference like that with the w5100 chip. The first is the microSD SPI interface. void setup(){
// disable SD SPI interface pinMode(4,OUTPUT); digitalWrite(4,HIGH);
Ethernet.begin(mac, ip); //Ethernet.begin(mac, ip, subnet, gateway); Serial.begin(9600); Serial.println("Better client test 12/01/11"); // so I can keep track of what is loaded Serial.println("Send an e in serial monitor to test"); // what to do to test } Try that first, even tho I think this is going to be the second thing I recommend. How does that do? Still garbage out the serial monitor? Add: May as well make it one response. Here is another topic with the second suggestion. Read reply#6. http://arduino.cc/forum/index.php/topic,86729.0.html
|
|
|
|
« Last Edit: January 27, 2012, 09:10:22 am by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #12 on: January 27, 2012, 05:34:49 pm » |
I love you  I have read reply#6 and I solved by replacing the code in w5100.h Thank you very much
|
|
|
|
|
Logged
|
|
|
|
|
|