How to Easily Configure WiFi in Raspberry Pi

Any version of Raspberry Pi can be very easily configured with WiFi access. Coupled with ssh or vnc, it allows you to manage your Pi remotely. Here is the simplest way I could think of, illustrated by a screenshot and detailed below.

Once your Raspberry Pi boots up, you will get to this shiny screen. Now open a Terminal by clicking on the black square icon on top-left of the screen.Screenshot from 2017-01-04 11-29-18

This opens a Terminal where you type in:

sudo leafpad /etc/network/interfaces

This opens up a notepad-like editor. Make three changes to the text as shown in the highlighted section:

  1. Change manual to dhcp in the line starting with “iface wlan0”
  2. Replace wifi_id with the Wireless Access ID / SSID
  3. Replace password with your actual password for Wireless Access

Now save it (Ctrl-S) like notepad and exit it. The terminal should still remain open.

Now either reboot the Pi or restart the network with the following command on Terminal (don’t forget to press <Enter> after you typed):

sudo service networking restart

Wait for a few minutes for the WiFi to come up. On latest Raspbian with PIXEL, you can verify by seeing the two blue arrows in opposite direction, as can be seen from the screenshot.

Suggestions for Raspberry Pi Demo & Tutorial for Engineering Students

Next week I am giving a demo of Raspberry Pi and a Tutorial to Engineering students, primarily from Electronics & Computer Science department. I am collecting suggestions on what to show them in this seminar. Currently I have thought about the following items

  • How to use Raspberry Pi to create a mini FM Radio Station as a cool example to get them hooked on Pi
  • How to write simple Java Programs with built-in IDE to show the capability of Pi

What else do you think I should show and tell?

Safest way to Update and Upgrade Raspbian Wheezy (Raspberry Pi OS)

There are plethora of instructions on the web to update and upgrade Raspbian and they work too, under normal conditions. However as Raspberry Pi is increasingly being used for Mission Critical tasks, it is important to adopt a procedure which won’t leave you with broken packages or worst, a un-bootable Operating System with your data on it. The following is a simple procedure, with explanations which will make sure that your Pi remains working.

First let’s update and upgrade the Pi with a single line command, run from terminal:

sudo apt-get update -y && sudo apt-get upgrade -y && echo success

This will update and upgrade your Pi and if successful will print success at the end.

Now reboot the Pi with:

sudo reboot

Normally Pi would reboot properly 99% of the time. If it refuses to boot then you can select the old kernel while booting to get back an usable version of Raspbian OS.

After this only two more steps remain. First is to dist-upgrade the Raspbian OS:

sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y && echo success

You  may wonder why I didn’t do it the very first time. While dist-upgrade is better than plain upgrade as it can intelligently install packages based on dependency, upgrade retains the older kernel and gives you a way to back out safely, unlike dist-upgrade. The procedure outlined above protects your OS from cases where the upgrade is broken for any reason.

Now all that is left is to reboot again to make sure everything is OK.:

sudo reboot

You may notice that I didn’t ask you to rpi-update, an instruction you will find at many places online. This is because you do not need rpi-update, the necessary firmware updates are already installed when you upgraded Raspbian. In fact, and I speak from experience, rpi-update can break your running system. Let’s leave that bleeding edge to who really needs it. If you are reading this article, then it can safely be said you don’t.

I used sudo apt-get autoremove to remove any extra packages.

The && before echo success makes sure success is printed only when the previous command succeeds.

Disk space is premium in SD Card. So it may not be out of place to check for available disk space before running update, upgrade or dist-upgrade:

df -h

To save some space clean up the downloaded debian archives with:

sudo apt-get clean

Now you understand why automating Raspbian updates / upgrades is a bad idea, unless you want to use the Raspberry pi only for testing purposes.

Advanced Note on why rpi-update was not suggested:

It’s current Raspberry Pi practice not to use this [ rpi-update ] unless you REALLY need it as it can bring in a non-working kernel (i.e. the latest bleeding edge version, which is not guaranteed to work).

My thoughts are that it is not actually required once you have done the apt-get update/upgrade cycle.

James, Raspberry Pi Foundation (Trading)

How to remove Squeak and Scratch from Raspberry Pi: Raspbian Jessie and Wheezy Distro

