Error compiling Ethernet sketch

I am using the following sketch to test my new Ethernet shield, but it does not compile, giving errors see below) :

//zoomkat 12-08-11, combined client and server
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor and send an g to test client and
//see what the arduino client/server receives
//web page buttons make pin 4 high/low
//use the \ slash to escape the " in the html 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

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

//changed this section :
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
//IPAddress ip(192,168,1,102); // ip in lan
//IPAddress gateway(192,168,1,1); // internet access via router
//IPAddress subnet(255,255,255,0); //subnet mask
//IPAddress myserver(208,104,2,86); // zoomkat web page
//EthernetServer server(84); //server port

//changed to :
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
IPAddress ip(192,168,1,101); // ip in lan
IPAddress gateway(192,168,1,254); // internet access via router
IPAddress subnet(255,255,255,0); //subnet mask
IPAddress myserver(41,204,200,12);
EthernetServer server(82); //server port

EthernetClient client;
String readString; 


//////////////////////

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  Ethernet.begin(mac, ip, subnet, gateway); 
  server.begin();
  Serial.begin(9600); 
  Serial.println("server/client 1.0 test 12/08/11"); // keep track of what is loaded
  Serial.println("Send an g in serial monitor to test client"); // what to do to test client

  
  }

void loop(){
  // check for serial input
  if (Serial.available() > 0) 
  {
    byte inChar;
    inChar = Serial.read();
    if(inChar == 'g')
    {
      sendGET(); // call sendGET function
    }
  }  

  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

            //now output HTML data header
          if(readString.indexOf('?') >=0) { //don't send new page
            client.println("HTTP/1.1 204 Zoomkat");
            client.println();
            client.println();  
          }
          else {
            client.println("HTTP/1.1 200 OK"); //send new page
            client.println("Content-Type: text/html");
            client.println();

            client.println("<HTML>");
            client.println("<HEAD>");
            client.println("<TITLE>Arduino GET test page</TITLE>");
            client.println("</HEAD>");
            client.println("<BODY>");

            client.println("<H1>Zoomkat's simple Arduino 1.0 button</H1>");

            client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>"); 
            client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>"); 

            //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
            client.println("<IFRAME name=inlineframe style=\"display:none\" >");          
            client.println("</IFRAME>");

            client.println("</BODY>");
            client.println("</HTML>");
          }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
} 

//////////////////////////
void sendGET() //client function to send/receie GET request data.
{
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0");
    client.println();
  } 
  else {
    Serial.println("connection failed");
    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();
    Serial.print(c);
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop();

}

However, it does not compile, giving the following errors :

In file included from C:\Program Files\arduino\libraries\Ethernet/Client.h:3,
                 from C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:5,
                 from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:7,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\hardware\arduino\cores\arduino/WProgram.h:22: error: default argument given for parameter 3 of 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/wiring.h:120: error: after previous specification in 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/WProgram.h:24: error: default argument given for parameter 3 of 'void tone(uint8_t, unsigned int, long unsigned int)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Arduino.h:201: error: after previous specification in 'void tone(uint8_t, unsigned int, long unsigned int)'
