Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set function to define the response timeout #189

Open
CNSNGopenSourceProjects opened this issue Mar 6, 2023 · 0 comments
Open

Add set function to define the response timeout #189

CNSNGopenSourceProjects opened this issue Mar 6, 2023 · 0 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@CNSNGopenSourceProjects
Copy link

CNSNGopenSourceProjects commented Mar 6, 2023

I like very much you library, but the 1000ms timeout (on forceUpdate) is too short some time.
I would like to make a suggestion to create a function to allow the definition of the response timeout to be used on forceUpdate().
The default value will be 1000ms, but it can be increased if necessary.

Just for reference, I did the following changes on my implementation for Arduino + ESP32:
On NTPClient.h:

::::::::::::::::::
    unsigned long _responceTimeout = 1000;  // In ms		// <--FC
::::::::::::::::::
    /**
     * Changes the response timeout. Cannot be lower than 1000ms.
     */
	void setTimeResponse(unsigned long timeResponse);	// <- FC
::::::::::::::::::

On NTPClient.cpp:

::::::::::::::::::
bool NTPClient::forceUpdate() {
::::::::::::::::::  // Wait till data is there or timeout...
  // byte timeout = 0;				// <--FC
  unsigned long timeout = 0;		// <--FC
  int cb = 0;
  do {
    delay ( 10 );
    cb = this->_udp->parsePacket();
    //if (timeout > 100) return false; // timeout after 1000 ms		// <--FC
    if (timeout > this->_responceTimeout) return false; // timeout 	// <--FC
    //timeout++;					// <--FC
    timeout+=10;					// <--FC
  } while (cb == 0);

  //this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time	// <--FC
  this->_lastUpdate = millis() - timeout + 10; // Account for delay in reading the time			// <--FC
::::::::::::::::::
void NTPClient::setTimeResponse(unsigned long timeResponse) {					// <- FC
  this->_responceTimeout     = (timeResponse <= 1000) ? 1000 : timeResponse;	// <- FC
}									
::::::::::::::::::

Best regards,

Fernando

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

2 participants