Thursday, 27 August 2015

PhotoBox Fragment Dos - Hardware & WiFi Hotspot

Hardware

The CubieTruck is a good start, to turn it into a useful photo storage device, I believe that it needs a few hardware additions. The hardware I've used is detailed below:
  • CubieTruck;
  • Black Ewell case - it has a nice rubberised exterior and enough space for all of the other items I wanted to add;
  • WD 1.0TB 2.5" hard drive - the case is specific for 2.5" disk and you can power it from the board. There is a 3.5" adapter available, which requires a dedicated external power supply;
  • 5300mAh Li-bartery - found on https://www.buyapi.ca/;
  • 150M USB WiFi Module - explained lower why I use 2 WiFi adaptors;
  • 2A USB power-supply - not necessary if you already have one and,
  • Double-sided tape - to hold the battery in place.

The battery fits neatly underneath the harddrive (only the cable shown in the image). For a nice guide on the hardware install see the following link: http://cubieboard.org/2014/02/27/ewell-has-come-minipc-not-be-far-behind/
Approximate over all cost is somewhere in $200-$250 (CAD): $100 of which was the 1TB drive (March 2014).

A WiFi hotspot

WiFi Background

The initial plan was to let the PhotoBox connect to a network through WiFi or Ethernet (or both) for my devices to gain access. This works well while at home; however after setting up the WiFi (see the first Blog post), I realised that access to setup the WiFi access (to other networks) would require a cable between the box and a computer to connect to new hot[-]spots.
For a very small price, there is a USB WiFi Dongle (specifically for CubieBoard I and II) that I added to the set up to allow it to act as both a WiFi client and hotspot. Note: there are other ways that this would be possible, such as a script that auto-starts the hotspot after it detects there is no active WiFi, but I wanted to keep it simple for the initial project set up.

WiFi USB Dongle

Before trying to set up the PhotoBox as a WiFi hotspot, I needed to ensure that I could still access the internet wirelessly and through a cable. The cable, known as 'eth0' was already working as is the onboard WiFi known as 'wlan0'. The USB WiFi Dongle wasn't detected until I added its module to the kernel:
$ sudo 
$ modprobe 8188eu
$ ifconfig -a
$ iwlist wlan1 scan 
The initial network configuration is just the same as before, edit "/etc/network/interfaces" and add:
auto wlan1
iface wlan1 inte dhcp
wpa-conf /etc/wpa.conf
(for testing I use the same wifi file)
$ ifconfig wlan1 down
$ ifconfig wlan1 up
$ ifconfig
Both interfaces now show an IP address, and connection to the router. (remember to add the module into the "/etc/modules" file to have it operate on boot).

Hotspot Software & Settings

Hostapd is the program that I used for creating and managing the WiFi hotspot. It can be obtained through apt-get (for version 1 at time of writing), but for higher level security (WPA or WPA2) you need version 2. 

Getting hostapd v2

Normally I'm not a fan of compiling software that I want to use, if something goes wrong you need a lot of patience to sort it out, thankfully there is a decent setup-by-setup guide found at: http://www.pietervanos.net/knowledge/debian-install-hostapd-2/ I have also included the steps I followed as a reference point here:
$ sudo apt-get install git-core
$ cd ~/
$ git clone git://w1.fi/srv/git/hostap.git
$ cd hostap/hostapd
$ cp defconfig .config
$ sudo apt-get install build-essential pkg-config
$ sudo apt-get install libnl-3-dev libnl-genl-3-dev libssl-dev
Edit the ".config" file and remove the '#' from the beginning of the following lines:
CONFIG_LIBNL32=y
CONFIG_IEEE80211N=y
CONFIG_IEEE80211AC=y
CONFIG_DEBUG_FILE=y
CONFIG_HS20=y
$ sudo make
$ sudo make install
$ hostapd -v
Update the kernal modules "/etc/modules" to all for the WiFi card to act as a hot-spot
$ bcmdhd op_mode=2

Making a WiFi hotspot

For 'quick and easy', only a few basic settings are applied to the hostapd config file "/etc/hostapd-basic.conf":
interface=wlan0
driver=nl80211
ssid=test
channel=1
wpa_passphrase=password 
I'm using the onboard WiFi 'wlan0' as the hotspot interface: to test, just start the hostapd application:
sudo hostapd /etc/hostapd.conf
A machine / mobile device can now see the WiFi (and probably connect), but nothing more until the network configuration which will be in the next blog post.
use 'control' + 'c' keys together to terminate before continuing to the next bet.

Thursday, 20 August 2015

PhotoBox Fragment One

PhotoBox Fragment One

Atmosphere

The PhotoBox project grew from an idea that I should store an active copy of my digital photos in a small and easy to access box while traveling. This blogg is the basis of my documentation, should I feel like remembering what was done to get the PhotoBox working.
I've posted this publicly for anyone who might want to produce something similar, even if it's just one of the topics: I certainly spent a lot of time searching on different implementations. I've tried to list all commands as-used in my set-up, however mistakes do happen and I'm happy to correct them should any be found.

