OBJECTIVE:
The objective of this lab is to configure the Pi to update its time using a rotating pool of Internet NTP servers.
REQUIRED MATERIALS:
- Raspberry Pi Micro-Controller
- 8GB SDCard with the Operating System NOOBS (Raspian – Debian Linux derivative) pre-installed.
- Power Supply, AC-DC Converter, External Plug in, Micro USB connector, 5W, 5V, 1A output.
- USB Keyboard.
- USB Mouse.
- HDMI Monitor.
- HDMI Cable.
- HDMI to DVI Adpater (if your monitor only has a DVI and not a HDMI connector).
- Two straight through Ethernet cables
- Home router\switch connected to a cable modem or DSL modem
- A personal computer
PRE-REQUISITES:
- An operating system must be installed onto the Raspberry Pi (see Pi Lab – Initial Setup)
- The Pi must have Internet connectivity.
- Ethernet networking.
- Connector types such as HDMI, DVI, USB, RJ-45 (Ethernet), etc…
- The Linux Operating System
- The Network Time Protocol (NTP) Protocol
REFERENCES:
Raspberry Pi Help
- http://www.raspberrypi.org/phpBB3
- ntpd
- ntp.conf
- ntpq
- ntpdc
- ntpdate
- ntp_mon
- ntp_acc
- ntp_clock
- ntp_misc
- http://www.ntp.org/
- http://www.eecis.udel.edu/~mills/ntp.html
- http://www.eecis.udel.edu/~mills/ntp/html/
- http://support.ntp.org/bin/view/Main/WebHome
PRELIMINARY READING:
Most computers have a clock somewhere in their circuitry. The clock circuitry usually has a battery connected to it so that after you set the time and date on your computer, and then turn off power to the computer, the clock circuitry still functions and keeps time so that when you power on the computer again, the correct time and date is readily available to initialize the operating system. When the computer is configured to synchronize it’s time to a NTP server, the operating system corrects the clock circuitry from time to time. The ntpd has this quirk in which if the computer’s clock is different than the NTP server’s clock by more than 1000 seconds (between 16 and 17 hours), ntpd assumes that something is very wrong and that the only dependable thing to do is have a human being step in and set the clock manually. It sends a warning message to the system log and then stops the NTP daemon. In other words, NTP won’t work.
The Raspberry Pi has a system clock, but it does not have a battery to keep it functioning when the Pi is powered off. This means that if you do not have an Internet connection, every time you turn the power off and then back on again, you will have to manually set the system clock. On my Pi, the default date was June 19, 2013 UTC time. Right now it is October, which means the clock is at least 3 months off. There are several workarounds to this dilemma:
1. Physically connect a real-time clock (RTC) module to the Pi circuit board. There are several different RTC clock modules sold by numerous vendors.
2. Raspbian (Debian-Wheezy Linux optimized for the Raspberry Pi) uses the “fake-hwclock” daemon to record a timestamp before you power down. When you boot the Pi back up, the system clock is set using the time recorded before you shutdown. That means that if you manually set the correct time on the pi, and then power it off for 3 hours, when you power it back on, the clock will be 3 hours off instead of 3 months off.
3. Use the “ntpdate” utility. This forces a system clock to update using the time received by querying NTP servers on the Internet. After you execute the “ntpdate” command and update the system clock, then you can run “ntpd”. The drawback is that you must have an Internet connection, and your firewall needs to permit packets using the NTP protocol to pass through it. It is not included the Raspbian installation.
4. The “ntpdate” has been deprecated and its functions are included in the newest version of the “ntpd” daemon. With the Raspbian OS installation, ntpd is configured to run at startup and automatically checks Internet NTP servers for time and updates the system clock. The clock update feature works when the Pi is a NTP client and is getting its time from stratum 1, 2, 3, etc., servers. However, if you are trying to make the Pi into a stratum 1 server by getting your time from a stratum 0 server (an external clock source such as GPS), then the clock offset becomes an issue. For example, if the GPS time differs from the system clock time by more than 1000 seconds, NTP will not work. You will have to manually set the system clock time before you can get the GPS to work with NTP. Also, be advised that NTP will not set your time zone. By default, the time zone is UTC. If you want your clock to reflect the time as it exists in your time zone, you need to change the time zone by executing the command “sudo raspi-config” and selecting option 4 - “Internationalization Options”.
Screen Shot of the Rasbian Software Configuraion Tool |
PROCEDURE:
Experiment 1
1. When you installed the Raspbian OS in the previous lab, the default time and date should have been updated over the Internet, assuming you were properly connected to the Internet.
2. Note the current time and date of the Pi by left clicking the time displayed in the bottom right corner of screen if you have the GUI desktop displayed. If you are using the command line interface, enter the command “date”.
3. Disconnect the Pi from the network.
4. Gracefully shutdown the Pi By clicking the ON\OFF button on the bottom right of the screen and selecting “Shutdown” or by executing the command “sudo shutdown –h now” at the command prompt. After the screen has gone blank, physically remove the power connector from the Pi.
5. Wait an hour or two.
6. Remove the Ethernet cable from the Pi thereby disconnecting it from any network, and then apply power to the Pi.
7. Check the time and compare it to the time noted before you removed power. They should be the same.
8. Reconnect the Pi to the Internet and wait a few minutes.
9. Look at the time and date again. The clock should be updated.
Experiment 2
1. Note the current time and date of the Pi.
2. Remove the Ethernet cable from the Pi.
3. Shutdown and turn off power to the Pi. Wait a few hours.
4. Turn on the Pi without being connected to the Internet.
5. Execute the command “sudo service ntp stop”.
6. Reconnect the Ethernet cable to the pi.
7. Execute the “date” command. The time should be the same as it was before removing power.
8. Execute the command “sudo service ntp start” and wait a minute or two.
9. Execute the “date” command again. The time should have been updated.
No comments:
Post a Comment