bxparks / AceTime

Date and time classes for Arduino supporting the IANA TZ Database time zones to convert epoch seconds to date and time components in different time zones.
MIT License
77 stars 15 forks source link

Question: Does Acetime support standalone determination of timezone using GPS module? #48

Closed Bwanna closed 3 years ago

Bwanna commented 3 years ago

The question assumes no internet access by the design, with everything needed to determine the Timezone based on the GPS provided coordinates. The design would need to incorporate a database for position comparison. Not sure how AceTime works and if it provides this database, how it does the position comparison to the database, etc.

Thanks,

bxparks commented 3 years ago

Hi, When most people ask about GPS module, they are thinking about using the GPS module as a source of accurate atomic clock. This would be the equivalent to using NTP (network time protocol) or a battery powered RTC (real-time clock) module, which AceTime supports. But currently, AceTime does not support GPS as a clock source. I think it would relatively easy to add --- probably just an adapter class in src/ace_time/hw pointing to the relevant GPS library --- but I don't own any GPS hardware right now, and I haven't had the time to look into this.

What you are asking for is slightly different and interesting. You want to extract the (lat, lon) location from the GPS, then consult a database to convert the coordinates to a timezone, then use AceTime to calculate the local time. Unfortunately, the AceTime library does not provide this database. However, if you were able to find such a database or build one yourself, to extract the local timezone, then AceTime will do everything else for you.

It seems to me that such a database must already exist somewhere, but I haven't done any research on this, and I am not sure if such a library has been created for the Arduino platform. If you decide to build something like that yourself, I may even be interested in helping out, because it sounds like an interesting problem, and it would compliment the AceTime library... if I ever get around adding support for a GPS module.

Bwanna commented 3 years ago

I agree the adding of GPS as a clock source is fairly easy. The big challenge is the geographic comparison of the GPS coords and the Timezone boundaries. Appreciate the feedback!

Saw this link and got the impression the geographic comparison was possible. Thoughts? https://www.reddit.com/r/arduino/comments/cq1wh6/acetime_library_date_time_clock_and_tz_database/

bxparks commented 3 years ago

Another random thought:

I would guess that GPS modules in the hobbyist market are far inferior to the GPS modules inside a modern smartphone. The smartphone combines information from cell tower triangulation, WiFi SSIDs, and GPS signals, to get the most accurate geo-coordinates. And we know that it converts that into timezone, because the phone is usually set to "Automatically set timezone from network". For your application, I wonder if it's possible to obtain the local timezone information over bluetooth from your smartphone? If that's possible, then you can feed the timezone into AceTime, and it will take over from there.

Caveat: I don't have any experience with the bluetooth stack on Arduinos (e.g. ESP32), so I don't know how well the bluetooth stack works on Arduinos.

bxparks commented 3 years ago

Not sure what you mean by "geographic comparison" in the reddit post that I wrote. I didn't mention GPS coordinates... Just timezones from the TZ database.

Bwanna commented 3 years ago

I'm looking to make the design fully standalone for the calculation of local time - no wifi/bt connection to external devices. Make it purely a geographic comparison of GPS coords to a timezone boundary database. Am ok if the resolution was only accurate to a few NMs... maybe that would reduce the database size by not requiring extensive boundary data. I do want something more than 1hr/15degrees though!

Bwanna commented 3 years ago

Not sure what you mean by "geographic comparison" in the reddit post that I wrote. I didn't mention GPS coordinates... Just timezones from the TZ database.

A bit of assumption on my part, but does the TZ database provide the geographic boundaries for each TimeZone? If so, then in theory the GPS coords could be compared to these boundaries to determine which timezone is for the location.

Bwanna commented 3 years ago

Just found this effort: https://github.com/evansiroky/timezone-boundary-builder Will continue researching.

bxparks commented 3 years ago

