Category Archives: Computing

Five Minutes of Linux – Episode 6

See the YouTube video Five Minutes of Linux – Episode 6
Just about every user has their own naming system for files. Two of those systems are camel-case and underscore. The file at hand is an mp3 of the song “Strange Magic” by ELO. The camel-case version is StrangeMagic and the underscore version is Strange_Magic. No spaces are used in the first but capitalization is – thus the name camel-case. In the latter example, spaces are converted to underscores.
In the video you will notice that file name completion provides the necessary escape character (\) in front of the embedded space so that the syntactic meaning of the space is ignored and the space is treated like a character in the file name. We could have typed it ourselves or could have issued rm “Strange Magic” to the same end.
The wild card character (*) can be used to speed up file management jobs. The example in the video first attempted to delete Strange_Magic by using rm *_ but was not successful. It would have worked if the name of the file ended in an underscore. The correct command was rm *_* because it specifies that the file just have an underscore somewhere in the name. Be careful using the wild card because every file with an underscore would have been deleted.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Five Minutes of Linux – Episode 5

See the YouTube video Five Minutes of Linux – Episode 5
clear clears the screen and places you at a command prompt at the top of the window.
touch creates a file if none exists or changes the time stamp on the existing file to the current time. For example touch myfile.txt would be created as an empty file if it did not exist.
rm removes files and can accept the wild card character “*” to operate on multiple files. rm *.txt would delete all of the txt files in the current directory as long as you had permissions to do so.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Five Minutes of Linux – Episode 3

See the YouTube video Five Minutes of Linux – Episode 3
pwd is print working directory. While useful, we can get the same information from the bash prompt. Its default format is username@computername:currentworkingdirectory $.
cd is change directory and will be covered more in Episode 4. In this episode it is used to move up in the directory structure by the cd .. command. Dot-Dot (..) means the directory containing the directory you are currently working in. If you were in the directory /home/pi the cd .. command would place you in the /home directory and one more cd .. would place you in the root directory /.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Five Minutes of Linux – Episode 2

See the YouTube video Five Minutes of Linux – Episode 2
ls is a very common command that shows the content of the current working directory. To show all of the files, even the hidden ones, use the -a option. The -l and -h options show the detailed listing and displays the information in a humanly readable format, respectively. In the video I used the command ls -alh, but ls -a -l -h, ls -hal and ls -h -al would have worked also. The rule is to precede option(s) by a minus sign or another option but never by a blank space. At least one minus sign must be used and it must be preceded by an empty space.
history displays everything typed at the command line that was executed. It’s good for reviewing the commands you know you have executed but cannot recall the exact syntax.
Piping is a way to push information through another command to further process the information. The pipe symbol is “|” and on my keyboard it is the result of pressing Shift+”\”. The examples used in the video are ls -alh | less and history | less.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Five Minutes of Linux – Episode 1

I have launched a YouTube channel named Linux By Pat. The first episode will be online later today and it’s the first in a series named “Five Minutes of Linux.”

These episodes will cover the basic Linux commands and will build on that as the series progresses. By learning a few commands you can begin to build more difficult statements made of two or more commands. Two or more statements can be thought of as a program and just like that you are a programmer. Here are the commands and concepts covered today:

sudo is a command that allows a user to run a command as if he or she is the root user. Back in the old days we would have two terminals – one as root and one as our normal user.
whoami does exactly what you think it does. It just returns the username of the person logged in at that terminal. Of great help when using more than one terminal for a few hours.
apt-get update and apt-get upgrade are commands used to update the software on a Linux machine. Using them are a breeze. Unless you are logged in as root you must use the sudo command to run either of the apt-get statements above.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Using 1-Wire Sensors with Raspberry Pi

This post details how to read 1-Wire temperature probes using a Raspberry Pi and how to serve those values to the rest of the world. Links to the four-part YouTube video series are listed below.

Using 1-Wire Sensors with Raspberry Pi: Part 1, Part 2, Part 3, Part 4.

The following Python code reads my 1-Wire temperature sensors and writes them to a text file I can read from Apache. This code executes every minute on my Raspberry Pi server in the KE5PRL shack and not on the KE5PRL.com server which is in Utah.

import os
import datetime
#Many thanks to the original author of this code.

#return local time
now = datetime.datetime.now()

#return UTC time
utcnow = datetime.datetime.utcnow()

#Inside the shack.
# Open the file
Inside_tfile = open("/sys/bus/w1/devices/28-02161df565ee/w1_slave")

# Read it.
Inside_text = Inside_tfile.read()

