Warning

Warning: Keep out of reach of small children and smart-alec teenagers. Keep printed material away from open flames or excessive heat. Studying these documents may cause drowsiness. Do not read while driving heavy equipment or machinery. If nervousness, sleeplessness or irritability occur, discontinue use and seek professional help. Excessive and prolonged use may cause career burnout and has been known to cause cancer in laboratory rats. Isolated cases of schizophrenia exhibiting delusions of grandeur have been reported. Do not use if you are being treated for high blood pressure or have problems urinating due to excessive consumption of caffinated drinks.

Friday, November 1, 2013

Bad Documentation – The Bane of My Existence

The problem with most open source and many commercial software packages is that the documentation sucks rocks. The two biggest reasons their creators often site for their oversight are:

1.    The project is a hobby and that they don’t have time to write decent documentation.
2.    Anybody that has any knowledge of computer programming should be able to figure it out. If you don’t have a Ph.D. in Computer Science, you shouldn’t be in the IT industry.

My response to that is this:

1.    If they had planned and organized their project from the very beginning like they teach you to do in college, the documentation would have been written before they ever wrote a single line of code. Should it come as a surprise then that their project is so buggy from the get-go? Poor planning and poor documentation is the sure sign of an amateur. Period.

2.    What is the point of creating software for someone to use if nobody can figure out how to use it? I have better things to do with my time than reverse engineering their project even if I was a code-head. It would be easier and more cost effective to purchase a retail version that is well planned and well documented. Heck, it might even be more cost effective to write it myself or pay someone else to write it!

3.    Everyone in the IT industry does not have Ph.D.s in Computer Science. In all the places I’ve worked in my 30 year career, less than one-third of the people I worked with had any extensive formal computer programming training and experience.

4.    If your program, like syslog-ng for example, is “written by programmers for programmers” not everyone that knows how to program know how to program in C# or whatever language your program is supposed to emulate.

If a user can’t figure out how to use a piece of software without having to reverse engineer it first, what is the point of writing it in the first place?

Take for example this article I recently read entitled "Receiving Messages from a Remote System" for the rsyslog logging software installed by default on my OpenSuSE Linux PC.

1.    It says "Note that the server port address specified in $InputTCPServerRun must match the port address that the clients send messages to." In the sample configuration file that immediately follows this statement, there isn’t one single line that even contains "$InputTCPServerRun". So how am I supposed to use this statement? When? Where?

2.    The author writes that to receive logging messages from remote devices, certain plugins need to be loaded at the start of the of the configuration file and shows examples in the sample configuration file. After the sample configuration, the author states that you need to activate “listeners” and that loading the “plugins” is not sufficient.
  • Are "plugins" the same as the "modules" that are loaded in the configuration file? He doesn’t say.
  • Nowhere in this article, or any other article, does he specify exactly what a "listener" is, nor does he describe how to "activate" them. Is a listener the same as a filter? A ruleset? Who knows?
3.    The author mentions in a completely different article that if you want to receive messages by both the TCP and UDP protocols, you need to configure them with different port numbers. Yet in the example configuration contained within this article, he configures both TCP and UDP to use the same port 514.

4.    In another document "Storing Messages from a Remote System into a Specific File", the author writes "It is important that the rules processing the remote messages come before any rules to process local messages." He doesn’t mention that in this document anywhere.

5.    I enter the "Config Statements" shown in the document exactly as written and they don’t work.
  • Error messages in the log files say that "no listeners are defined – no input will be gathered" among others. Why would anyone put a incomplete, non-working configuration example in their documentation? What is the point in doing that?
  • The configuration is for TCP, but most logging programs send their log messages via UDP (including Cisco, which is what I’m trying to receive messages from). What good is a configuration that receives only TCP to me?
6.    In the configuration examples of some articles, he uses these commands:
  • module (load="imtcp")
  • input (type="imtcp" port="514")
  • In other examples he uses "$Modload imtcp" but doesn’t explain why there is a difference.

