0

Is there in Raspberry Pi some setting for automatic timezone synchronization? Maybe some application that can set local timezone on Raspberry Pi?

Let's say, I send device to client, after he switches on my device, I need it will synchronize to local TIMEZONE in automatic way. Is it possible?

MY SOLUTION: https://www.raspberrypi.org/forums/viewtopic.php?t=188770

2
  • How do you think the Pi will magically know where it is?
    – Milliways
    Nov 22 '20 at 10:51
  • Maybe by IP. Enough magically?
    – Rougher
    Nov 22 '20 at 10:54
2

From Terminal call setuo by command: sudo raspi-config

Select Internationalization Option to set Time Zone

Time and date are automatically set from network if you connected to the internet.

If you are not connected to the internet you can set it manually using command: sudo date -s $date

3
  • I need an AUTOMATIC way. I send device to client, after he switches on my device, I need it will synchronize to local TIMEZONE in automatic way. Is it possible?
    – Rougher
    Nov 22 '20 at 9:27
  • Set Time Zone manually but sync time with server enabled/disabled by commands: sudo timedatectl set-ntp false sudo timedatectl set-ntp true #It is enabled by default
    – user16181
    Nov 22 '20 at 9:31
  • I can't set it manually. I don't know what is timezone of my client. I need it will be set automatically
    – Rougher
    Nov 22 '20 at 9:34
2

The timezone is the area in which the device is located. The problem is that something must know what timezone your client is in. If you don't know it, how should the client know it? It could connect to a server nearby which is in the same timezone that tells it something like: "Hey, I'm in timezone Europe/Berlin. You seem to be in the same timezone."

Do you see the problem? How will the client know that it connects to a server that is in the same timezone? Of course there may be solutions to solve this problem, but it seems not to be an easy task.

  • Maybe a service from your internet provider? He knows where you are connected.
  • A GPS solution?
  • Google also knows where you are located
  • IP addresses?
3
  • Thank you for your answer. I used this solution: raspberrypi.org/forums/viewtopic.php?t=188770
    – Rougher
    Nov 22 '20 at 12:45
  • @Rougher What is it? geoip? Please create a short answer about your solution and mark it as the accepted one with a click on the tick on its left side. That prevents your Question from being shown as an unsolved Post to the community and saves them/us a lot of work.
    – Ingo
    Nov 22 '20 at 17:59
  • I posted my solution
    – Rougher
    Nov 24 '20 at 10:16
1

Geolocation by IP address will most likely work - for example. The sleazy technical giants do this routinely, and as someone once said, "Internet privacy is a myth." Part of the reason they know your location with such uncanny accuracy goes back to "Google Maps"... the same people filming your street are also recording all the WiFi data.

One way to get your own location information is to go the the ipinfo.io website. And as you've now noted, it's a simple matter to find a source for this information, use wget or curl to download a URL, parse the output, and then update /etc/timezone and /etc/localtime following the guide you found - or one of many others available online.


Other geolocation sources:

  1. https://www.ipfingerprints.com/geolocation.php

  2. https://www.maxmind.com/en/home

  3. https://www.ipinfodb.com/api

  4. DIY listing of free IP address geolocation services

  5. Is geolocation by IP address an invasion of privacy?

4
  • 1
    "The sleazy technical giants do this routinely" and routinely get it wrong, telling me I am in a city 1000km away, in a different state and timezone. I just tried ipinfo.io which gives another city 1400km away.
    – Milliways
    Nov 23 '20 at 3:47
  • @Milliways: Don't know where you are (Oz?), but if that's the case, I would count you among the lucky ones. I've lived in 3 countries over the past 5 years, traveled quite a bit, and they nailed my location consistently. Maybe I'll move there... what's your address? :) LOL
    – Seamus
    Nov 23 '20 at 20:35
  • I live in Sydney. I just checked again; I have a different IP Address, but apparently I have moved over 2000km overnight (between 2 states with closed borders due to COVID-19).Unfortunately we are closed to visitors (footballers excluded) - even citizens can't return home.
    – Milliways
    Nov 24 '20 at 9:47
  • @Milliways: Yes - I see a bit of that as I follow Rita Panahi - I'm astonished that they even allow IP addresses any mobility in Victoria :)
    – Seamus
    Nov 24 '20 at 19:38
1

I used solution from here with my small changes:

zone=$(wget -O - -q http://geoip.ubuntu.com/lookup | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/ p')

if [ "$zone" != "" ]; then
    echo $zone | sudo tee /etc/timezone > /dev/null
    dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>&1
    timedatectl set-timezone $zone
    echo "[INFO] Timezone was set to $zone" >> "$logFile"   
else
    echo "[ERROR] Timezone is empty" >> "$logFile"
fi

You can set this code into script that run on RPI boot through sudo crontab -e:

@reboot sh myscript.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.