No the TZ database is a listing of rules. The physical boundaries are not defined by them. With a big enough database, and enough resources to keep it up to date, I'm sure it's technically possible. But it seems like a lot of work. This map (https://en.wikipedia.org/wiki/Time_zone#/media/File:World_Time_Zones_Map.png) shows the high level timezone boundaries. But we also know that small cities (e.g. in Indiana) and regions (e.g. Native American reservations, war-conflict regions) inside those big boundaries can follow different sets of rules.

Bwanna commented 3 years ago

Ah, so unlikely a single design for world use would be feasible. However, wonder if a design for just the U.S. would be reasonably possible? ...not requiring too large an onboard database?

bxparks commented 3 years ago

It kinda depends on how much accuracy you need, doesn't it. If your timezone regions are defined by only a handful large, rectangular lat/lon blocks, that's a small database. But it would often be wrong when crossing state boundaries. If you want more accuracy, you need large databases and more complicated code. Sounds like an interesting project, have fun!

doanerock commented 3 years ago

I personally have no interest in my clock trying to determine what time zone it is in. I do have a BIG interest in using AceTime to use GPS to set the time with no internet access. Pease keep in mind that there is a packet that contains a GPS-to-GNSS time offset that must be accounted for.
@bxparks Would you like me to send you a GPS break out board? They are pretty neat and often work inside.

bxparks commented 3 years ago

@doanerock: Hmm. So let me just clarify that if you are working on a commercial project that needs this GPS feature, you should contact me via email to chat about it, because I'm not going to do this work for free. If this is for personal use, I'm sorry that I won't have time to do this work. It's an interesting feature that I would love to support, but realistically I have too many other projects in my queue, and this feature is not something I need in the next 6-12 months. You are of course encouraged to write this code yourself, and offer it as your own Arduino library that extends AceTime. (I would be hesitant to accept that code into AceTime, because that would impose future maintenance burden on me, especially for code that I cannot test myself.) So, thanks for the offer, but probably not in the next 6-12 months. I'm not completely ruling it out, because I hope to look into this feature at some point.

doanerock commented 3 years ago

@bxparks Sorry I did not mean to offend. I saw that previously in the thread you mentioned you did not have any GPS hardware so I thought since am not the best coder but I do have a GPS breakout board handy so I should offer it since that is what I can do to help. I did not mean to put unnecessary pressure on you. I just wanted to put in a vote for the feature and lend assistance.

Bwanna commented 3 years ago

Np. I think you'll misunderstand my query. I simply didn't know how your coding worked and had a question. Not seeking to change your work our ask you to do more. I just didn't know how to use your code. Honestly, I still am not sure what your code does, but it seems that it doesn't include what I'm seeking. Thanks for the information.

On Mon, Feb 15, 2021, 11:02 AM doanerock notifications@github.com wrote:

@bxparks https://github.com/bxparks Sorry I did not mean to offend. I saw that previously in the thread you mentioned you did not have any GPS hardware so I thought since am not the best coder but I do have a GPS breakout board handy so I should offer it since that is what I can do to help. I did not mean to put unnecessary pressure on you. I just wanted to put in a vote for the feature and lend assistance.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bxparks/AceTime/issues/48#issuecomment-779315088, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGA5YHYJJEK2UBLXPKSLEOLS7FAP7ANCNFSM4XTMOIIA .

bxparks commented 3 years ago

@doanerock : No worries, no offense taken. Just wanted to be straightforward about how I prioritize my time and effort, and what my schedule looks like for the next 6-12 months.

@Bwanna : It sounds like you are not familiar with other timezone libraries (e.g. Python pytz, dateutils; Java Time, Joda Time, Noda Time, etc). If you are familiar with those, then the AceTime README.md and the sample code should make it pretty clear about what the library does. If you are not familiar with timezone at all, then yes, it can all be very confusing. I have a whole bunch of links and references in my README.md and USER_GUIDE.md files. Hopefully, some of those will help you. Good luck!

bxparks commented 3 years ago

I'm going to close this ticket, since I don't think there is anything actionable for me to do. Please reopen if you have further questions.