Raspbian Jessie and Wheezy distribution includes Squeak and Scratch. While these can be helpful educational tools for students which provides a gentle introduction to programming, it doesn’t have much use for others. The following instructions will remove both Squeak and Scratch from your Raspberry Pi (Raspbian distribution). It saves 92.7 MB and 1.15 MB respectively in Jessie and another 10.2 MB with subsequent autoremove, so over 100 MB space saved.

root@puma:/home/pi# apt-get remove --purge scratch*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'nuscratch' for regex 'scratch*'
Note, selecting 'squeak-plugins-scratch-dbg' for regex 'scratch*'
Note, selecting 'squeak-plugins-scratch' for regex 'scratch*'
Note, selecting 'python3-pifacedigital-scratch-handler' for regex 'scratch*'
Note, selecting 'libdirectory-scratch-perl' for regex 'scratch*'
Note, selecting 'libdirectory-scratch-structured-perl' for regex 'scratch*'
Note, selecting 'scratch' for regex 'scratch*'
Package 'libdirectory-scratch-perl' is not installed, so not removed
Package 'libdirectory-scratch-structured-perl' is not installed, so not removed
Package 'squeak-plugins-scratch-dbg' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  fonts-roboto gtk2-engines-clearlookspix liblightdm-gobject-1-0
  libxfce4ui-1-0 libxfce4util-bin libxfce4util-common libxfce4util6
  libxfconf-0-2 lightdm-gtk-greeter pimixer pipanel squeak-vm wiringpi
  xfce-keyboard-shortcuts xfconf
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  nuscratch* python3-pifacedigital-scratch-handler* scratch*
  squeak-plugins-scratch*
0 upgraded, 0 newly installed, 4 to remove and 1 not upgraded.
After this operation, 92.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 136309 files and directories currently installed.)
Removing nuscratch (20160115) ...
Removing 'diversion of /usr/bin/scratch to /usr/bin/scratch.old by nuscratch'
Removing 'diversion of /usr/bin/squeak to /usr/bin/squeak.old by nuscratch'
Removing 'diversion of /usr/share/scratch/locale/ja_HIRA.po to /usr/share/scratch/locale/ja_HIRA.po.old by nuscratch'
Removing 'diversion of /usr/share/scratch/locale/ja.po to /usr/share/scratch/locale/ja.po.old by nuscratch'
Purging configuration files for nuscratch (20160115) ...
Removing python3-pifacedigital-scratch-handler (2.0.5-1) ...
Purging configuration files for python3-pifacedigital-scratch-handler (2.0.5-1) ...
Removing scratch (1.4.0.6~dfsg1-5) ...
Purging configuration files for scratch (1.4.0.6~dfsg1-5) ...
Removing squeak-plugins-scratch (1.4.0.2~svn.r83-2) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for gnome-menus (3.13.3-6) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.58) ...
Processing triggers for shared-mime-info (1.3-1) ...
root@puma:/home/pi# apt-get remove --purge squeak*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'squeak-plugins-scratch-dbg' for regex 'squeak*'
Note, selecting 'squeak-vm' for regex 'squeak*'Mathematica
Note, selecting 'squeak-plugins-scratch' for regex 'squeak*'
Package 'squeak-plugins-scratch' is not installed, so not removed
Package 'squeak-plugins-scratch-dbg' is not iAfter this operation, 1,151 kB disk space will be freed.nstalled, so not removed
The following packages were automatically installed and are no longer required:And 
  fonts-roboto gtk2-engines-clearlookspix liblightdm-gobject-1-0
  libxfce4ui-1-0 libxfce4util-bin libxfce4util-common libxfce4util6
  libxfconf-0-2 lightdm-gtk-greeter pimixer pipanel wiringpi
  xfce-keyboard-shortcuts xfconf
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  squeak-vm*
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 1,151 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 135057 files and directories currently installed.)
Removing squeak-vm (1:4.10.2.2614-1.1+b1) ...
Processing triggers for shared-mime-info (1.3-1) ...
Processing triggers for gnome-menus (3.13.3-6) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.58) ...
Processing triggers for gnome-icon-theme (3.12.0-1) ...
Processing triggers for man-db (2.7.0.2-5) ...