The documentation on the rsyslog website is extensive, yet there is nothing there, that I can find, that is actually usable. It’s like trying to hunt down little bits and pieces here and there in the various different articles and then try and fit them all together like a jig-saw puzzle.  Yast’s description of rsyslog says that it is easy for novices to use.

I’d be willing to bet real money that they never actually asked a novice user to try and figure out how to use it before making that statement.

Why people say on the Internet that this logging program is better than the old syslog program is beyond my comprehension. I am going to unload rsyslog and load the old, tried and true syslog.

As far as  syslog-ng is concerned – though I do have some programming training and experience, I don’t have a Ph.D. in Computer Science. My degree is in Electronics Engineering Technology. I don’t have the time or the motivation to learn their programming language. I need something that’s KISS. I don’t need something that will clean the kitchen sink. Whatever happened to

Keep It Simple Stupid?

What about the Windows logging program called Kiwi? It doesn’t support IPv6. REALLY? With the remaining IPv4 address allotment being exhausted in a matter of months, Kiwi won’t support the newer IPv6 addresses? Who’s the genius that made that command decision?

The university I went to required engineering majors to take a class in technical writing in addition to the usual English Composition classes. Don’t all universities require engineering majors to take a course in technical writing for graduation? Sadly, apparently not.




Friday, October 18, 2013

Pi Lab 4: GPS on the Pi







OBJECTIVE:
The objective of this lab is to connect a GPS receiver to the Pi and use it to determine location and time.

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.
  • USB Hub
  • HDMI Monitor.
  • HDMI Cable.
  • HDMI to DVI Adpater (if your monitor only has a DVI and not a HDMI connector).
  • One Ethernet cable
  • Adafruit Ultimate 66 GPS Breakout with 9 pin Header and Coin Cell Battery Holder
  • SMA to uFL/u.FL/IPX/IPEX RF Adapter Cable
  • Adafruit External GPS Antenna, 3-5Volt,  28dB gain, 5 Meter cable with SMA Connector
  • USB to TTL Serial Cable - Debug / Console Cable
  • CR1220 Coin Cell Battery
  • Soldering iron with solder
  • Electronics cleaning solvent (available at electronics and automotive stores)
PRE-REQUISITES:
  • An operating system must be installed onto the Raspberry Pi (see Pi Lab – Initial Setup)
  • The Pi must have Internet connectivity.
A basic understanding of:
  • Ethernet networking.
  • Connector types such as HDMI, DVI, USB, RJ-45 (Ethernet), etc…
  • The Linux Operating System
REFERENCES:
Raspberry Pi Help
  • http://www.raspberrypi.org/phpBB3
  • http://learn.adafruit.com/adafruit-ultimate-gps-on-the-raspberry-pi
  • http://blog.retep.org/2012/06/18/getting-gps-to-work-on-a-raspberry-pi/
GPS
  • http://gpsd.berlios.de/gpsd.html
  • http://catb.org/gpsd/
  • http://gpsd.berlios.de/client-howto.html
PROCEDURE:
Parts Assembly   
1.    Place the battery holder onto the back side of the circuit board using the outline that is printed on the circuit board as a guide. Solder the ears of the battery holder onto the solder pads of the circuit board.
2.    The header that came with my GPS Breakout module had more than 9 pins on it. If yours does too, then break off the extra pins so that you header has 9 pins.
3.    Insert the short pins into the holes of the GPS Breakout circuit board and solder them into the circuit board. The longer pins should be pointing away from the circuit board. Whether they are on the top of the circuit board or the bottom, it doesn’t really matter. I soldered mine with the pins pointing down so that I can stick them into a breadboard with the circuitry facing up if I want to at some future date.
4.    Clean the flux residue off of the circuit board using a brush and circuit board cleaner.
5.    Insert the battery into the clip on the backside of the circuit board with the positive terminal facing away from the board.
6.    Screw the smaller connector of the white antenna adapter cable to the connector on the circuit board as shown below.
7.    Screw the GPS SMA connector on the black antenna cable onto the larger (SMA) connector on the white adapter cable.
8.    Take the four wires of the USB to TTL adapter and connect them to the header pins on the GPS circuit board as follows:
  • The white wire goes to the header pin labeled “TX”.
  • The black wire goes to “GND”.
  • The red wire goes to “VIN”.
  • The green wire goes to “RX”.
