Problems with NTP and Server

Working with an Uno + Ethernet + SD.
I’m trying to write a library called NetworkSensor which will abstract away the messy details of logging timestamped data to a file and serving that data back over a network. I have some middle- and high-school students who will be using this library to write their own simple sensors, so I need the library to take care of anything more complicated than, analogRead(), delay(), etc.

The given example code in Time > TimeNTP works fine. When I copied that code into my NetworkSensor class, I’m no longer getting any UDP responses. I thought that maybe my EthernetServer instance was getting in the way, but at least according to this stack overflow post, there’s no good way to stop the server.

Am I doing anything blatantly wrong here? Or subtley wrong? Has anyone else had success hiding NTP synchronization away in a class?

NetworkSensor.cpp (6.15 KB)

NetworkSensor.h (2.56 KB)

Am I doing anything blatantly wrong here?

Probably running out of memory. You have a lot of string literals that get into SRAM, that don’t need to.
Serial.println(F(“Serial connection ready.”));

There are other things that are wrong, too:

  pinMode(ETHSS, OUTPUT);
  pinMode(SDSS,  OUTPUT);

This assumes that the hardware is ready. It probably isn’t, since your constructor is called (probably) before the init() function that gets the hardware ready. You’ve no doubt seen that HardwareSerial has a begin() method. Your class should, too.

The issue persists after moving code from the constructor to a separate begin() method and removing a bunch of Strings. (I doubt the strings really take up that much space).

compiler: Binary sketch size: 22142 bytes (of a 32256 byte maximum)

Does that address the memory issue at all?

(I doubt the strings really take up that much space).

Which Arduino are you using? The 328-based machines have only 2K of SRAM. The SD library needs 1/4 of that to open 1 file. Your strings DO take up a lot of space - 1 byte per character.

Does that address the memory issue at all?

No, but it does tell me that you have a 328-based Arduino.