Various initial options were considered, including a kick-starter project: that is essentially what I created; unfortunately it was not funded. I have listed options below [as with everything I write, what I chose fitted my purpose and may not be the best option for you].

Options:

  1. External USB storage drive. This works well for a back-up, and I'm still using an external for 'static' back-up. There is a manual process involved and also some tasks that you will need to 'remember' to do. For this option, you will require a laptop to act as an intermediate. As I don't want to always carry a laptop, this option was not practical for me.
  2. Cloud Dropbox/OneDrive/GoogleDrive (similar). They all work equally well for both external archiving and syncing between computers. BUT, and this is a big one if traveling, they all required an internet connection.
  3. Bigger disk in laptop: although, it doesn't give easily shareable photos and is not a back-up. (I did this as well),
  4. Buy a NAS/Cloud system. This seems like a nice idea, but it's expensive: a simple Synology (without disks) is two times the price at the start of project.
  5. Create my own NAS/Cloud server that I can transport with me. The downside here (and I knew this at the start), is that it takes a longer time to get working (or working correctly) and occasionally needs some 'tinkering'. On the plus side, such a system an be a lot more versatile.
  6. Don't bother. (should always be considered an option). I've had computers break before and lost photos, this is not an option this time.

The CubieTruck

CubieTruck MainboardThere are many nice little PC-boards on offer that can be used for this sort of project. Initially, a colleague put me onto the CubieTruck (CubieBoard III). There are a few useful features which are particularly handy for this project:
  • Has a SATA port and can power a 2.5" disk.
  • Has build-in wireless and wired networking & bluetooth (there is also an IR port should you desire one)
  • Has inbuilt battery capability (you just need to buy a battery)
  • SD-Card slot (allows you to run an OS from a card giving you the ability to fix mistakes)
  • Available with a rather nice little box with enough room for everything used in my project.

OS & Networking

Fragment One will include what has been configured for the OS and Networking. This is the place to start, after which there are many options.

Getting the OS installed & updated

The initial setup has used the on-board NAND storage and the Lubuntu Server (v13) image form the Cubie site http://docs.cubieboard.org (instructions on site). I later changed my mind and converted the initial install to a SDcard and deployed a desktop Ubuntu image (I like to have VNC available for remote-desktop configuration).

Note: when initially using LiveSuite and a 2013 MacBook Pro, I found that the image would fail (possibly due to the USB3 ports). Using a 2010 MBP (with USB2) it seemed to work.

There are two options once the OS is installed. 
  1. Connect a Keyboard and TV/Monitor (and a Mouse if you are using a desktop OS)
  2. Connect the Ethernet to a network, find the IP address (thankfully my wifi-router lists the IPs on it's main page) and SSH into the box. The default username for the chosen image was 'linaro' (and the password is also 'linaro')
Once you have logged in, the first thing you need to do, is change the password for you user 
$ passwd

The second thing that you want to do, is get any updates to the OS. Part of the reason for this is that most of the installation later is using Ubuntu's `apt-get`, and making sure it works now will help.
I found that the initial sources list is out-dated and you will want to update to the following (May 2015).

Edit the file "/etc/apt/sources.list" and replace/update with the following:
deb http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse

deb http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse

deb http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse

deb http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse

Now (assuming you have internet access from the machine, for me this mean a network cable to the router for initial setup), update initial repo's, install a program called 'screen' (this lets you run commands and connect/reconnect, if needed, everything later is run under screen, although I do not specifically mention it).
$ sudo apt-get update
$ sudo apt-get install screen
$ screen 
$ apt-get dist-upgrade
$ apt-get autoremove
$ exit
(to exit screen while running, use 'control'+a then 'control'+d, to re-enter screen use `screen -x`)

It's probably a good idea to set a hostname for the machine so that you don't need to remembers it's IP-address, edit the file "/etc/hostname"
$ <my server name>

Connecting the wifi

(these instructions are taken from various sites, this is what I used in the end)
Test config
$ sudo -s
$ apt-get install iw
$ modprobe bcmdhd


$ ifconfig -a
$ iwlist wlan0 scan
# list of wi-fi network will appear
$ wpa_passphrase <Wireless Network Name> <WiFi Password> > /etc/wpa.conf

Edit then network file "/etc/network/interfaces" and add the following at the bottom of the file:
$ auto wlan0
$ iface wlan0 inet dhcp
$ wpa-conf /etc/wpa.conf

Bring up the network interface:
$ ifconfig wlan0 down
$ ifconfig wlan0 up

If this is now working, you can set the wi-fi module to load into the kernel at boot.

Edit the file "/etc/modules" and add the following to the bottom of the list:
bcmdhd

All done (for this Fragment). The OS is installed and both networking is operational. Next step is configuring a the CubieTruck as a WiFi access-point.