9.    Because there are only two USB ports on the Pi, and three USB connectors that you need to plug into the Pi, you will need to connect the USB hub to the Pi and then connect the keyboard, mouse and GPS Breakout board to the hub.
10.    Power on the switch and connect the Pi to the Ethernet switch with the straight through Ethernet cable.
11.    Place the GPS antenna (the big black square block) on a window sill.
12.    Connect the monitor to the Pi and turn it on.
13.    Apply power to the Pi.


Installing the “gpsd” Program On the Pi
1.    Assuming you have booted up the Pi while being connected to the Internet, your Pi should have the current UTC time. Execute the “date” command to verify (remember that your local time might be several hours different than UTC time) or if you booted to the GUI, the time is displayed in the bottom right corner of the screen. Move your mouse over the time to view the date.

pi@raspberrypi ~ $ date
Wed Oct 16 16:38:38 CDT 2013


2.    Verify that the GPS module connected to the USB port is being recognized. The Adafruit GPS module is highlighted in yellow. Enter the following commands:

pi@raspberrypi ~ $ ls /dev/ttyUSB*
/dev/ttyUSB0
pi@raspberrypi ~ $ sudo lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 058f:9254 Alcor Micro Corp. Hub
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 006: ID 04d9:1702 Holtek Semiconductor, Inc.
Bus 001 Device 007: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse


3. Verify that the GPS module is sending data to the Pi. Enter the following command and watch the streaming data scroll down your screen. Press “ctrl-c” to exit the data flow and return to the command prompt.

pi@raspberrypi ~ $ sudo cat /dev/ttyUSB0
$GPGGA,221016.000,3531.7468,N,09735.5017,W,2,8,1.02,382.5,M,-25.2,M,0000,0000*66
$GPGSA,A,3,18,02,05,25,29,21,26,15,,,,,1.83,1.02,1.52*0C
$GPRMC,221016.000,A,3531.7468,N,09735.5017,W,0.02,332.89,161013,,,D*78
$GPVTG,332.89,T,,M,0.02,N,0.05,K,D*3C
$GPGGA,221016.000,3531.7468,N,09735.5017,W,2,8,1.02,382.5,M,-25.2,M,0000,0000*66
<output omitted>


4. Install the gps daemon. Enter the command:

pi@raspberrypi ~ $ sudo apt-get install gpsd gpsd-clients python-gps
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following extra packages will be installed:
  libgps20 python-cairo python-gobject-2 python-gtk2
Suggested packages:
  python-gobject-2-dbg python-gtk2-doc
