on my embedded device with YOCTO and none ethernet connection I would set a specific date and keep it udpdate after the device power-off.
I tryed with :
date --set '2022-05-25 11:17:00'
hwclock --utc --systohc
poweroff
but at power on the dat&time are switched back to old value
The same result using :
timedatectl
where ntp is disable, RTC local in TZ is enable and system clock synchromized is enable.
Where is my mistake?
Related
I've searched around, but I cannot find an answer.
Can I use my Raspberry Pi as an NTP server (independently).
I want to synchronize 4 devices on a LAN for logging. They will be on a LAN with no WAN access... one is a Cisco Switch, one is the Pi and the other two are conversion boxes I want to log things on (they will be NTP client).
I just need them all to sysnc to 1 clock source (the Pi) is there a way to do this? All the answers I find are either to setup the Pi with a GPS module (which I can't do here) or sync it to external NTP servers for cascading the clock down (which I can't do here)... can I use NTP just to send out the Pi's system time ?
You could but best with a time source.
You would need to edit the code for a NTP server, as there isn't much cause to do this.
Best idea is to use a GPS hat on the RPi
http://www.reeve.com/Documents/Articles%20Papers/Reeve_GpsNtp-Pi.pdf
DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...
On your Raspberry Pi, run the following commands:
sudo apt update
sudo apt install ntp
sudo ufw allow ntp # if your firewall is enabled
sudo ufw allow 123
sudo sed --in-place --expression "\$aserver 127.127.1.0" /etc/ntp.conf
sudo systemctl start ntpd
On your Cisco switch, run the following commands:
NOTE - If you are using Cisco IOS, do not forget to force the NTP synchronization using clock read-calendar.
configure terminal
ntp server <the IPv4 address of your Raspberry Pi>
end
clock read-calendar
PS - If you want to shut everything down...
On your Raspberry Pi, run the following commands:
sudo ufw delete allow ntp
sudo ufw delete allow 123
sudo systemctl stop ntpd
sudo sed -i "/server 127.127.1.0/d" /etc/ntp.conf
On your Cisco switch, run the following commands:
configure terminal
no ntp server <the IPv4 address of your Raspberry Pi>
end
If right now VPS situated in US shows time "Mon Sep 25 20:23:56 UTC 2017",
my local machine in India show time "Mon Sep 25 20:25:36 UTC+5:30 2017"(appx 2 minutes early on VPS).
My problem is When I save date to mongodb remote it save as "createdAt" : ISODate("2017-09-25T20:23:56.461Z") and when I see website on my local machine the time shows Tue Sep 26 01:33 UTC 2017. I seriously don't understand what is wrong??
why UTC+5:30 on my local machine? and how come the VPS server time is same as Indian Standard time?
Check the system time with date command.
All the servers should sync time with NTP server to avoid this kind of issues.
yum install ntp
chkconfig ntpd on
ntpdate pool.ntp.org // You can use ur own NTP server
service ntpd start
I'm trying to sync the timezone of a docker container with my host. My host is using ISM and the docker container (using a tomcat image) uses UTC by default. I've read that we should mount a volume to share the timezone of the host:
$ docker run -t -i -p 8080:8080 -p 8090:8090 -v /etc/localtime:/etc/localtime:ro tomcat:7.0.69-jre8 /bin/bash
After that I can check that the date retrieved is the same as the host:
$ date
Fri Jul 22 13:53:45 IST 2016
When I deploy my application and I try to update a date, I can see that the date 22/07/2016 is using my browser timezone, which is the same as the host where the docker container is running. But debbuging the server side of the app I can see that the date is converted into UTC timezone. This means that the docker container is not really using the host volume I did mount.
Am I missing anything?
Another way I tried and did work was updating the timezone in the docker container:
$ dpkg-reconfigure tzdata // Selecting the corresponding options afterwards
This way I can see the same timezone in both: client side and server side of my app.
After debugging and reading about date and time, I think it makes sense that the backend stores the date and time in UTC/GMT, that way is independent of the client's timezone when it's saved in the DB. So it wouldn't be a good practise to change the tomcat server timezone to match the host (it shouldn't really matter).
The issue I had was the front end was using date and time (UTC/GMT +1) and the time was set to 00:00h and when it reaches the back end, the date and time is converted to UTC/GMT which makes it 23:00 of the previous day. The persistence layer was just storing the date which it's wrong as we lose data (the time) and when we try to retrieve that record from the DB we will get the previous date without the time so it's not the result we would expect.
I hope my explanation makes sense
I have connect my Raspberry Pi to LAN but there is no internet available. Is there any method to update raspberry pi date time by using a PC (windows 7) in LAN? I want to get computer date and time to my Raspberry Pi when it is booting.
Remember that Raspberry Pi does not have real time clock. So even you are connected to internet have to set the time every time you power on or restart.
This is how it works:
Type sudo raspi-config in the Raspberry Pi command line
Internationalization options
Change Time Zone
Select geographical area
Select city or region
Reboot your pi
Next thing you can set time using this command
sudo date -s "Mon Aug 12 20:14:11 UTC 2014"
More about data and time
man date
When Pi is connected to computer should have to manually set data and time
Thanks for the replies.
What I did was,
1. I install meinberg ntp software application on windows 7 pc. (softros ntp server is also possible.) 2. change raspberry pi ntp.conf file (for auto update date and time)
server xxx.xxx.xxx.xxx iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
3. If you want to make sure that date and time update at startup run this python script in rpi,
import os
try:
client = ntplib.NTPClient()
response = client.request('xxx.xxx.xxx.xxx', version=4)
print "===================================="
print "Offset : "+str(response.offset)
print "Version : "+str(response.version)
print "Date Time : "+str(ctime(response.tx_time))
print "Leap : "+str(ntplib.leap_to_text(response.leap))
print "Root Delay : "+str(response.root_delay)
print "Ref Id : "+str(ntplib.ref_id_to_text(response.ref_id))
os.system("sudo date -s '"+str(ctime(response.tx_time))+"'")
print "===================================="
except:
os.system("sudo date")
print "NTP Server Down Date Time NOT Set At The Startup"
pass
I found more info in raspberry pi forum.
You will need to configure your Win7 PC as a Time Server, and then configure the RasPi to connect to it for NTP services.
Configure Win7 as authoritative time server.
Configure RasPi time server lookup.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I've tried doing the NTP, but this pi travels from various places at various times a month and doesn't always have the proper access for NTP. Is there a way I can have it sync with Colorado's atomic clock during its booting sequence?
I currently running Raspian OS on the 512 version of Model B
There are three options by which you can sync your raspberry pi time.
Solution 1: you can use RTC or any hardware clock and you can sync your RPi time with the clock.
Solution 2: Use a GPS module and sync the time with that.This will not work properly until your get you GPS locked.
Solution 3: You can use NTP server to sync your Raspberry Pi time. At this case you need your RPi connected to Internet.
First install ntp to your Pi.
$ sudo apt-get install ntpdate
Then reconfigure your tzdata with your location and local time by typing
$ sudo dpkg-reconfigure tzdata
Now you need to run this following commands to sync your RPi time with NTP server.
$ sudo service ntp stop
$ sudo ntpdate -s time.nist.gov
$ sudo service ntp start`
If you want to sync your time with web on start/reboot, you have to add it in your cronjob.
Assuming I have understand the question correctly – if syncing manually to the internet time whenever online and then let the local RTC do its job when offline is good enough, then you should use an external RTC module, like this one (or this one) and follow the instructions on how to configure the Linux to get the time locally instead from internet. On the adafruit's 'Set RTC Time' page it says "Once the time is correct [i.e. from the internet] (...), run sudo hwclock -w to write the system time to the RTC", so I assume this command can be used later at anytime to sync again the local clock with the defined NTP clock (but cannot check this for myself, as I don't have a hardware RTC yet).
As for the timezone, if using Raspbian this can be set via sudo raspi-config > Internationalisation Options (when in command line mode) or via Menu > Preferences > Raspberry Pi Configuration > Localisation (when in desktop mode).
I was stuck on this for a while. Was able to sync to the NTP server but was always 9 hours ahead. Fixed it by forcing a timezone change to Pacific.
$ sudo dpkg-reconfigure tzdata