Don’t forget to run clean and autoremove:

apt-get clean
apt-get autoremove

Now you are done!

The commands were run as root. However you can do the same from pi login by prefixing sudo at the beginning of each command. Here is a single-line version of the above using sudo:
sudo apt-get -y remove --purge scratch* squeak*; sudo apt-get clean; sudo apt-get autoremove

How to remove Wolfram Language and Mathematica from Raspberry Pi: Raspbian Jessie and Wheezy distro

Raspbian Jessie and Wheezy distribution includes Wolfram Language and Mathematica. While this can be helpful for students, it doesn’t have much use for others. The following instructions will remove both Wolfram and Mathematica from your Raspberry Pi (Raspbian distribution). It saves 658MB in Jessie.

sudo apt-get remove wolfram-engine
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following packages will be REMOVED:
 wolfram-engine
0 upgraded, 0 newly installed, 1 to remove and 59 not upgraded.
After this operation, 658 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 150191 files and directories currently installed.)
Removing wolfram-engine (10.3.1+2016012407) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for gnome-menus (3.13.3-6) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.58) ...
Processing triggers for shared-mime-info (1.3-1) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...

Then there is one final step:

sudo rm /usr/share/raspi-ui-overrides/applications/wolfram-language.desktop /usr/share/raspi-ui-overrides/applications/wolfram-mathematica.desktop

And you are done!

PS. You can read more about these free (not for commercial use) packages here.

What I learned and how I recovered from Partition Table corruption due to Power failure and fsck

Had an interesting experience. Our power blinked (rapid off and on) few times. Not only did SuKam UPS pass that through the power fluctuations but continued after power has stabilized. By the time I switched off the computer, the damage was done. It would only boot to Grub prompt.

Used a SSD drive from another computer to boot the computer and ran fsck. Instead of fixing the situation, it f*ck’ed up the three partitions of /dev/sda (/boot, swap and /) and created a single partition!

I hadn’t saved the partition information and didn’t remember how much I allocated to swap so I couldn’t safely guess their size and re-partition the disk myself.

I tried rescue option of parted and part, none of them helped.

Then I used testdisk from CGSecurity. It accurately detected the partitions and saved it. Then I fired up gparted. It couldn’t read /dev/sda3 but suggested I should reboot first, which I did.

Funnily the system was rebooting with /boot -> /dev/sda1 instead of /dev/sdb1 (SSD added for recovery) but then mounting /dev/sdb3 as / instead of /dev/sda3. This happened because the menu.lst specified the volume by label and both sda3 and sdb3 had identical label:

kernel /vmlinuz-2.6.18-408.el5 ro root=LABEL=/ rhgb quiet

During booting I changed it to use ID: root=ID=yuwew…

The ID used was of /dev/sda3

It came up but gave an error in nvidia.

I decided to try again on the actual system. I removed the extra SSD to allow the actual SSD to boot properly.

It came up fine but nvidia driver was not loading. After working for so loong with multi-monitors, it was strangely restrictive trying to get work done with a single monitor, duplicated. After some frantic search I found that the best option was to download it from nvidia and run it using init 3.

chmod 755 NVIDIA-Linux-x86_64-340.96.run
./NVIDIA-Linux-x86_64-340.96.run

Then switched back to init 5, rebooted and it multi-monitor started working again.

Take away from this experience:

  1. Always backup partition table.
  2. Do not run fsck without backing up partition table.
  3. Don’t expect fsck to always do the right thing. After all the name is intentional and the tool is to be used only as a last ditch effort to save your disk and data.
  4. UPS should not be your only protection. I am thinking of adding a spike buster in between.
  5. Regular backups are a must. I had some backups but when it happened I realized they were much too old to be of much use. Cloud backup services like Dropbox are your friend.
  6. Backup is of no value unless you remember how to restore them in an emergency.
  7. Backup disk on the same machine was unharmed. So backup even on the same machine is of some value.
  8. Next time around I will choose Graphics Card with seamless Linux support
  9. Always have a second computer around in running condition, even a Raspberry Pi is good. You may need lots of help from the Internet.
  10. Do not setup your Internet connection, router, firewall, DNS, DHCP etc. on your machine. Use your router and share with all your machines from there. Your router is less likely to fail than your machine. You may keep the settings on an unused NIC on a computer to use if your router fails.

