Advanced Users can post their questions and comments here for the not so Newbie crowd.

Moderator: eriksl

User avatar
By eriksl
#81569 Also interesting to know: by default LWIP works in a zero-copy model. Any chunk of data you supply to tcp or udp is used as-is without copying (and you can't change the memory until sent). Unless you supply the "please copy data" flag. Which I don't because I don't use it. Now it appears that Espressif has set a low-level device trait flag "always copy" and that overrides anything the user requests. So my data (up to 4k) is still copied before transmission. I tried turning off that flag, but it crashed. I will now try to do the same, but then with the payload alignment option of LWIP, which will insert a "nop option" between header and payload, making the payload aligned on 32 bits. That may or may not help. Fingers crossed ;-) If it works, it will spare me another 4k of ram...
User avatar
By davydnorris
#81573
eriksl wrote:I think using SNTP will yield a really not so bad timekeeping, if contrained to a local area network. Especially if repeated frequently. Probably in the order of 10ths or even 100ths of seconds.

I just had a quick glance at the SNTP spec and it's really easy to implement. I don't understand why Espressif needs so much code to implement it (and even then do a lousy job).

So this will be continued ;-)


Sampling the NTP stratum servers at that rate will get you knocked out - they get very upset if people sample too frequently. This is from the ntp.org Terms of Service:

4. End-User agrees that he or she will not:
(a) Change default settings to make more frequent request of the Services, if using an ntp daemon (“NTP Protocol”);
(b) Request time from the Services more than once every thirty (30) minutes (ideally at even longer intervals), if using SNTP.
(c) Set the time more often than is necessary for the purposes of the device; if the device can keep reasonably accurate time for several days, End-User will not set the time every hour. Additionally, if the device only uses whole seconds, End-User will not optimize the device for millisecond accuracy.
(d) Set up a regular time sync interval such as “top of the hour”, “top of the minute”, or “at minute or second X”.
Examples of Time Setting

BAD: setting the time daily at midnight;
GOOD: Setting the time at boot and every 36 hours after boot (rather than at a specific time);

BAD: Setting the time every 90 minutes at the “top of the minute” (0 seconds);
BETTER: Setting the time every 89 minutes plus random number of seconds between 0 and 120;

BAD – Setting the time every 2 minutes;
GOOD – Setting the time according to needs, for example every 4 hours or daily (or less often)
User avatar
By davydnorris
#81574
eriksl wrote: End goal is to have a clean "stock" LWIP with the minimum of patching to have it run on ESP8266. From there it should be doable to move on to LWIP 2.


WOW! This is incredible work - well done!
User avatar
By eriksl
#81576 Hi Dave,

I didn't mean "poll your server subsecond", I meant that if you poll your server frequently (e.g. once every ten minutes) the precision will be quite acceptable, i.e. subsecond.

Please note my reference context is a bit different, I am developing stuff that only runs in a local area network. Where I have one, my own NTP (1) server, my own DHCP (1) server, etc. No need for DNS either. I think (but who knows) most users will have a similar setup.

In the meantime I have succeed in making the pbuf allocation from LWIP completely static, with minimal unnecessary overhead. End result is 5200 bytes to be thrown in and completely lost, but LWIP will never ask for more, at any point and it will be able to send and receive payloads of 4k over tcp and udp, not bad imho.

That will make the work on the LWIP (2) migration easier (less dependence on Espressif code). BTW I've left the code for mem_alloc/pvPortAlloc etc. stuff in, it's selectable using the lwip/opt.h file.