The following NEW packages will be installed:
  gpsd gpsd-clients libgps20 python-cairo python-gobject-2 python-gps
  python-gtk2
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,605 kB of archives.
After this operation, 8,113 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libgps20 armhf 3.6-4+deb7u1 [233 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main gpsd armhf 3.6-4+deb7u1 [110 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-gps armhf 3.6-4+deb7u1 [124 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-cairo armhf 1.8.8-1 [68.6 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-gobject-2 armhf 2.28.6-10 [475 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-gtk2 armhf 2.24.0-3 [1,450 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ wheezy/main gpsd-clients armhf 3.6-4+deb7u1 [144 kB]
Fetched 2,605 kB in 22s (116 kB/s)                                            
Preconfiguring packages ...
Selecting previously unselected package libgps20:armhf.
(Reading database ... 62275 files and directories currently installed.)
Unpacking libgps20:armhf (from .../libgps20_3.6-4+deb7u1_armhf.deb) ...
Selecting previously unselected package gpsd.
Unpacking gpsd (from .../gpsd_3.6-4+deb7u1_armhf.deb) ...
Selecting previously unselected package python-gps.
Unpacking python-gps (from .../python-gps_3.6-4+deb7u1_armhf.deb) ...
Selecting previously unselected package python-cairo.
Unpacking python-cairo (from .../python-cairo_1.8.8-1_armhf.deb) ...
Selecting previously unselected package python-gobject-2.
Unpacking python-gobject-2 (from .../python-gobject-2_2.28.6-10_armhf.deb) ...
Selecting previously unselected package python-gtk2.
Unpacking python-gtk2 (from .../python-gtk2_2.24.0-3_armhf.deb) ...
Selecting previously unselected package gpsd-clients.
Unpacking gpsd-clients (from .../gpsd-clients_3.6-4+deb7u1_armhf.deb) ...
Processing triggers for man-db ...
Processing triggers for menu ...
Setting up libgps20:armhf (3.6-4+deb7u1) ...
Setting up gpsd (3.6-4+deb7u1) ...
Setting up python-gps (3.6-4+deb7u1) ...
Setting up python-cairo (1.8.8-1) ...
Setting up python-gobject-2 (2.28.6-10) ...
Setting up python-gtk2 (2.24.0-3) ...
Setting up gpsd-clients (3.6-4+deb7u1) ...
Processing triggers for python-support ...
Processing triggers for menu ...
pi@raspberrypi ~ $


5. Now I will start up the gps daemon and instruct it to acquire its data from the Adafruit Ultimate GPS device that is connected to the the USB to TTY adapter cable. The Adafruit procedure omits the “-n” switch, but I am going to use it.

pi@raspberrypi ~ $ sudo gpsd /dev/ttyUSB0 -n -F /var/run/gpsd.sock

If the Adafruit is locked onto some satellites and tracking them, and the gpsd has opened up the appropriate socket (it may require you to wait a minute or so), you should be able to display the resulting stream of GPS data that we saw earlier. To see if “gpsd” is working properly, execute the command:

pi@raspberrypi ~ $ cgps -s


Press “ctrl-c” to exit and return to the command prompt. If you desire a fancier graphical display, enter the command:

pi@raspberrypi ~ $ xcgps

 

Your display should have a valid number for latitude and longitude. I scrambled the latitude and longitude in the pictures so you won’t come hunt me down and kill me if your gps doesn’t work like mine.

TROUBLESHOOTING:
1. Something that I encountered after I powered off my Pi for the night and then powered it back on the next day was that for some reason “cgps” and “xgps” did not work anymore!  No data was displayed! So I opened up "/var/log/syslog" with the Leafpad text editor and found the following output:

Oct 16 23:15:20 raspberrypi gpsd[1988]: gpsd:ERROR: can't bind to IPv4 port gpsd, Address already in use
Oct 16 23:15:20 raspberrypi gpsd[1988]: gpsd:ERROR: maybe gpsd is already running!
Oct 16 23:15:20 raspberrypi gpsd[1988]: gpsd:ERROR: can't create IPv6 socket


2. Apparently multiple instances of gpsd are trying to access the same resources. So I terminated all instances of gpsd running by executing the command:

pi@raspberrypi ~ $ sudo killall gpsd

3. Then I restarted gpsd:

pi@raspberrypi ~ $ sudo gpsd /dev/ttyUSB0 -n -F /var/run/gps.sock

4. Then I tried “cgps -s” again, and lo and behold, it was working properly.

Change the gpsd Startup Parameters
1. So, what I did next is change the startup parameters of gpsd using the “dpkg-reconfigure” program so that the next time the Pi reboots, it won't try to load gpsd multiple times.

pi@raspberrypi ~ $ sudo dpkg-reconfigure gpsd

2. Select YES to start gpsd automatically.

3. Do NOT let gpsd handle attached USB GPS receivers automatically. Select NO!



4. Enter "/dev/ttyUSB0" if isn't entered already, then select "Ok".


5. Enter the "-n" switch and select "Ok".


6. "/var/run/gpsd.sock" should be entered. If not, enter and then select "Ok". The program should exit at this point and return you to the command prompt.


7. Now that you have reconfigured the startup parameters of gpsd, I reboot your Pi, wait for a few minutes for the GPS to acquire a satellite fix and then try to run “cgps -s”. It should work every time you boot up the Pi now.


Thursday, October 10, 2013

Pi Lab 3 – NTP Server Pools






OBJECTIVE:
The objective of this lab is to learn how to configure NTP services on the Pi by changing the NTP configuration file and change the Pi’s time sources.

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.
A basic understanding of:
  • 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
Linux NTP Man Pages
  • ntpd
  • ntp.conf
  • ntpq
  • ntpdc
  • ntpdate
  • ntp_mon
  • ntp_acc
  • ntp_clock
  • ntp_misc
The NTP Protocol
  • http://www.pool.ntp.org/en/use.html
  • http://www.ntp.org/
  • http://tf.nist.gov/tf-cgi/servers.cgi
  • 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:
To change the operating parameters of the ntp daemon, you need to make changes to the configuration file “/etc/ntp.conf”.

On a fresh install of Raspbian on a Raspberry Pi, NTP is configured to get its time from a pool of low-stratum NTP servers on the Internet. Because these servers are located all over the world, the accuracy of the time updates may not be as accurate as your needs might warrant. According to the NTP Pool Project (http://www.pool.ntp.org), you will get better results getting your time from servers located closer to home, so to speak. So they have organized server pools by continent, and even by country in some instances. Each pool named in your “ntp.conf” file points to a random set of servers that changes every hour. The closer the time servers are to you, the better. You can measure a specific server’s distance from you by using the traceroute or ping utilities.

If you happen to know of a time server run by an organization that is close to you and that is available to the public (such as your ISP, a local business, or a university perhaps), you should use that instead of the pool. You can even use a combination of local servers and pool servers. Because I live in Oklahoma, smack dab in the middle of the United States, I am going to configure my Pi to use the US Zone that is a subset of the North America Zone and some servers that are closer to where I live and not half way around the world.

PROCEDURE:
Experiment 1
Change the server pool.
1.   Make a backup of the ntp.conf
2.   In the GUI, right click the icon of the computer screen entitled “LXTerminal” and then left click “Open”. This opens a CLI.
3.   Make a backup of the “ntp.conf” file. In the terminal window, enter the command “sudo cp /etc/ntp.conf /etc/ntp.conf.bak”.
4.   Open the ntp configuration file for editing by entering the command: “sudo leafpad /etc/ntp.conf”.
The reason I opened the Leafpad text editor from the CLI using “sudo” is because by default the Pi logs you into the GUI as the user “pi” and not as “root”. If you want to save any changes made to the configuration file, you must edit it as the “root” user. If you open Leafpad by clicking on the icon and then open the configuration file, you will not be able to save any changes made to it because you doing so as the user “pi”.
5.   In your “ntp.conf” file, examine the section that looks like this:
# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
6.   In front of each “server” statement, type a hash symbol (#) in a manner similar to the statements above. This turns the line of text into a comment and prevents it from being executed.
I copied and pasted the following text from “http://www.pool.ntp.org/zone/us” and then added the “iburst” option:
server 0.us.pool.ntp.org iburst
server 1.us.pool.ntp.org iburst
server 2.us.pool.ntp.org iburst
server 3.us.pool.ntp.org iburst
By adding the “iburst” option, when a time server is unreachable, the Pi will send 8 request packets to the server spaced 2 seconds apart (a burst of packets). According to the “ntp.conf” Man Page, this is a recommended option.

7.   In Leafpad, click “File”, then “Save”.
8.   Restart the ntp daemon by executing the command: “sudo service ntp restart”.
9.   After waiting a few minutes for the Pi to sync with the Internet servers, check to see if the Pi is synchronizing with the servers. This is done by executing the command: “ntpq –p”. The resulting display should look something like this:

pi@raspberrypi ~ $ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*paladin.latt.ne 204.123.2.72     2 u    2   64    1   55.435   -2.688   9.286
 int42.org       128.4.1.1        2 u    2   64    1   14.762   -1.008   1.069
 mirror          164.244.221.197  2 u    -   64    1   35.037    2.539   9.179
 tock.usshc.com  .GPS.            1 u    1   64    1   48.938   -0.541   1.574
pi@raspberrypi ~ $
Under the “remote” column you will see listed the names or IP addresses of the servers being synched to. The “refid” is the reference ID and can be an IP address, or a name that you specifically assign to it. The “st” refers to the server’s stratum. The “when” refers to the time elapsed in seconds since the server was last heard from. The “poll” column is the polling interval in seconds. The “jitter” column refers to changes in the rate packets arrive from the same flow of data. The values under “offset” and “delay” should not be zero, and the “jitter” should be less than 100. If they all are zero, then there is a problem with NTP synching with anything.

The asterisk (*) shown in the left margins indicates the currently selected peer, in other words, the server that the Pi is synching up to at that point in time. If there is no asterisk, then the Pi is not synching with anything.

Experiment 2   
Getting time from specific servers and not through a pool.
1.   Edit the “ntp.conf” file by executing the command “sudo leafpad /etc/ntp.conf”.
2.   Comment out the lines specifying the server pools by inserting the # symbol at the start of line.
Type the following lines into the configuration file as follows:

# This is a stratum 1 time server from NIST
# located in Carrollton, Texas.
server 96.226.242.9 iburst

# This is a time server from the U.S. Naval
# Observatory located at Oklahoma State
# University in Stillwater, Oklahoma.
server ntp.okstate.edu iburst
3.   In Leafpad, click “File”, then “Save”.
4.   In the CLI, restart ntp by entering the commands “sudo leafpad /etc/ntp.conf”.
5.   Next, check the status of NTP by executing the command “ntpq –p”. Here is the resulting output:

pi@raspberrypi ~ $ sudo leafpad /etc/ntp.conf
pi@raspberrypi ~ $ sudo service ntp restart
[ ok ] Stopping NTP server: ntpd.
[ ok ] Starting NTP server: ntpd.
pi@raspberrypi ~ $ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*static-96-226-2 .ACTS.           1 u    -   64    1   86.985   -0.661   1.913
+ntp.okstate.edu .GPS.            1 u    1   64    1   44.818   -1.801   4.675
pi@raspberrypi ~ $



Tuesday, October 8, 2013

Pi Lab 2 - NTP Services







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.
A basic understanding of:
  • 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
Linux NTP Man Pages
  • ntpd
  • ntp.conf
  • ntpq
  • ntpdc
  • ntpdate
  • ntp_mon
  • ntp_acc
  • ntp_clock
  • ntp_misc
The NTP Protocol
  • 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.




Monday, October 7, 2013

Pi Lab 1 – Initial Pi Setup







OBJECTIVE:

The objective of this lab is to:
Install the Raspbian Linux operating system onto the Raspberry Pi microcontroller board. Configure the Pi to communicate with other devices on an Ethernet network.

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.
  • Two straight through Ethernet cables
  • Home router\switch connected to a cable modem or DSL modem
  • A personal computer

Top View of Raspberry Pi with NOOBS SDCard












Notes:
The Pi only has only two types of display connectors – RGA and HDMI. This allows you to connect a TV to your Pi and use it as a monitor. You can also use a monitor with a standard VGA connector, but you will need to purchase a VGA-to-HDMI converter which contains circuitry to change the signal from the VGA format to the HDMI format. They can cost $20 dollars or more, and you will probably have to order it over the Internet. When I went looking for one, I went driving around to 4 different stores, but nobody had it.

Nobody had a monitor in their store that had HDMI connectors either – just VGA or DVI. So, I bought a small monitor with a DVI connector that was on sale, a HDMI cable and a HDMI-to-DVI adapter to go with it.

I initially used my cell phone charger to power the Pi because it had the required voltage and amperage rating. Then l purchased another charger on the Internet later.

PRE-REQUISITES:

A basic understanding of:
  • Ethernet networking.
  • Connector types such as HDMI, DVI, USB, RJ-45 (Ethernet), etc…
  • The Linux Operating System

REFERENCES:

http://www.raspberrypi.org/phpBB3

PROCEDURE:

Connect Everything Together
1.       Connect the PC to the router\switch that is connected to the Internet with the Ethernet cable.
Turn on and configure the PC with DHCP (obtain an IP address automatically). Using the PC, verify connectivity to the Internet so that if the Pi has any problems connecting the Internet, you will know that it isn't a problem with the Internet.
2.       Connect the keyboard and mouse to the Pi’s USB ports.
3.       Connect the monitor to the Pi’s HDMI port.
4.       Connect the Ethernet port to the router\switch with an Ethernet cable.
5.       Insert the SDCard with the pre-installed NOOBS Operating System into the Pi’s SDCard connector on the underside of the Pi as shown in the photo below.


Inserting SDCard into Pi card reader slot














Power Up the Pi
1.   Because the Pi does not have an ON\OFF switch, you turn the Pi on by connecting it to the power supply. Apply power to the Pi. When the Pi finishes booting up, you will see a window in the middle of the screen with the header “NOOBS v1.2.1-Built June 26, 2013”that lists various options.
  • Archlinux
  • OpenELEC
  • Pidora
  • RISC OS
  • RaspBMC
  • Raspbian [Recommended]
  • Edit Config (e) - allows you to change various startup parameters including video settings.
  • Online Help (h) – requires a connection to the Internet to access the URL shown above under REFERENCES.
2.   A drop down menu at the very bottom center of the screen that has various language options.
  • English
  • Deutsch (German)
  • Suomi (Finland)
  • Franais (French)
  • Magyar (Hungarian)
  • Japanese
  • Nederlands (Dutch)
  • Portugues (Portugese)
3.   Using the mouse, select “Raspbian” (double left click), and then click on the “Install OS” button. A message appears saying “Warning: This will install the selected Operating System; All existing data on the SD card will be overwritten.” Click the “Yes” button.
4.   If everything goes well, you should see a message pop up “Image applied successfully”. Click “OK” to reboot the system.
5. After the Pi reboots, a window will pop up showing the “Software Configuration Tool”. Options are:
  • Expand Filesystem. Ensures that all of the SD card us available to the OS.
  • Change userpassword. Change the password for the default user (pi).
  • Enable Boot to desktop. Boot to GUI or the command line.
  • Internationalization options.
  • Enable camera
  • Add to Rastrack
  • Overclock
  • Advanced Options
  • About raspi-config
Note: The up\down arrows and the “Tab” key are used to navigate the menus. Use the “Enter” key to make your selection.
6.   Select option “1. Expand Filesystem”. A popup message says “Your partition is not currently supported by this tool. You are probably using NOOBS, in which case your root file system is already expanded anyway.” Select “OK”.
7.   Select option “3. Enable boot to desktop”. A popup message asks “Should we boot straight to desktop?” (GUI). Select “Yes” for now.
8.   Select option “8 Advanced options”. A submenu appears. Select “A2 Hostname”. Press “Enter” and type the new hostname. Tab to “OK”, press “Enter” again to return to the main menu. When entering the new hostname, use:
  • Only letters a through z (case sensitive).
  • Digits zero through nine.
  • A hypen.
  • The name cannot begin or end with a hyphen.
  • No symbols, punctuation characters, or spaces are permitted.
9.   On the main menu, select option “2 Change password”. A popup message says “You will now be asked to enter a new password for the pi user”. “Enter” for “OK”. At the bottom left of the screen, enter your new password twice. I will use “cremepie” as my password for now.
10.   We are finished making changes. Tab to “Finish”, press “Enter”. “Reboot now?”, “Enter” again for “Yes”.
11.   At the bootup screen, there is a message that says “For recovery mode press shift”, (don't touch it!) then after a small waiting period goes to the GUI desktop interface. No login required.
12.   Verify network connectivity. Right click on the icon labeled “Midori”. This is a lightweight Internet browser. Left click “open”. If the pi has properly connected to the Internet, the page will open to an Internet website.


Midori Web Browser Icon






13. To turn the Pi off, left click the red power button on the bottom right of the screen (shown below). Wait a spell, and the power off menu will appear showing the options:
  • Shutdown
  • Reboot
  • Logout
  • Cancel
Raspberry Pi ON\OFF Button


Wednesday, October 2, 2013

Discovering CSU\DSU Loopback Plugs


In studying for the certification tests, mention was made in class, and in the books, about doing loopback tests to help in troubleshooting router WAN connections. They mentioned the required commands to enter at the router console, but no mention was made that anything needed to be done physically to the equipment.

One day I was in Leland, Mississippi trying to troubleshoot a downed T1 connection at the school district’s main office. The telco tested their circuits and said they were ok. Exasperated, I finally called Cisco’s tech support. The Cisco tech said that I needed to make a loopback plug, remove the T1 line from the

CSU\DSU, insert the plug into the DSU\DSU, and enter some commands at the router console. If the serial interface came “up and up”, then the router was good and the problem was most likely on the telco’s equipment. He also said that the telcos almost always say that it isn’t their problem. But if I tell them that my physical loopback worked, then they will admit that it’s their equipment, if it is.

So, I made the loopback plug in the manner in which he instructed me and tested the router. The interface came back up just as he said it would. So, I called the telco back and told them that my loopback tested good. They hemmed and hawed and then finally said they would do a loopback “again” on their end. Sure enough they “discovered” that they couldn’t loop their smartjack and that the problem was with their equipment at the CO (Central Office). Within 20 minutes, the school district’s router was working fine.

Cisco has a document on their web site that tells you how to make a loopback plug, but if you don’t know about it, you won’t go looking for it. Also, if you have no access to the Internet at the site because the line you are trying to fix is your connection to the Internet, how are you going to access Cisco’s web site? This is something I’d really wished was part of my training. From then on, I have always made sure that I had T1 and 56k loopback plugs in my laptop carrying case and they have saved my hide many, many, many times over.

How to Make CSU\DSU Loopback Plugs

Constructing loopback plugs for CSU\DSUs is pretty simple and straightforward. If you are accustomed to making Ethernet cables, then you should have little problems making a loopback plug. With the tip of the connector facing you, the clip on top and the wires extending out the back, the pins are numbered 1 through 8 reading from the left to the right

T1 Plug

  1. Basically all you need is an RJ45 connector and two wires from a piece of scrap Ethernet cable. A length of about 4 inches should be more than sufficient.
  2. For a T1 CSU\DSU, the idea is to connect pin 1 to pin 4, and pin 2 to pin 5. Insert the 2 wires into the connector as shown in Figure 1 and crimp.

Figure 1. T1 CSU\DSU loopback plug.

 

56K Plug

For a 56k CSU\DSU, the idea is to connect pin 1 to pin 7, and pin 2 to pin 8. Again, Insert the 2 wires into the connector as shown in Figure 2 and crimp.

Figure 2. 56k CSU\DSU loopback plug.

 

No Crimper Handy? No Problem.

So, what if you don't have a pair of crimpers handy?
  1. Find a pre-made CAT 5 cable that has the connectors already installed on both ends.
  2. Cut the cable in two about three inches from one of the ends.
  3. Remove the shielding and separate the wires.
  4. Strip the necessary wires leaving about a half-inch or so of bare metal on the ends and then twist the ends together.
  5. For a T1 loopback plug, strip and twist wires 1 and 4 together and then strip and twist wires 2 and 5 together.
  6. Leave the remaining wires dangling out the back. Do the same for a 56k loopback plug strip except twist wires 1 and 7 together and 2 and 8 together. See the diagram for a T1 loopback plug below.

Figure 3. T1 CSU\DSU loopback plug using the stripped and twisted wire method
That's all there is to it!