In file included from C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:5,
                 from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:7,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/Client.h:15: error: conflicting return type specified for 'virtual void Client::write(uint8_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Client.h:17: error: conflicting return type specified for 'virtual void Client::write(const uint8_t*, size_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:50: error:   overriding 'virtual size_t Print::write(const uint8_t*, size_t)'
In file included from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:7,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:17: error: conflicting return type specified for 'virtual size_t EthernetClient::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Client.h:15: error:   overriding 'virtual void Client::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:18: error: conflicting return type specified for 'virtual size_t EthernetClient::write(const uint8_t*, size_t)'
C:\Program Files\arduino\libraries\Ethernet/Client.h:17: error:   overriding 'virtual void Client::write(const uint8_t*, size_t)'
In file included from C:\Program Files\arduino\libraries\Ethernet/EthernetServer.h:4,
                 from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:8,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/Server.h:17: error: conflicting return type specified for 'virtual void Server::write(uint8_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Server.h:19: error: conflicting return type specified for 'virtual void Server::write(const uint8_t*, size_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:50: error:   overriding 'virtual size_t Print::write(const uint8_t*, size_t)'
In file included from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:8,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/EthernetServer.h:17: error: conflicting return type specified for 'virtual size_t EthernetServer::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Server.h:17: error:   overriding 'virtual void Server::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/EthernetServer.h:18: error: conflicting return type specified for 'virtual size_t EthernetServer::write(const uint8_t*, size_t)'
C:\Program Files\arduino\libraries\Ethernet/Server.h:19: error:   overriding 'virtual void Server::write(const uint8_t*, size_t)'

I have the Ethernet and SPI libraries in place as they were installed when I originally installed the Arduino IDE.

Suggestions please.

I have the Ethernet and SPI libraries in place as they were installed when I originally installed the Arduino IDE.

Are you using the arduino 1.0 IDE?

Yes 1.0

If you are using v1.0 or later, then this is incorrect:

pinMode(4, OUTPUT); //pin selected to control
  Ethernet.begin(mac, ip, subnet, gateway);

You are activating the SD SPI interface, and the wondering why there is trash on the SPI interface.

pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac,ip,dns,gateway,subnet);

You are activating the SD SPI interface, and the wondering why there is trash on the SPI interface.

That is interesting. It works fine for me. Does the OP have undisclosed equipment connected to pin 4 that is causing the compile issue? If nothing is effectivly connected to pin 4, then what is the orgin of the "trash"?

There is nothing connected to pin 4.

The errors appear at the bottom of the IDE during compiling, before it starts uploading.

Isn't the SPI related to the SD card ? I do not have an SD card in the slot on the ethernet shield.

Is it possible that the Ethernet or SPI Library on my PC is outdated ? If so, is there a link where I can download the latest versions of Ethernet and SPI ?

I do recall some IDE update a short while back that changed the file extensions for the sketches.

Holy cow! Where have you been? If this is an ethernet shield, digital pin 4 is the Slave Select pin for the SD SPI interface. Sometimes I wonder why I do this...

Is it possible that the Ethernet or SPI Library on my PC is outdated ? If so, is there a link where I can download the latest versions of Ethernet and SPI ?

When I download a new IDE version, I make a new folder for it so there is no mixing of the librarys (I make seperate shortcuts to the arduino.exe files so I have all the old IDEs available as needed). You might reload the 1.0 IDE to make sure you have the latest files.

SurferTim:
Holy cow! Where have you been? If this is an ethernet shield, digital pin 4 is the Slave Select pin for the SD SPI interface. Sometimes I wonder why I do this...

@SurferTim

Very unfair comment I think.

I am a complete novice to Arduino and electronics, so please excuse me as an idiot if I'm not up on your level. I was hoping to use the forum to help learn and solve problems - just like zoomkat has kindly done with his constructive posts.

Tomorrow, I will know more that I did the day before. You, however, will most likely still be an ass.

SurferTim:
Holy cow! Where have you been? If this is an ethernet shield, digital pin 4 is the Slave Select pin for the SD SPI interface. Sometimes I wonder why I do this...

If there is nothing connected to pin 4, where does the trash come from? I have an older ethernet shield so I can't do an actual test, but from what you say with a new ethernet shield has issues with pin 4 being used for anything but an spi interface. I currently use IDE1.0-rc2 and have no compile errors. How does any connection to pin 4 impact compiling the code?

zoomkat:

Is it possible that the Ethernet or SPI Library on my PC is outdated ? If so, is there a link where I can download the latest versions of Ethernet and SPI ?

When I download a new IDE version, I make a new folder for it so there is no mixing of the librarys (I make seperate shortcuts to the arduino.exe files so I have all the old IDEs available as needed). You might reload the 1.0 IDE to make sure you have the latest files.

Thanks zoomkat. I will download and re-install the IDE.

If there is nothing connected to pin 4, where does the trash come from?

Holy cow!! There are two of you?? Digital pin 4 is the SD SPI control.

edit: My code works. Yours doesn't. Bear that in mind while you try all the alternatives. :smiley:

Holy cow!! There are two of you?? Digital pin 4 is the SD SPI control.

In the current arduino librarys developed for hardware interface, it appears that pin 10 is used for spi interface with an ethernet shield and pin 4 is used as the interface pin for an SD device. Have you actually tried compiling the code I posted? If so, what errors do you get? Just to minimize potential future issues when SD cards are actually being used, I'll change the test pin to 5 or similar. :wink:

Frank knew that no man had ever crossed the desert on foot and lived to tell about it. So, he decided to get back in his car and keep driving. - Deep Thoughts by Jack Handy

edit: My code works. Yours doesn't. Bear that in mind while you try all the alternatives

My code compiles with the arduino IDE I'm using without errors (I have made the library mod you posted in the past, but that should not impact compiling), which is technically different than "My code works". My code also "works" with IE 8 on my laptop. I'm just trying to avoid chasing "phantom" issues that turn out to be distractors from the acual issue.

Frank knew that no man had ever crossed the desert on foot and lived to tell about it. So, he decided to get back in his car and keep driving. - Deep Thoughts by Jack Handy

Where in the desert are you? Can you see anything from where you are?

Yes 1.0

The 1.0 version does not have a WProgram.h file. So, how are you getting errors related to that file having been included?

OK. I have re-installed the IDE from a fresh download and the Ethernet sketch now compiles and uploads perfectly. Therefore I can only assume that the libraries that were installed as part of my first original ( 1.0 ) installation were not compatible with the upgrade to the latest IDE 1.0

However, I did have a problem with another sketch that uses the Dallas Temperature library. Had to make a change to the .cpp file as reply#5 here :

to zoomkat, my sincere thanks for the assistance.

to zoomkat, my sincere thanks for the assistance.

No, problem. Now you know how this forum works. :wink:

OK. Trying to understand why strange behaviour on the board.

I have the code working, but still don't understand why I had problems.

My setup :
Mega 2560
new Ethernet Shield
Port forwarding for port 82 set in the router.
Current IP xx.xx.xx.xx:82 viewed from a browser which displays the test page from the Arduino 100% OK : Zoomkat's simple Arduino 1.0 button ON OFF

I had the inputs for my home panic system ( linked to a remote security company ) on pins 14 & 15
The relay that activates the radio signal is on pin 9
LCD was on 2,3,4,5,6,7

I moved the LCD to 18,17,16,5,6,7
Also moved the panic inputs to 2,3

pins 4 and 10 both empty

System works fine, until I try to GET data to my php page.

in my temperature sensor reading code, I have added the LogItWeb line here :

  float tempC1 = readTemperature(outsideThermometer);
  float tempC2 = readTemperature(insideThermometer);
  LogItC("Temp In : ",0);
  LogItF(1,tempC2,0,4);
  LogItWeb(1,tempC2);
  LogItC(" -- Out : ",0);
  LogItF(2,tempC1,1,4);

The LogItWeb goes to :

void LogItWeb(int Location, float LogTxt){
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.print("GET http://www.myserver.com/serveit.php?data=");
    client.print(Location);
    client.print("--");
    client.print(LogTxt);
    client.println(" HTTP/1.1");
    client.println("Host: www.myserver.com");  // i found my server rejects the connection if this line is not present
    client.println();
 
    while(client.connected() && !client.available()) delay(1); //waits for data
    while (client.connected() || client.available()) { //connected or data available
      char c = client.read();
      Serial.print(c);
    }
    client.stop();
    Serial.println("disconnected");
    Serial.println("==================");
  } 
  else {
    Serial.println("connection failed");
    Serial.println("==================");
  }
}

I can see that the ethernet code is calling the php file and writing to the txt file on my web server.
I am getting exactly as expected :
IP address : xx.xx.xx.xx 2012-04-01---12:02:27 1--26.25

However, once it has run once, it seems to activate my panic system relay ( pin 9) and then freezes the system. The temp readings on the LCD are not updating and I have to re-set the system.

Can you see anything in the LogItWeb function that would cause this erratic behaviour ?

What I am seeing in the Serial Monitor as soon as I reset is :

server/client 1.0 test 12/08/11
Send get1 in serial monitor to test client
Setup Completed - System Operational
Setup Completed - Checking SMS state
EEProm read
EEProm = 0 (sms OFF, Home)
Temp In : 26.25
connected
HTTP/1.1 200 OK
Date: Sun, 01 Apr 2012 10:02:56 GMT
Server: Apache/2.2.16 (Debian) mod_fcgid/2.3.6 mod_ssl/2.2.16 OpenSSL/0.9.8o mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.3-7+squeeze8
Content-Length: 0
Content-Type: text/html

I would expect the next line to be :
-- Out : 26.25
but it would appear that the sketch is freezing in the section where it waits for a reply from the web server.

Next, I added a short delay (250) and commented out the section of code that I think waits for a response from the web server. Everything seems to be working fine now. Could it be that because my web side php script receives the data and writes it to a web side txt file, but doesn't actually send anything back to the Arduino ?

I found that before this mod the Rx LED on the ethernet board was on constantly. Was that because it was always waiting for incoming data ?

I just don't understand why the unmodified code would activate my panic system relay on pin 9 ( activates the relay with a ground / low signal ).

The new function :

void LogItWeb(int Location, float LogTxt){
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.print("GET http://www.imagedisk.co.za/serveit.php?data=");
    
    client.print(Location);
    client.print("--");
    client.print(LogTxt);
    client.println(" HTTP/1.1");
    client.println("Host: www.imagedisk.co.za");
    client.println();
 
    delay(250);
 
//    while(client.connected() && !client.available()) delay(1); //waits for data
//    while (client.connected() || client.available()) { //connected or data available
//      char c = client.read();
//      Serial.print(c);
//    }
 
    client.stop();
 
    Serial.println("disconnected");
    Serial.println("==================");
  } 
  else {
    Serial.println("connection failed");
    Serial.println("==================");
  }
}

Couple things I see. When you construct the GET line in the request, are there any illegal characters in the filename, like spaces? No spaces allowed. They are %20.

I would expect the next line to be :
-- Out : 26.25

Then, you should probably send a close connection after the host. If you send an HTTP/1.1 request, the server may not close that end unless you send that.

  client.println("Host: www.myserver.com");
  client.println("Connection: close");
  client.println();