Comments (8)
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.
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.
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.
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.
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.
@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.
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.
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)
- Problem in ESP32 HOT 2
- General dependency on ESP8266 library errors on ESP32 HOT 1
- Beta 3.0.2 version fails with ESP32 HOT 8
- ESPAsyncUDP dependency on esp32 HOT 3
- reference to 'map' is ambiguous HOT 3
- DST HOT 1
- Wrong time in NTPClientAvr example HOT 2
- ESP32 : memory leak ? HOT 6
- [idea] let the library wrap the SNTP SDK functions of ESP8266 and ESP32 HOT 4
- Please... is there any way to get the day of the week ? (Sunday, Monday etc.) Thanks HOT 2
- Getting error: "reference to 'byte' is ambiguous" with Arduino IDE1.8.15 HOT 11
- DST not working for USA default to EU Why? HOT 1
- Update PlatformIO Version HOT 1
- Hi, I know this is an old thread, but it annoys me.... And maybe it does not relate to you code, but any help would be appreciated. HOT 1
- _uptime definition error [Bug]
- The client and server's times differ by 136 years
- Arduino Library
- Failed DNS lookup leads to exception in ' void NTPClient::s_dnsFound ' HOT 1
- Dependency on Time lib 5.1; latest is 1.5 HOT 1
- Crash when in Async UDP library on ESP32 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ntpclient.