PS. The SuKam Tubular battery has failed which SuKam support insists as the cause of this catastrophe. It was aged over 5 years.

Single line command to install PHP5, MySQL, Apache2, XCache, PHP-Pear on Raspberry Pi

Installing LAMP on Raspberry Pi is very very simple. It takes a single line to execute on terminal / console. Continue reading “Single line command to install PHP5, MySQL, Apache2, XCache, PHP-Pear on Raspberry Pi”

How to auto-update CNote, Simple CLI Note Taking Application, to Google Drive Cloud

Super simple command line note taking tool for tracking breadcrumb trail during application development…

CNote is a super-simple command line based Note taking application which we use to track changes, take notes before signing-off etc. during development. It can be used on all variants of Unix, Linux and Mac OS. It’s power lies in quickly taking notes as you are working, without interrupting your flow. The notes are searchable and stored in a viewable text file. You can download it from CNote – CLI Note Taking Application site or directly install it from command line with the following:

wget --no-check-certificate -q -O- https://raw.githubusercontent.com/angsuman/cnote/master/install.sh|bash -

CNotes is super-fast because it stores the notes locally, specifically in ~/.notes.

As we started piling up valuable notes you may start thinking what-if you machine crashes?

One simple solution is to create a symbolic link to it from DropBox managed folder. This ensures DropBox updates it in their cloud whenever new notes are added.

DropBox Nazi says: No DropBox for you!

Incidentally I use CentOS 5.1.x (latest update) on Desktop, which is not supported by DropBox. I also use Raspberry Pi, which also is not supported by DropBox.

Enter Google Drive to the rescue

I tried to make DropBox command line tool work but I found out that DropBox command line client will not work without full installation. This is not possible as CentOS 5.1.x and RaspBerry Pi are unsupported platforms.

Google Drive has a nice third-party command line tool called gdrive (download link) which is just right for my purpose. So instead of wasting more time trying to make DropBox work on RaspberryPi etc., I decided to use Google Drive cloud for backup. I used an unused Google Account for this purpose.

Get access to Google Drive

    • Open a browser and login to Google with the account you want to use.
      • Note: This may be done later too.
    • Upload ~/.notes to Google Drive for the first time:
      gdrive upload ~/.notes
      • This will provide an url which you have to open in your browser to allow gdrive to access files and directories in your Google Drive. After allowing you will be given a code which you will have to copy-paste in command line for the first upload to complete
      • After upload it prints a string (something like: 0B8qjyN8TMP9zSmRYQzhNTaBcdEFg) which is the ID of the file. Copy it. This magic key is the identity of your file on Google Drive.

Backup CNote in Google Drive

    • Now create a file named (for example) updateNoteonGDrive and open it in a text editor and paste the saved file ID.
      nohup ~/bin/gdrive update 0B8qjySampleIDQzhNTaBcdEFg ~/.notes >/dev/null 2>&1 &
  • Make this file executable with chmod:
    chmod 700 ~/bin/updateNoteonGDrive
  • Run it by hand to ensure that it properly updates your notes file in Google Drive.
  • Now open ~/.bashrc with a text editor and invoke this after saving your note like:
    n() {
            echo `date "+%Y-%m-%d %H:%M:%S"`'> '"$*" >> ~/.notes
            tail -1 ~/.notes
            updateNoteonGDrive
    }
  • This ensures every note is backed up in Google Drive. The backup process runs in the background so press Enter and continue with your work. Even if it fails because Internet is down, it will update when you write the next note.

Questions:

DropBox client on Raspberry Pi

DropBox installer client can be installed from source on Raspberry Pi.

The client expects GUI with nautilus installed which is not available by default on Pi. The installation however succeeds.

You will need to install libnautilus-extension-dev and python-docutils:

apt-get install libnautilus-extension-dev and python-docutils

Then install using:

./configure;make;sudo make install

However the whole process is in vain as it cannot install the daemon (server) dropbox with:

dropbox start -i

In the end you get the dreaded:

Error: Platform not supported

Would you like a solution – would you like to use Dropbox on Raspberry Pi?

Drop me a comment below and I may be able to help.