Git Product home page Git Product logo

Comments (8)

devyte avatar devyte commented on September 18, 2024

Something along these lines is what I had in mind (untested!):

bool NTPClient::setNtpServerName(String ntpServerName, int idx)
{
	if ((idx >= 0) && (idx <= 2)) {
		char * buffer = (char *)malloc((ntpServerName.length()+1) * sizeof(char));
		if(buffer == nullptr)
			return false;
		sntp_stop();
		char * old = sntp_getservername(idx);
		free(old); //if old is nullptr, nothing happens, per standard
		ntpServerName.toCharArray(buffer, ntpServerName.length()+1);
		sntp_setservername(idx, buffer);
		DEBUGLOG("NTP server %d set to: %s \r\n", idx, buffer);
		sntp_init();
		return true;
	}
	return false;
}

from ntpclient.

gmag11 avatar gmag11 commented on September 18, 2024

You're right, thank you.

Have you tested that this code works?

char * old = sntp_getservername(idx);
free(old);

If so, please make a pull request. If you can't (for any reason) please let me know.

Regards

from ntpclient.

trentbrown13 avatar trentbrown13 commented on September 18, 2024

I am using a program(s) that use ntpClientLib with modem sleep. When using ntpClientLib, there is a heap loss on every re-connect when the modem "wakes" up and ntp restarts until I finally run out of memory and it resets (usually around 24+ hours with a 1 minute sleep).
If I comment out (or #ifdef out) all ntp references and just let the modem disconnect/reconnect the heap stays stable.

I'll be glad to try any proposed patch if you need a tester

thanks
-trent

from ntpclient.

gmag11 avatar gmag11 commented on September 18, 2024

Most probably, as there is a reconnection of WiFi network new object instances are created without cleaning old ones out.
I'm rewritting this lib completely to add new features. Currently it uses Espressif internal SDK sntp funtions, so I'm restricted to its features. Development is slower than I would like so there is no ETA yet.
As a workaround you can use TimeLib examples together with sntp from SDK. It should work.

from ntpclient.

trentbrown13 avatar trentbrown13 commented on September 18, 2024

Thank you, I'll be glad to try out your new lib when you are ready for some testing.

As a workaround (still using your library) I start ntp just once in setup and let it run through each connect/disconnect by not restarting it with onSTAGotIP event. My modem sleeps are fairly short (< 1 minute) so it apparently works fine for this application.

from ntpclient.

devyte avatar devyte commented on September 18, 2024

@gmag11 I've been testing the proposed code for a while, and it seems to work well. Now that I finished the cleanup of the Arduino issues I'm moving on to PRs, so I'll be making one of this soon.

from ntpclient.

trentbrown13 avatar trentbrown13 commented on September 18, 2024

This is probably a stupid question/observation, but all my esp's running NtpClient started reporting current time as current time minus 1 hour this morning (11-01-2017). At first I thought all of them had crashed an hour ago (very weird) but then saw the stats were updating. It is close to daylight savings time change (this coming Sunday, 11-05-2017) and I am on PST time .

Setup is like this
Global:
int8_t timeZone = -8

in setup:
NTP.begin("pool.ntp.org", timeZone, true);
NTP.setInterval(63);

and publishing is like this
void publishNTP(void)
{
String currDate = NTP.getTimeDateString();
String upTime = NTP.getUptimeString();
String bootDate = (NTP.getTimeDateString(NTP.getFirstSync()).c_str());

client.publish("TbOfficeClient/upTime", upTime.c_str());
client.publish("TbOfficeClient/currTime", currDate.c_str());
client.publish("TbOfficeClient/bootTime", bootDate.c_str());

}

from ntpclient.

gmag11 avatar gmag11 commented on September 18, 2024

Please test new beta version on https://github.com/gmag11/NtpClient/tree/pre2.5.0. I've rewritten all sync stuff and added ESP32 as supported platform.

from ntpclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.