# Close it.
Inside_tfile.close()
# Split the text with new lines (\n) and select the second line.
Inside_secondline = Inside_text.split("\n")[1]

# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
Inside_temperaturedata = Inside_secondline.split(" ")[9]

# The first two characters are "t=", so get rid of those and convert the temperature from a string $
Inside_temperature = float(Inside_temperaturedata[2:])

# Split the text with new lines (\n) and select the second line.
Inside_secondline = Inside_text.split("\n")[1]

# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
Inside_temperaturedata = Inside_secondline.split(" ")[9]

# The first two characters are "t=", so get rid of those and convert the temperature from a string $
Inside_temperature = float(Inside_temperaturedata[2:])

# Put the decimal point in the right place (in degrees C)
Inside_temperature = round(Inside_temperature / 1000, 1)

# Convert to F
Inside_Convert = round((Inside_temperature * 1.8) + 32, 1)

#Under the shack.
Under_tfile = open("/sys/bus/w1/devices/28-02161e0125ee/w1_slave")
Under_text = Under_tfile.read()
Under_tfile.close()
Under_secondline = Under_text.split("\n")[1]
Under_temperaturedata = Under_secondline.split(" ")[9]
Under_temperature = float(Under_temperaturedata[2:])
Under_temperature = round(Under_temperature / 1000, 1)
Under_Convert = round((Under_temperature * 1.8) + 32, 1)

#Outside the shack.
Outside_tfile = open("/sys/bus/w1/devices/28-02161de3afee/w1_slave")
Outside_text = Outside_tfile.read()
Outside_tfile.close()
Outside_secondline = Outside_text.split("\n")[1]
Outside_temperaturedata = Outside_secondline.split(" ")[9]
Outside_temperature = float(Outside_temperaturedata[2:])
Outside_temperature = round(Outside_temperature / 1000, 1)
Outside_Convert = round((Outside_temperature * 1.8) + 32, 1)

#GPU Temperature.
gpu1 = os.popen('vcgencmd measure_temp').readline()
gpu2 = gpu1.replace("temp=", "")#delete "temp="
gpu3a = gpu2.replace("'C", "")#delete "'C"
gpu3 = gpu3a.replace("\n","")#delete the return
gpu4 = float(gpu3)
gpu6 = round((gpu4 * 1.8) + 32, 1)

#CPU Temperature.
cpu1 = open('/sys/class/thermal/thermal_zone0/temp')
cpu2 = cpu1.read()
cpu3 = float(cpu2)
cpu4 = round((cpu3/1000 * 1.8) + 32, 1)
cpu5 = round((cpu3/1000),1)

#Open a file for writing
fo = open("/var/www/html/shackdata.txt", "w")

#Write the following pipe-delimited string.
#localtime|UTC time|Inside F|Inside C|Under F|Under C|Outside F|Outside C|GPU F|GPU C|CPU F|CPU C

fo.write( now.strftime("%H:%M %Y-%m-%d"))
fo.write("|")
fo.write( utcnow.strftime("%H:%M %Y-%m-%d"))
fo.write("|")
fo.write( str(Inside_Convert))#inside shack F
fo.write("|")
fo.write( str(Inside_temperature))#inside shack C
fo.write("|")
fo.write( str(Under_Convert) )#Under shack F
fo.write("|")
fo.write( str(Under_temperature) )#Under shack C
fo.write("|")
fo.write( str(Outside_Convert))#outside shack F
fo.write("|")
fo.write( str(Outside_temperature))#outside shack C
fo.write("|")
fo.write( str(gpu6) )#GPU F
fo.write("|")
fo.write( str(gpu3) )#GPU C
fo.write("|")
fo.write( str(cpu4) )#CPU F
fo.write("|")
fo.write( str(cpu5) )#CPU C

#Close the opened file
fo.close()

The following PHP code reads the text file created above and displays it on KE5PRL.com. This code executes on the KE5PRL Web site server and not on my Raspberry Pi server.


Facebooktwittergoogle_plusredditpinterestlinkedinmail

Raspberry Pi PuTTY Network Error Connection Refused

Just a quick mention on an update to Raspberry Pi running Raspbian… I recently used apt-get to update and upgrade and found out a few hours later that I could not SSH into my RPi using PuTTY.  Internet searches revealed that it was a common problem but not a new one.  In other words my update/upgrade wasn’t the source of the problem – it’s a problem that happens regularly.  After a couple of hours of various tweaks I discovered that SSH was not enabled.  Here is how to do it… Continue reading Raspberry Pi PuTTY Network Error Connection Refused

Facebooktwittergoogle_plusredditpinterestlinkedinmail