Tuesday, 20 August 2013

My Current Network

I just thought I'd create a diagram of what devices I have where in my network, with what names. It's beginning to get a little difficult to keep them apart.
Made a small batch script to check my network ips, just for fun.
#!/bin/bash
for i in {1..150}
do
   ping -c 3 -w 100 10.0.0.$i | grep -e "icmp_req" -e "PING"
done
As you are no doubt aware, I've based the names of my devices, the naming scheme, on characters in Sir Arthur Conan Doyle's Sherlock Holmes.

Monday, 12 August 2013

Raspberry Pi

Hardware


My current hardware setup seems to work okay with the Raspberry Pi.
  • Raspberry Pi model B
  • Pretty Adafruit Pi Box (Enclosure)
  • Belkin Gold Portable Audio Player-to-Stereo Cable (2xRCA male to 3.5 mm male)
  • Belkin USB 2.0 Micro B Cable
  • Sitecom USB 2.0 hub 4-port with power adaptor and weird USB port on top (ART. CODE CN-050 v1 002)
  • SanDisk Ultra SDHC Card 32 Gb class 10
  • Perimac USB 2 to Fast Ethernet Adapter
  • RCA cable (male to male) (I had one lying around)

Software

  • mpd - Music Player Daemon (plays audio files in "/var/lib/mpd/music")
  • deluged - Deluge BitTorrent Client [2]
  • deluge-console - Deluge BitTorrent Client console
  • xbmc - X Box Media Center
  • Java JDK 8 - for the arm hf

Reasons

  • wanted to have internet 'always on' without a lot of power/computers involved
  • wanted to be in control of the software
  • wanted to download stuff easily
  • wanted to be able to send my solar panels input to the internet during daylight hours
  • wanted to play music on my (very old) stereo
  • wanted to do stuff with our old TV
  • wanted new toys to play with

Trying Wheezy Raspbian


I've downloaded Wheezy Raspbian, nowadays with Hard Float, and put it on a 32 GB SD Card.
dd bs=4M if=2013-07-26-wheezy-raspbian.img of=/dev/sdb

Downloaded 2013-05-29-wheezy-armel.zip first, which is the Software Floating Point image. XBMC is compiled for the Hardware Floating Point image. So, it won't work. Originally, I had envisioned playing with Java, and Java SDK was not available for Hardware Floating Point at the time. This has now been remedied, luckily. So no reason not to use Hardware Floating Point.[5][6]

Installing XBMC


Now, I've already tried RaspBMC, and I didn't like the fact that my default linux network scripts were replaced by XBMC scripts. Especially, as I had a non-standard setup (two ethernet ports).

So I installed XBMC on a standard Wheezy Raspbian. [4]

My TV is Black & White?


My TV provided a black and white screen. Now, given I'm European, I assumed the TV to use PAL (Phase Alternating Line, 'Picture Always Lousy') and not the (American?) NTSC (National Television System Committee, 'Never The Same Colour'). NTSC is probably the default.

Added sdtv_mode=2 to /boot/config.txt (0 is NTSC, 1 is Japanese NTSC, 2 is PAL, 3 is Brazilian PAL.)[1]

Attaching a second Ethernet by means of USB


I'm wanting to use the thing (amongst other things) as my little firewall.

ip_tables: (C) 2000-2006 Netfilter Core Team
nf_conntrack version 0.5.0 (6007 buckets, 24028 max)
Console: switching to colour dummy device 80x30
NET: Registered protocol family 10
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
smsc95xx 1-1.1:1.0: eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
usb 1-1.2: USB disconnect, device number 4
bcm2708 watchdog, heartbeat=10 sec (nowayout=0)
bcm2835-cpufreq: switching to governor ondemand
bcm2835-cpufreq: switching to governor ondemand
usb 1-1.2: new high-speed USB device number 5 using dwc_otg
usb 1-1.2: New USB device found, idVendor=05e3, idProduct=0608
usb 1-1.2: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 1-1.2: Product: USB2.0 Hub
hub 1-1.2:1.0: USB hub found
hub 1-1.2:1.0: 4 ports detected
usb 1-1.2.4: new high-speed USB device number 6 using dwc_otg
usb 1-1.2.4: New USB device found, idVendor=0424, idProduct=9e00
usb 1-1.2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.2.4: Product: LAN9500A
usb 1-1.2.4: Manufacturer: SMSC
usb 1-1.2.4: SerialNumber: 000950458
smsc95xx v1.0.4
smsc95xx 1-1.2.4:1.0: eth1: register 'smsc95xx' at usb-bcm2708_usb-1.2.4, smsc95xx USB 2.0 Ethernet, b8:27:eb:ac:eb:6a
IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
pi@raspbmc:~$ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:ac:eb:6a
inet addr:10.0.0.151 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:feac:eb6a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:560 errors:0 dropped:0 overruns:0 frame:0
TX packets:384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:36573 (35.7 KiB) TX bytes:78537 (76.6 KiB)
eth1 Link encap:Ethernet HWaddr b8:27:eb:ac:eb:6a
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

