Monday 22 December 2014

Monitor and Display Apartment Temperature using BeagleBone Black



As a project I wanted to be able to monitor the temperature in my apartment and display it on an LCD screen. I also decided that I would also like to simultaneously display the local city temperature.

Setup

In addition to the BeagleBone Black I purchased from AdaFruit


AdaFruit provide two Python libraries


For the OS I am running the latest version of Debian wheezy

# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 7.7 (wheezy)
Release: 7.7
Codename: wheezy

After following the wiring instructions from Adafruit and installing the two python libraries as mentioned above I could display the temperature from my Apartment on the LCD screen. The next step was to get the local temperature in Vancouver, Canada. I looked at a few options such as screen scraping using the Python Beautiful Soup library on the Environment Canada website. The screen scraping did work but not consistently. Looking around for some other options I found the fantastic OpenWeatherMap project, which for Canada uses Environment Canada as a data source. There is a Python library pyowm for OpenWeatherMap. This can be installed using pip :

# pip install pyown

From OpenWeatherMap you can register for free and obtain an API key. Using the pyowm library is relatively straight forward which then allows the data to be obtained and displayed on the LCD screen. 

I have a cron job that runs every 15 minutes during the hours I want the screen to display. I posted the Python script I used on my GitHub repository in case anyone finds it a useful reference.




Fix : Linux NTFS Error Mounting $MFTMirr does not match $MFT (record 0)




With an external USB hard drive that is used to share files between Windows and Linux computers you may get an Error on Linux similar to the following :

Error mounting: mount exited with exit code 13: $MFTMirr does not match $MFT (record 0). Failed to mount ‘/dev/sdd1′: Input/output error NTFS is either inconsistent, or there is a hardware fault, or it’s a SoftRAID/FakeRAID hardware. In the first case run chkdsk /f on Windows then reboot into Windows twice. The usage of the /f parameter is very important! If the device is a SoftRAID/FakeRAID then first activate it and mount a different device under the /dev/mapper/ directory

To resolve the issue is to use ntfsprogs which can be installed from most Linux distributions e.g.

Arch Linux

$ sudo pacman -S ntfsprogs

Ubuntu/Linux Mint/Debian

$ sudo apt-get install ntfsprogs

To fix the issue run the following command syntax

$ sudo ntfsfix <drive mount point>

Change the drive to be the same shown in the Error. For example in the above error the command is

$ sudo ntfsfix /dev/sdd1

Wednesday 17 December 2014

How to : Disable BeagleBone USR Heartbeat LED lights


The BeagleBone Black by default has 4 User LED's USR0, USR1, USR2 and USR3 that light up to show the board is alive. While useful it can be annoying.

There are 4 sub directories under /sys/class/leds which allow you to configure the LED behaviour. There is one directory per LED. Within each sub directory a trigger file details what triggers the LED e.g.

# cat /sys/class/leds/beaglebone\:green\:usr0/trigger
none nand-disk mmc0 mmc1 timer oneshot [heartbeat] backlight gpio cpu0 default-on transient

The [heartbeat] is what is showing the board is alive. This can be disabled via :

# echo none > /sys/class/leds/beaglebone\:green\:usr0/trigger
# echo none > /sys/class/leds/beaglebone\:green\:usr1/trigger
# echo none > /sys/class/leds/beaglebone\:green\:usr2/trigger
# echo none > /sys/class/leds/beaglebone\:green\:usr3/trigger

To light up the LED use the brightness file.

Turn USR0 on

# echo 1 > /sys/class/leds/beaglebone\:green\:usr0/brightness

Turn USR0 off

# echo 0 > /sys/class/leds/beaglebone\:green\:usr0/brightness

Reboot

The LEDs will be reset on after reboot which is useful for troubleshooting. The /sys directory on Linux is a RAM based File system. For ease you could create a simple bash script to run as the last file on boot.

