SOLVED: Problems Ethernet.h

I just received my Ethernet W5100 shield.

I try to synchronize the DS1307 RTC via the NTP server.

The library Ethernet.h is installed, but during compilation of my program I get the error:

Test_syncing_DS1307_01.ino:16:22: fatal error: Ethernet.h: No such file or directory
compilation terminated.
Error compiling.

Who can test / adapt my program?
Otherwise: who has a working solution

/*
Trying to synchronize RTC with NetworkTimeProtocl.
Original post http://www.bajdi.com/syncing-ds1307-rtc-with-timeserver/
All other stuff removed to focuss to job

Hardware:
- Arduino Mega 2560 Rev.3
- Ethernet Schield W5100
- RTC DS1307

Software:
- Version 1.6.1

Edited: C.W.A. Baltus, 20160323
 */

//=============================================================================
//Libraries
#include <Ethernet.h>
#include <EthernetUdp.h>
#include "RTClib.h"
#include <SPI.h>
#include <Wire.h>

unsigned int localPort = 8888;             // local port to listen for UDP packets
byte timeServer[] = {81, 95, 126, 170};    // be.pool.ntp.org NTP server  
const int NTP_PACKET_SIZE= 48;             // NTP time stamp is in the first 48 bytes of the message
byte pb[NTP_PACKET_SIZE];                  // buffer to hold incoming and outgoing packets

//Set external devices
RTC_DS1307 RTC;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,168, 14 };    //Edited 20160319

Server server(80);

const int chipSelect = 4;      // CS for SD card

//=============================================================================
void setup()
{
  Serial.begin(9600);
  lcd.begin(20, 4);        // set the LCD address to 0x20 for a 16 chars and 2 line display
  Ethernet.begin(mac, ip);
  server.begin();
  Wire.begin();
  RTC.begin();
  
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(__DATE__, __TIME__));
    }   //End if
    
  //Step 1: Set a wrong time
  RTC.adjust(DateTime(1952, 7, 2, 10, 15, 0));   //1952, July 2
  DateTime now = RTC.now();
  //Compile strings
  strDate = String(now.year());
  strDate.concat("-");
  strDate.concat(strNumber[now.month()]);
  strDate.concat("-");
  strDate.concat(strNumber[now.day()]);
  
  strTime = strNumber[now.hour()];
  strTime.concat(":");
  strTime.concat(strNumber[now.minute()]);
  strTime.concat(":");
  strTime.concat(strNumber[now.second()]);
  Serial.println(strDate & "  " & strTime);
    
  //Step 2: Wait 5 seconds
  delay(5000(;
  
  //Step 3: Adjust time with timeserver
  DateTime now = RTC.now();     // get wrong time from RTC
  int time = now.second();
 
  Client client = server.available();
  Udp.begin(localPort);
  delay(250);
  // send an NTP packet to a time server
  sendNTPpacket(timeServer);

  // wait to see if a reply is available
  delay(1000);
  if ( Udp.available() ) {
      // read the packet into the buffer
      Udp.readPacket(pb, NTP_PACKET_SIZE);

      // NTP contains four timestamps with an integer part and a fraction part
      // we only use the integer part here
      unsigned long t1, t2, t3, t4;
      t1 = t2 = t3 = t4 = 0;
      for (int i=0; i< 4; i++)
      {
        t1 = t1 << 8 | pb[16+i];      
        t2 = t2 << 8 | pb[24+i];      
        t3 = t3 << 8 | pb[32+i];      
        t4 = t4 << 8 | pb[40+i];
      }

      // part of the fractional part
      // could be 4 bytes but this is more precise than the 1307 RTC
      // which has a precision of ONE second
      // in fact one byte is sufficient for 1307
      float f1,f2,f3,f4;
      f1 = ((long)pb[20] * 256 + pb[21]) / 65536.0;      
      f2 = ((long)pb[28] * 256 + pb[29]) / 65536.0;      
      f3 = ((long)pb[36] * 256 + pb[37]) / 65536.0;      
      f4 = ((long)pb[44] * 256 + pb[45]) / 65536.0;

      const unsigned long seventyYears = 2208988800UL;
      t1 -= seventyYears;
      t2 -= seventyYears;
      t3 -= seventyYears;
      t4 -= seventyYears;

      // Adjust timezone and DST... in my case substract 4 hours for Chile Time
      // or work in UTC?
      t4 += (2 * 3600L);     // Notice the L for long calculations!!
      t4 += 1;               // adjust the delay(1000) at begin of loop!
      if (f4 > 0.4) t4++;    // adjust fractional part, see above
      RTC.adjust(DateTime(t4));
      
  Serial.println("RTC synced");
  //Show adjusted time
  DateTime now = RTC.now();
  //Compile strings
  strDate = String(now.year());
  strDate.concat("-");
  strDate.concat(strNumber[now.month()]);
  strDate.concat("-");
  strDate.concat(strNumber[now.day()]);
  
  strTime = strNumber[now.hour()];
  strTime.concat(":");
  strTime.concat(strNumber[now.minute()]);
  strTime.concat(":");
  strTime.concat(strNumber[now.second()]);
  Serial.println(strDate & "  " & strTime);    
    }
    
  }
  
}  //End setup

//=============================================================================
void loop()
{
//Empty
}

Test_syncing_DS1307_01.ino (4.37 KB)

Check that Ethernet.h exist on your computer in the right place.

Either under something like C:\program files\Arduino... or in the libraries folder which is next to where your own sketches are stored.

When I try to compile your ancient code, I get:

sketch_mar23a:36: error: no matching function for call to 'Server::Server(int)'

As of Arduino 1.0, the Server class in the Ethernet library has been renamed to EthernetServer.

C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Server.h:4: note: candidates are: Server::Server()
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Server.h:4: note: Server::Server(const Server&)
sketch_mar23a:36: error: cannot declare variable 'server' to be of abstract type 'Server'
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Server.h:4: note: because the following virtual functions are pure within 'Server':
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Print.h:48: note: virtual size_t Print::write(uint8_t)
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Server.h:6: note: virtual void Server::begin()
sketch_mar23a.ino: In function 'void setup()':
sketch_mar23a:44: error: 'lcd' was not declared in this scope
sketch_mar23a:59: error: 'strDate' was not declared in this scope
sketch_mar23a:61: error: 'strNumber' was not declared in this scope
sketch_mar23a:65: error: 'strTime' was not declared in this scope
sketch_mar23a:73: error: expected primary-expression before ';' token
sketch_mar23a:76: error: redeclaration of 'DateTime now'
sketch_mar23a:57: error: 'DateTime now' previously declared here
sketch_mar23a:79: error: 'class Server' has no member named 'available'
sketch_mar23a:79: error: cannot declare variable 'client' to be of abstract type 'Client'
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:7: note: because the following virtual functions are pure within 'Client':
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:12: note: virtual size_t Client::write(uint8_t)
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:13: note: virtual size_t Client::write(const uint8_t*, size_t)
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:14: note: virtual int Client::available()
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:15: note: virtual int Client::read()
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:17: note: virtual int Client::peek()
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:18: note: virtual void Client::flush()
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:10: note: virtual int Client::connect(IPAddress, uint16_t)
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:11: note: virtual int Client::connect(const char*, uint16_t)
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:16: note: virtual int Client::read(uint8_t*, size_t)
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:19: note: virtual void Client::stop()
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:20: note: virtual uint8_t Client::connected()
C:\Users\pjs9486\Documents\Arduino_105\hardware\arduino\cores\arduino/Client.h:21: note: virtual Client::operator bool()
sketch_mar23a:80: error: 'Udp' was not declared in this scope

As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.

sketch_mar23a:83: error: 'sendNTPpacket' was not declared in this scope
sketch_mar23a.ino: At global scope:
sketch_mar23a:146: error: expected declaration before '}' token

When you fix all these issues, if you still have problems, feel free to post the modified code AND the complete list of errors.

My knowledge of libraries is too limited.
I'm sure that the libraries are installed.

I use version 1.6.1. and get only 1 (!!!) error message (see attachment).

Maybe you can explain what I have to do; some errors are solved (see version 2)

Test_syncing_DS1307_02.ino (4.3 KB)

I'm sure that the libraries are installed.

Where? Did you (try to) do something to make that happen? You should NOT have.

char *strDate[11], *strTime[9], *Text1[9];

Why do you have arrays of pointers?

  strDate = String(now.year());

WTF? You can't store a String instance in an array of pointers to char.

  strDate.concat("-");\

Arrays do not have methods.

  now = RTC.now();     // get wrong time from RTC

Why do you assume that the time is wrong?

  Serial.println("RTC synced");
  //Show adjusted time
  DateTime now = RTC.now();

By creating a local variable with the same name as a global one? What a crappy idea.

  Serial.println(strDate & "  " & strTime);

I REALLY don't think bitwise anding arrays is anything even remotely like a good idea.

ArduinoStarter1:
The library Ethernet.h is installed, but during compilation of my program I get the error:

I tried compiling your program and only got one error:

: RTClib.h: No such file or directory #include "RTClib.h"

but that is right because I don't have that library

Now the question is how do you know that Ethernet.h is installed? On my system (64 bit Windows 7) I have the file here:

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.h

Can you find yours?

Location: D:\Arduino\libraries\Ethernet\src\Ethernet.h

ArduinoStarter1:
Location: D:\Arduino\libraries\Ethernet\src\Ethernet.h

A mystery inside an enigma. Do you have one here too:

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.h

?

And just to make things really simple could you write a sketch which only includes Ethernet.h?

#include <Ethernet.h>


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Just to try to home in onto the problem...

(By the way I'm using Arduino 1.6.7, what is your version?)

ArduinoStarter1:
Location: D:\Arduino\libraries\Ethernet\src\Ethernet.h

And in the Arduino menu, Sketch -> Included Libaries -> there is a list of included libraries.

(Your menu text may be different, I'm reading mine in Italian and inventing the English. But that menu will show you which menus are installed.)

Also, do you have anything in...

C:\Users?...YourName...?\Documents\Arduino

?

For private reasons I installed the program in D:\Arduino, so all libraries are installed on D:\Arduino\libraries.

I discovered that a library was twice on my computer. I removed the second one and everything worked!!!!
I assume that version 1.6.1 can not get on with double existing libraries.

Problem solved.