adafruit / Adafruit_FONA

Arduino library for the Adafruit FONA
https://www.adafruit.com/products/1946
211 stars 237 forks source link

Enable Network Time Sync is not implemented for FONA 3G #114

Open OscarVanL opened 4 years ago

OscarVanL commented 4 years ago

Hi,

The Adafruit FONA library has a function enableNetworkTimeSync(), however, this does not work for the FONA 3G as the AT+CLTS command this uses is not used by FONA 3G.

This has been a source of frustration for me over the past days, as the module's documented GPS week rollover issue and inability to enable network time sync has left me without a usable date/time.

Fortunately, I've worked out what AT commands are required to enable this for FONA 3G. I've made a thread on the Adafruit Forums about this here.

I hope to make a pull request in the near future that adds support for this feature on the FONA 3G to Adafruit FONA. If I don't get around to it, feel free to do so for me :)

OscarVanL commented 4 years ago

I've made the PR to implement Network Time Sync on the FONA 3G.

Nathan-ma commented 4 years ago

Great Oscar! can I ask you how can I use this?

What I'm expecting to receive is a NTP Number from the board, I've noticed your implementation enables the NTPSync, How can I receive the output from it? and how can I set the server?

Should I use it like in this example?

image

Thank you and Sorry in advance for the bad english.

OscarVanL commented 4 years ago

Hi Nathan, this is a little different.

There are three ways of getting the time on the FONA:

  1. From the GPS (Doesn't work anymore due to time rollover bug).
  2. From an NTP server (This is what you were referring to)
  3. From your Cellular Provider

My implementation does (3). All you will need to do is run enableNetworkTimeSync(true) once, then this setting is saved permanently. FONA automatically gets the time from the network provider and sets its RTC from it.

Then to read the RTC use readRTC. Unfortunately, Adafruit did not finish the readRTC function, but a pull request exists that adds this functionality. https://github.com/adafruit/Adafruit_FONA/pull/76

The great part about this is no NTP server needs to be configured. The downside is that not all network providers support this (though most will).