# cat DisableUSRLEDs.sh
#!/bin/bash
echo none > /sys/class/leds/beaglebone\:green\:usr0/trigger
echo none > /sys/class/leds/beaglebone\:green\:usr1/trigger
echo none > /sys/class/leds/beaglebone\:green\:usr2/trigger
echo none > /sys/class/leds/beaglebone\:green\:usr3/trigger

Tuesday 16 December 2014

BeagleBone Black Debian image initial steps



This article details initial steps of a BeagleBone Black with a Debian image. For this setup I am using a 5V adapter for power and connecting the Ethernet port to my local LAN.

  • With power and Ethernet connected the BeagleBone is set to automatically run DHCP. You can ping the hostname of 'beaglebone' to show the connectivity

$ ping beaglebone
PING beaglebone.lan (192.168.1.155) 56(84) bytes of data.
64 bytes from beaglebone.lan (192.168.1.155): icmp_seq=1 ttl=64 time=0.964 ms
64 bytes from beaglebone.lan (192.168.1.155): icmp_seq=2 ttl=64 time=0.630 ms

  • Next ssh as root (there is no password set)


  • Set a password for root :

# passwd

  • Update to the latest builds

# apt-get update
# apt-get upgrade

  • Set the correct Timezone
# dpkg-reconfigure tzdata

  • Confirm correct date

# date

  • Check that the web server is listening on port 80

# netstat -an | grep -i 80
tcp6 0 0 :::8080 :::* LISTEN
tcp6 0 0 :::80 :::* LISTEN

  • In a web browser (not IE) open the IP address of your Beaglebone to display the default page
  • Enjoy your Beaglebone!

Monday 15 December 2014

How to : Delete files securely using shred from Nemo



The Linux command line tool shred is a fantastic way to securely remove files. It can be used from the command line e.g.

$ shred --force --remove --verbose --zero examplefile3
shred: examplefile3: removing
shred: examplefile3: renamed to 000000000000
shred: 000000000000: renamed to 00000000000
shred: 00000000000: renamed to 0000000000
shred: 0000000000: renamed to 000000000
shred: 000000000: renamed to 00000000
shred: 00000000: renamed to 0000000
shred: 0000000: renamed to 000000
shred: 000000: renamed to 00000
shred: 00000: renamed to 0000
shred: 0000: renamed to 000
shred: 000: renamed to 00
shred: 00: renamed to 0
shred: examplefile3: removed

Where

  • --force : change permissions to allow writing if necessary
  • --remove : truncate and remove file after overwriting
  • --verbose : show progress
  • --zero : add a final overwrite with zeros to hide shredding

The default is to overwrite the file 3 times but you can override this with –iterations=N, setting N to be the number of iterations.

Its useful to be able to quickly remove files securely using the File manager for Cinnamon Nemo. First its useful to review the Nemo Actions sample file :

$ vim /usr/share/nemo/actions/sample.nemo_action

Define the settings you require e.g.

$ cat /usr/share/nemo/actions/shred.nemo_action
[Nemo Action]
Name=Shred file
Comment=securely delete a file
Exec=/usr/bin/shred --force --remove --verbose --zero %F
Icon-Name=gtk-execute
Selection=S
Extensions=any;
Quote=double

  • Start nemo, right click on file and select 'Shred file'



    Note – Based on feedback I added 'Quote=double' which will delete files with spaces. 

How to : Password protect a zip file on Linux




Its useful to quickly password either one or a number of files on Linux. For example to transit some files between sites on a USB drive. The encrypt option on the zip command line tool will encrypt the contents of the zip archive using a password which is entered on the terminal in response to a prompt

Note : The Zip encryption is not very strong and could be cracked so use with caution

  • To encrypt a single file :

$ zip --encrypt Example.zip examplefile1
Enter password:
Verify password:

  • To encrypt a multple files :

$ zip --encrypt ExampleMulti.zip examplefile1 examplefile2 examplefile3
Enter password:
Verify password:

  • Tu uncompress the zip file :

$ unzip Example.zip
Archive: Example.zip
[Example.zip] examplefile1 password: