Showing posts with label os. Show all posts
Showing posts with label os. Show all posts

Tuesday, December 3, 2013

Raspberry Pi Journal #39


Portable Webcam Hardware - hardware+os


Okay, so we know that the webcam project works in Raspberry Pi. The next step is to bring out the portability of the device. So, we'll be making a portable Deer Camera project. Which is basically just a box with a camera on it. Because we're using Raspberry Pi, we can have all the features we want. So here's the shopping list:

Raspberry Pi B : $40
Case : $9
16 GB SD card: $12
ASUS N150 Wifi: $20

Total: $81.

Add webcam for $10, and battery pack for $50, and we'd have spent about $140 total. The battery pack is really the expensive option, and I'm sure the more creative among you can get it cheaper. I'm just using the common iphone charger. Which turns out to be a mistake. I don't have a solution for this yet, but one potential solution that you can consider would be to get a 12V car battery, hook it up with cigarrete lighter to phone charger, and into the raspberry pi. We still need lights to see, but I'm leaving it out for now.

I'm thinking that the Raspberry Pi model A would be better. However, this being my first experiment, I decided to keep it simple and simply copy the OS from my desktop computer. It works! So, the next step is to create a copy from scratch and install it SSH way. Big problems.

First, format a 16 GB SD card and copy NOOBS into it. Assemble the hardware. I'm pilfering the HDMI, keyboard, mouse, and power supply from my desktop Raspberry Pi for setting it up. Booting NOOBS over it, I'm setting it up this way:


  1. GUI off
  2. SSH on
  3. Set locale+keyboard
  4. set wpa_cli
  5. set hostname


Pull out keyboard. Reboot. SSH into it. So far so good. Half hour since I first started. I assembled the hardware already. Here is the final desired setup:




Problem. There is no connection to the network. Obviously, the /etc/network/interfaces is faulty. All attempts to fix it failed. I look for instructions. All instructions involved putting in a GUI in order to set it up. I frantically searched for instruction to set up the network without GUI. Couldn't find it. So, 2 hours later, I'm back to square one, and booted up the GUI version. It works no problem.

Sigh. Since I'm being stubborn, I want to know what action items behind the scenes are necessary in order to put up the network via CLI interface, instead of GUI interface. So, I remove everything. And after a long and arduous search on the internet, with a good deal of experimentation on my own, I finally came up with this:


  1. wpa_cli (starts in interactive mode)
  2. -scan (wait until WPA-AP-AVAILABLE)
  3. -scan_result
  4. -add_network (returns network#)
  5. -set_network 0 ssid "MyNetworkName"
  6. -set_network 0 psk "password"
  7. -enable network 0
  8. -save_config


Once you quit, you do these commands (instruction from the internet, I don't understand this):


  • iwconfig
  • sudo ifdown wlan0
  • sudo ifup wlan0
  • ip addr


So, those are the commands that comes from instruction gleamed from the internet. Don't ask. I don't know the answer.

Reboot into SSH. Success! Well, not really (Siiiiiigh!!!). I ran into the message "Remote Host ID has changed". Something about man-in-the-middle attack. So, back into the last set up. Erase all keys. Reboot into SSH. Success, finally.

So now I have a Wifi and webcam into both USB plugs, and everything is just peachy. Time to install the software


  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get motion mplayer fswebcam


We want to do it real quick to see if the set up works:


  • fswebcam -r 640x480 sample.jpg -D 15 -fps 1


check it


  • fswebcam 0l 1 --save pic%a%S.jpg
  • rsync webcampi:/home/pi/pic*.jpg


After entering the password, I downloaded the file into the desktop pi, and use gpicview to see it. Success!

Phew. Finally done.

Next step, we need to configure motion software so the server daemon would be running at reboot. But that's topic for another time.

Tuesday, October 1, 2013

Raspberry Pi Journal #30

NOOBS 1.3


Rob Bishop of Raspberry Pi foundation just announced recently asking for Beta Testers for the newly crafted NOOBS 1.3

I can see that a lot of work has been done to make it extremely user-friendly and accessible. A very interesting take about it, is the fact that you can easily have multiple OS flavor in one SD card. Therefore, you can have one all-encompassing SD card that is suitable for general, scratch, headless, servers, and so on. This is very big news! An educator can now use just one SD card for teaching different discipline. Very convenient, and thank you for providing this functionality.

I'm ambivalent about it, though. I guess I'm more of the old school tar-ball method. My idea of doing minimal headless server method would be to just install a standard distro, then ruthlessly purge the unnecessary packages. Of course, it'll be done automatically with a script.

Speaking of which, there is still no switch to use external USB hard drive. Considering that SD card do have the very real issue of wear, I think attaching a USB hard drive would be recommended so as to prolong the life of the system. I will see if I can do something about it.

Maybe some script that says: reboot with USB harddrive, and reboot with internal SD card. One button backup/restore would be handy, too. I probably will use rsync on that one.

I currently have a script that I run at the end of the day. I call it "EndOfDay.sh" that back ups my SD card to USB flashdrive, and updates my ToDo List. It's all very messy, so I will have to clean it up further.

Wednesday, August 14, 2013

Raspberry Pi Journal #6

Back Up Your SD Card part 2

On the last journal entry, I mentioned how everybody is satisfied with turning off their Raspi and pulling the card out, only to insert it to a Windows computer just to back up their SD card. Well, I'm not going to settle for that.

So, I keep digging, and finally found the program "part image". It's a partition backup program that takes a partition and save it to a file. Sounds familiar? Yes, that's exactly what "DD" Disk Dump do!

I ran into another problem. What's the name of the OS partition? Not documented anywhere, is it? After a few trial and error with fdisk, I came up with the name /dev/mmcblk0

There are 4 different partition, mmcblk0p1, mmcblk0p2, mmcblk0p3, mmcblk0p4. I'm sure one of those thing is the swap partition.

I'm backing up the first partition to my flash drive. mmcblk0p1 is fat32, 1.04 GB. Well, I think I just backed up NOOBS bootloader partition. Oh, well. It only takes about 20 minutes, anyway. Nice interface, too.

sudo -z1 -o -d save /dev/mmcblk0p1 /mnt/Lexar/raspi-p1.partimg.gz

So, that's it! Maneuver through the GUI and make some coffee!

Be careful about some of the options. There is a sync option at the end, that you want to keep, especially if you're doing live back-up. Mount devices are also iffy, and although you can override it, you definitely want to be extra careful on this one. I almost made the mistake of copying and writing to the same device, which would be bad.

I tried to do more back up:

The file system of [/dev/mmcblk02p2] is [-unknown-], and is not supported

As is partition 3 and 4.

So, the question is: Am I fully backed up or just the NOOBS?

I did

sudo dd if=/dev/mmcblk0p2 of=/media/Lexar/raspi-2.img

2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0992122 s, 10.3 kB/s

Well, obviously, my /home directory isn't in there. Let's do partition 3:

No such file or directory

Huh? It turns out they got shifted to 5 and 6. Oh, well. This is bad. I wonder if I'm destroying the file system! Better stop here for now.

In the end, I bit the bullet, and dump those anyway. Partition 5 is about 60 MB, so I'm guessing that's the swap partition. Partition 6 took such a long time, that I simply didn't wait.

sudo dd if=/dev/mmcblk0p6 | gzip -c >/media/Lexar/raspi-6.img.gz

It does about 2 MB per minute, and so I decided not to wait. Next time, I'll do it without compression, and if desired, do the compression separately. Also, I'll probably do it in the background so I can check the copying status

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid

Straight from the man page!

So, I finally did it, and what happens? Ran out of space! How can that be? And before you ask, nope, it doesn't work. Does not even boot.