My second ethernet is detected. Yay! My /etc/network/interfaces file looks like:
auto lo eth0 eth1

iface lo inet loopback
iface eth1 inet dhcp
iface eth0 inet static
address 10.0.0.11
netmask 255.255.255.0

#allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

I have my little firewall script in "/etc/network/if-up.d/" so it runs upon boot, after network setup. But I usually forget to turn on "net.ipv4.ip_forward" in /etc/sysctl.conf.

Root access


Root access to Raspbmc is disabled, and you should use 'sudo'. But you can turn it on. http://www.raspbmc.com/wiki/user/root-access/.

I was never a "sudo" guy, but I'm getting used to it.

Expanding the root partition by hand


My Second SD card provided the following problems, after indicating that the Raspberry Pi should expand the SD Card partition and reboot. As the other SD card I have did not have this problem, I surmise that the SD card is a bit dodgy. This is the message I saw (a lot) on the screen upon boot:

end_request: I/O error, dev mmcblk0, sector 137029
mmcblk0: error -110 transferring data, sector 137030, nr 185, cmd response 0x900, card statux 0xb00
So, I attempted to expand my SD Card partition on my labtop. That fixed the problem (for now).[7]
[mrbear@localhost ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 232K 1.9G 1% /dev/shm
tmpfs 1.9G 712K 1.9G 1% /run
/dev/sda3 229G 205G 14G 94% /
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 1.9G 0 1.9G 0% /media
/dev/sdb2 1.8G 1.5G 166M 91% /media/9c7e2035-df9b-490b-977b-d60f2170889d
/dev/sdb1 56M 19M 38M 33% /media/boot
[mrbear@localhost ~]$ su -
Password:
[root@localhost ~]# umount /media/boot
[root@localhost ~]# umount /media/9c7e2035-df9b-490b-977b-d60f2170889d
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.0
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit chs
(parted) print
Model: Generic- Multi-Card (scsi)
Disk /dev/sdb: 3880,27,50
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 3880,255,63. Each cylinder is 8225kB.
Partition Table: msdos
Number Start End Type File system Flags
1 0,130,2 7,165,29 primary fat16 lba
2 7,165,30 235,214,42 primary ext4
(parted) rm 2
(parted) mkpart primary 7,165,30 3880,27,50
(parted) quit
Information: You may need to update /etc/fstab.
[root@localhost ~]# e2fsck -f /dev/sdb2
e2fsck 1.41.14 (22-Dec-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb2: 69641/114688 files (0.2% non-contiguous), 393071/458240 blocks
[root@localhost ~]# resize2fs /dev/sdb2
resize2fs 1.41.14 (22-Dec-2010)
Resizing the filesystem on /dev/sdb2 to 7776384 (4k) blocks.
The filesystem on /dev/sdb2 is now 7776384 blocks long.
[root@localhost ~]#

References

[1] RPiconfig
http://elinux.org/RPi_config.txt
[2] How to Turn a Raspberry Pi into an Always-On BitTorrent Box
http://www.howtogeek.com/142044/how-to-turn-a-raspberry-pi-into-an-always-on-bittorrent-box/
[3] RaspbianXBMC
http://www.raspbian.org/RaspbianXBMC
[4] Michael Gorven's XBMC packages for the Raspberry Pi
http://michael.gorven.za.net/raspberrypi/xbmc
[5] JavaFX on Raspberry Pi in 3 Easy Steps
http://javafx.steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
[6] OpenJDK version for the Raspberry Pi
https://wiki.openjdk.java.net/display/OpenJFX/OpenJFX+on+the+Raspberry+Pi
[7] RPi Resize Flash Partitions
http://elinux.org/RPi_Resize_Flash_Partitions
Official Raspberry Pi Website
http://www.raspberrypi.org/

Tuesday, 6 August 2013

Old Gists

Recently found out I can refer directly to different revisions of a Gist, by adding the hashtag of a revision.

Instead of <script src="https://gist.github.com/maartenl/6048082.js"></script>.

This <script src="https://gist.github.com/maartenl/6048082/95c021aa4e2b1dc1570b5f70c2dcc95a26944fe1.js"></script> will show the revision with hashtag 95c021aa4e2b1dc1570b5f70c2dcc95a26944fe1.

It's very REST-y this way.

It provides an ideal way to show different refactorings in a blog.

Awesome!

References

Embedding a specific revision of a Gist on GitHub.com via JavaScript
http://webapps.stackexchange.com/questions/22792/embedding-a-specific-revision-of-a-gist-on-github-com-via-javascript