WiFi time provider with NTP support.

More
1 year 4 months ago - 1 year 3 months ago #9638 by MikeS
I modified Ian's "v355" code to add support for NTP and timezones. If configured and reachable, the NTP source will be preferred but it will fall back to the "traditional" time server if the NTP server can't be reached. It uses the Arduino ezTime library.

The advantage is that there are _lots_ of ntp servers out there, so there's no reliance on using just one or two. By default, it points to an ntp pool server. Timezones with summertime changes are supported.

The sketch can be downloaded here .

Edit: I uploaded a newer version which fixes one bug and adds the ability to do OTA updates if you have an ESP-01 with at least 1 MB of flash (uncommon with ESP-8266, but there on any ESP-8285). If you downloaded earlier, grab the new "v355mjs.4" one.

Lightly tested.
Last edit: 1 year 3 months ago by MikeS. Reason: url for current version
The following user(s) said Thank You: Ian

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago - 1 year 3 months ago #9644 by MikeS
OK, looks like Ian sources ESP8266/ESP-01 modules with 1 MB of flash (he can confirm if that's true for all), so OTA should work on them.

One more update , to .5. This one has a lot of tweaks, but the two significant changes are support for basic security on any web pages which can change the config (passwords, web: admin/setup, update: admin/update), and it will sync to NTP within ~25 ms, usually better (the regular time service only had a granularity of 1 s). A .bin file suitable for flashing to a ESP8266/ESP-01 is in the zip. This is the file type which can be used for an OTA update.
Last edit: 1 year 3 months ago by MikeS. Reason: Make url point to current version

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago - 1 year 3 months ago #9647 by Phil_Mod3
Thank you Mike,
I'll give your latest update a try.
Your .4 worked very well, but I noticed that the turn of a second was not synchronous to my other clocks, being one radio-controlled clock and one Arduino NTP, which corrects for delays and synchronizes the oscillator of an RTC exactly for the turn of a second. I assumed that this was due to that it is not sufficient to get the correct timestamp but also to synchronize the Nixie's clock to this timestamp with ~100ms accuracy.
The only thing that really annoys me: I started to implement NTP on the clock on my own and spent two hours on this yesterday before finding what you did. (however, my solution would never have been as elegant as yours.)
Thanks again
Phil

Edit: Accuracy with v5 is great!
while ( ms() > 25 ) {   // exit when we're within 25 ms of actual time
      yield();
    }
^^seems to do the trick!
Last edit: 1 year 3 months ago by Phil_Mod3.

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #9652 by MikeS
Yep, the long delay doesn't hurt anything ( providing accurate time to the clock once a minute is its ultimate job, and any UI delay is minimal). And, if it's called during the 97.5% of the time it's not within 25 ms, It's going to return at very close to the actual time (it's a tight loop).

I originally spent time trying to round to the nearest second - something like
time_t timeNow = TIME_NOW;
if ( ms() > 500 ) { timeNow++ ;}
// use timeNow
Which always moved the time back by hours. Not sure why, time_t is usually a signed long int (Arduino time.h defines it as typedef unsigned long time_t;, but defers to prior definitions), so it should have changed by 1 second. Finally gave up and did what I did, which is better anyway.

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #9653 by Ian
Hi Mike, much appreciated that you put the time and effort into this. I've had it on the to do list for a long time to integrate NTP and OTA, but there never seem to be enough hours in the day for it.

Would you be OK for me to merge this into the main source and let other people benefit from it as well?

And yes, the ESP-01s are 1MB, so as long as you stay below half of that, it should be fine.

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #9655 by MikeS
Ian, I'll defer for right now, I'm still tweaking. For instance, I just added a username/password hint to the home page when in softAP mode. I'm also adding some bounds checks.

I'd like to let it "soak" for a bit and see if there's any feedback.

I'm not sure how EEPROM is implemented. I know it's kept at the end of the flash, so it survives OTA updates. I expanded it to 1024, and it still seemed to pick up the existing settings. So, I'm guessing that it may be implemented in reverse (i.e. location 0 is at the high end), so when it's expanded it grows downward without disturbing existing offsets? I'm too lazy to go digging. Whatever - a /reset might be good practice when moving to it.

Please Log in or Create an account to join the conversation.

Moderators: AccutronTy_EeberfestIan
Time to create page: 0.216 seconds

Search

Tube Suppliers

Go to top
JSN Boot template designed by JoomlaShine.com