esp8266 / Basic

Basic Interpreter for the ESP8266
http://esp8266basic.com
259 stars 216 forks source link

Feature request: NTP Client #33

Open riban-bw opened 7 years ago

riban-bw commented 7 years ago

I can not see a way to implement a NTP client. NTP client is not a documented feature and the UDP implementation only supports string handling. The NTP message consists of a 384 bit or 48 byte data structure containing 17 fields which require raw data, not string. There is a nice (simple) guide to implementing a NTP client here: https://lettier.github.io/posts/2016-04-26-lets-make-a-ntp-client-in-c.html.

riban-bw commented 7 years ago

Or an implementation on the Arduino playground: http://playground.arduino.cc/Code/NTPclient which is fairly simple. Neither of these calculate the loop delay (the Arduino version assumes 50ms) but for most purposes, getting one second accuracy is fine. Even the rounding done in the Arduino code may be excessively accurate for most purposes.

riban-bw commented 7 years ago

I have now found that SNTP is already implemented and an enhancement planned http://www.esp8266.com/viewtopic.php?f=43&t=11510&p=54024&hilit=ntp#p54024. It would be advantageous for this to be documented. I was perplexed when the device magically knew the time. It may also be advantageous to be able to set the time manually in case Internet is not available. Also, able to get the unix timestamp rather than just human readable format, so that program can easily compare values, etc.