NTP support

Tomer
Posts: 3
Joined: Sun Nov 30, 2014 9:08 pm

NTP support

Postby Tomer » Thu Dec 25, 2014 4:40 pm

Hi All,

I added two new AT commands to get the time from NTP servers (pool.ntp.org). I used AT commands version 20 as starting point.

AT+CIPNTP=<offset from GMT> , to initialize the ntp, and start syncing the time - for example: AT+CIPNTP=2 to intialize it with GMT+2 offset.
AT+CIPNTP? - to get the current time, for example:

AT+CIPNTP?
Time: 22:22:42 12/02/2014 GMT+02

Binaries compiled with SDK 0.9.3: http://bit.ly/esp8266-ntp
Binaries compiled with SDK 0.9.4: http://bit.ly/esp8266-ntp0-9-4

Source code with SDK 0.9.3: https://github.com/TomerCo/ESP8266-AT

Comments/Suggestions are welcome.

scargill
Posts: 70
Joined: Sun Nov 02, 2014 8:09 pm

Re: NTP support

Postby scargill » Thu Dec 25, 2014 7:17 pm

HI

On the assumption that the files load at 0 and x040000 I have loaded the version compiled with SDK 0.9.4 - the AT command set responds - and I put in the information for my router.

I set it up - to my router.. and then issued the command to go get the time..


OK
AT+CWMODE=1

OK
AT+CWJAP="loft-east","xxxxxxxxx"


OK
AT+CIPNTP=0

Sntp initializing TZ: GMT00...
Sntp initializing...
pool.ntp.orgsntp_request: Waiting for server address to be resolved.
AT+CIPNTP=0

Sntp initializing TZ: GMT00...
Sntp initializing...
sntp_dns_found: Failed to resolve server address resolved, trying next server
sntp_retry: Next request will be sent in 3000 ms
pool.ntp.orgsntp_request: Waiting for server address to be resolved.
sntp_dns_found: Failed to resolve server address resolved, trying next server
sntp_retry: Next request will be sent in 6000 ms
pool.ntp.orgsntp_request: Waiting for server address to be resolved.
sntp_dns_found: Failed to resolve server address resolved, trying next server
sntp_retry: Next request will be sent in 12000 ms
pool.ntp.orgsntp_request: Waiting for server address to be resolved.
sntp_dns_found: Failed to resolve server address resolved, trying next server
sntp_retry: Next request will be sent in 24000 ms
pool.ntp.orgsntp_request: Waiting for server address to be resolved.
sntp_dns_found: Failed to resolve server address resolved, trying next server
sntp_retry: Next request will be sent in 24000 ms
pool.ntp.orgsntp_request: Waiting for server address to be resolved.
sntp_dns_found: Failed to resolve server address resolved, trying next server
sntp_retry: Next request will be sent in 24000 ms
pool.ntp.orgsntp_request: Waiting for server address to be resolved.
sntp_dns_found: Failed to resolve server address resolved, trying next server
sntp_retry: Next request will be sent in 24000 ms

I left this one for ages and it wimply would not resolve the address...

So I powered the unit off - and then on - and tried again - and it worked... have you tried the NTP command without having the IP address in intially and setting the router info just maybe 10 seconds or so before trying this command?

When it is finished getting the time could you please have the response end with a line "OK" or "ERROR" to make it easier to know if this has succeeded or not - indeed that's all we really need to know....

Does it try one NTP server (dangerous) or a pool?

Pete.
Last edited by scargill on Thu Dec 25, 2014 7:30 pm, edited 1 time in total.

Tomer
Posts: 3
Joined: Sun Nov 30, 2014 9:08 pm

Re: NTP support

Postby Tomer » Thu Dec 25, 2014 7:28 pm

scargill wrote:And are the binaries at 0000 and 0x40000??


Yes:
eagle.app.v6.flash.bin -> 0x0000
eagle.app.v6.irom0text.bin -> 0x40000

Tomer
Posts: 3
Joined: Sun Nov 30, 2014 9:08 pm

Re: NTP support

Postby Tomer » Thu Dec 25, 2014 7:38 pm

It tries to connect to pool.ntp.org, I am also thinking about giving the option to specify the ntp server/pool to use.

Regarding the messages, I will change to output to OK/ERROR.

anlpereira
Posts: 1
Joined: Fri Apr 29, 2016 8:14 pm

Re: NTP support

Postby anlpereira » Mon Feb 26, 2018 4:14 am

Hi, I'm using the new commands to get the time but the answer is Thu Jan 01 00:00:00 1970

Commands:

AT+CIPSNTPCFG=1,-3

OK
AT+CIPSNTPTIME?
+CIPSNTPTIME:Thu Jan 01 00:00:00 1970

Her Majesty
Posts: 329
Joined: Mon Oct 27, 2014 11:09 am

Re: NTP support

Postby Her Majesty » Wed Feb 28, 2018 1:15 pm

Code: Select all

+CIPSNTPTIME:Thu Jan 01 00:00:00 1970

It is the initial time, did you connect the ESP8266 to the router?
The SNTP time should be got from the internet, it needs to connect to the router first.

Who is online

Users browsing this forum: No registered users and 1 guest