new raspberry pi setup

Today I’m gonna setup a raspberry pi to be installed at my parents house. It runs as a headless backupmachine sitting in their meter cupboard, connected to an ADSL router modem switch (whatever).

Te most important part of this setup will be, 1) How to recognize this device from anywhere out of this world and 2)How to connect to this device for maintenance.

Things to do: setup a working ssh server, setup port forwarding on the adsl modem, setup managed dns.

Therefor I installed 2 packages: ddclient and openssh-server.

openssh-server

That’s the easiest part of this tutorial. Because I’m installing the default  raspbian (download zip, extract and dd image to sd card), I got the question if ssh server should be enabled.

wpid-20130504_104357.jpg

(also disabled desktop at boot, changed password, locale, timezone, minimized the memory_split and expanded the rootfs and updated/upgraded the packages) after first boot i also installed vim.

ddclient

first install the package by:

$sudo apt-get install ddclient

it requires some extra perl packages.

During installation some questions are asked.

I am using www.dyndns.com service.

My Login Username and password for the dynamic dns service are asked

The one milion dolar question, should in my case be answered with YES:

Please choose whether ddclient should try to find the IP address of this machine via the DynDNS web interface. This is recommended for machines that are using Network Address Translation. 

Find public IP using checkip.dyndns.com?

At my dyndns accounts I already had setup some hostnames, so I had only to pick the right one from the list.

Now only portforwarding of some port to rasby’s port 22 should be setup in the adsl modem.

apcupsd

apc_ups

Our housekeeper likes to pull plugs for vacuumcleaning (oh sorry yeah I forgot) especially the one which powers our nasses.  Besides these personal accidents, last year one of the harddisks got damaged through a very short power outage (just a fraction of a second). So to protect my nasses from these power interruptions, I bought a fully linux supported ups, a “APC Power-Saving Back-UPS Pro 900”.

Before pluging the device insert the batteries as mentioned in the manual. After this I plugged in all the cables, including a usb cable to my nas.


Installation

I installed 2 packages: apcupsd and apcups-cgi. The first handles the communication between ups and nas, the latter is for showing statistics in a webinterface.

$sudo apt-get install apcupsd apcupsd-cgi

A test can now be performed:

$sudo apctest

 

Configuartion

Now the device needs to be configured:

$sudo vi /etc/apcupsd/apcupsd.conf

and edit a few lines:

change the line:
UPSCABLE smart
into
UPSCABLE usb

Change the lines:
UPSTYPE apcsmart
DEVICE /dev/ttyS0
into
UPSTYPE usb
#DEVICE /dev/ttyS0

(ie commenting the DEVICE line).

And at last change the line:
NISIP 127.0.0.1
into
NISIP 0.0.0.0
Now the web interface can be shown from outside the machine (the nas itself is headless).

<ESC>:wq

Now the deamon needs to be started at boot time, edit:

$vi /etc/default/apcups

change the line:
ISCONFIGURED=no
into
ISCONFIGURED=yes

<ESC>:wq

Now the daemon can be started by:

$sudo service apcupsd start

 

Webinterface

This webinterface assumes an installation of apache2. With the cgi module enabled:

$sudo a2enmod cgi
$sudo service apache2 restart

The webinterface can be accessed by entering:
http://<nas url>/cgi-bin/apcupsd/multimon.cgi
and selection the nas (only 1 in my case) shows the statistics:

apc_web

sending mail from the command line with heirlooms xmail…….

First I created a ~/.mailrc file containing:

 set smtp-use-starttls
 set ssl-verify=ignore
 set smtp=smtp://$SMTPSERVERMYISP:587
 set smtp-auth=login
 set smtp-auth-user=$SMTPLOGINACCOUNT
 set smtp-auth-password=$SMTPLOGINACCOUNTPASSWORD
 set from="$MYEMAILADDRESS ($MYNAME)"

Then sending an email is just as simple as:

$mail someone@someonesisp.com

Then give the subject and start typing your message. Sending will be done by pressing CTRL-D.

read data from hyt 271 (c code)

plaatje + text

pi@raspberrypi ~/bin $ vi readhyt.c

#include <stdio.h> 
#include <fcntl.h> /*file control options. ie for open file use O_RDWR*/
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h> /* sleep */
#include <dirent.h>

int main()
{
int fh; 
unsigned char buf[4];
float h, t;

fh = open("/dev/i2c-1", O_RDWR);

ioctl(fh,I2C_SLAVE,0x28);

buf[0] = 0;
write(fh,buf,1);

usleep(60*1000);

read(fh,buf,4);

h = ((buf[0] & 0x3f) << 8 | buf[1]) * (100.0 / 0x3fff);
t = (buf[2] << 8 | (buf[3] & 0xfc)) * (165.0 / 0xfffc) - 40;

printf("0x%x 0x%x 0x%x 0x%x %4.2f %4.2f\n", buf[0],buf[1],buf[2],buf[3],h,t);

close(fh);
return 0;

}

$gcc readhyt.c -o readhyt

used variables:

fh file handle

h humidity

t temperature

$./readhyt
0x00 0x00 0x00 0x00 32.22 22.34

that part with buf[0] & 0x3f << 8 is called a mask.

 

pandaboard: wifi accesspoint, alcatel hsdpa / sms

1. download ubuntu 12.04 armhf version
(http://cdimage.ubuntu.com/releases/12.04.2/release/)

2. unzip file (right click> extract here) and dd to an sd card:
$sudo dd if=precise-preinstalled-desktop-armhf+omap4.raw of=/dev/sdd bs=4M

3. insert sd card in pandaboard. boot. answer some installation questions.

4. install advanced vi (vim).
$sudo apt-get install vim

5. install openssh-server
$sudo apt-get install openssh-server

6. main user does not need sudo passwd
$sudo visudo
add line:
icontrol ALL=NOPASSWD: ALL

7. get rid of networkmanager.
$sudo apt-get purge network-manager
(answer Y to continue)

And then as a bonus:
$sudo rm -rf /etc/NetworkManager

8. configure good old ifup eth0
$sudo vi /etc/network/interfaces

add lines:
manual eth0
iface eth0 inet dhcp

bring eth0 up:
$sudo ifup eth0

9. setup hostapd and dnsmasq
(excerpt from this previous blog)
Edit /etc/network/interfaces

Add lines and save:
auto wlan0
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0

Install hostapd and dnsmasq
$sudo apt-get install hostapd dnsmasq

create hostapd.conf
$sudo vi /etc/hostapd/hostapd.conf

Add lines:
interface=wlan0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=icontrol
hw_mode=g
channel=8
beacon_int=100
auth_algs=3
wmm_enabled=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_passphrase=very-secret-password

edit the file /etc/default/hostapd and add the line:
DAEMON_CONF="/etc/hostapd/hostapd.conf"

restart hostapd:
$sudo service hostapd restart

Should result in:
$ sudo service hostapd restart
* Stopping advanced IEEE 802.11 management hostapd [ OK ]
* Starting advanced IEEE 802.11 management hostapd [ OK ]
$

Now edit (create) the file /etc/dnsmasq.d/dnsmasq.conf and add lines:
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h

Finally edit the /etc/hosts and add:
10.0.0.1 icontrol

10. now setup the usb-hsdpa-dongle for 2 purposes: sending sms’es with gammu and connecting to the internet.
first setup the dongle. do some udev hocus pocus.

lsusb shows a device with vendor:product_id 1bbb:0017 with a description T&A Mobile Phones. That’s correct (it’s a alcatel onetouch x515 modem)
this means the usb_modeswitch rules are set correctly for this device.

make a script which on boot time the device connects to al serial driver.
create a file /usr/local/bin/usbAlcatel
$sudo vi /usr/local/bin/usbAlcatel

Add these lines:
#!/bin/sh
echo 1bbb 0017 > /sys/bus/usb-serial/drivers/option1/new_id

ie copy pasting results in a corrupt file, retype it litteraly by hand
Make this file executable:
$sudo chmod +x /usr/local/bin/usbAlcatel

now make some udev rules for this device
$sudo vi /etc/udev/rules.d/alcatelmobile.rules
Add these lines:
ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="0017" ,RUN+="/sbin/modprobe usbserial vendor=0x1bbb product=0x0017"
ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="0017", RUN+="/usr/local/bin/usbAlcatel"
ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="0017", RUN+="/sbin/modprobe option"

KERNEL!="ttyUSB[0-9]*|ttyACM[0-9]*", GOTO="alcatel_end"
ENV{ID_MODEL_ID}=="0017", ENV{ID_VENDOR_ID}=="1bbb" , SYMLINK+="alcatelmodem$env{ID_USB_INTERFACE_NUM}"
LABEL="alcatel_end"

Also here, don’t copy paste, it will result in corrupt quotes

Now a bunch of /dev/ttyUSBx devices with links to /dev/alcatelmodem0x’s are created.

Next device /dev/alcatelmodem03 will be used for the internetconnection (wvdial) and /dev/alcatelmodem05 for the sms interface (gammu)

install wvdial and gammu:
$sudo apt-get install wvdial gammu

add user to dialup group:
$sudo usermod -aG dialout icontrol

configure gammu:
$sudo vi /etc/gammurc
add these lines:
[gammu]
port = /dev/alcatelmodem05
model = onetouchx515
connection = at
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =

configure wvdial:
$sudo vi /etc/wvdial.conf
add thes lines:
[Dialer Defaults]
Dial Command = ATDT
ISDN = 0
Modem Type = Analog Modem
Modem = /dev/alcatelmodem03
Baud = 9600

[Dialer init]
Init1 = AT+CPIN=0000

[Dialer connect]
Init2 = ATZ
Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init4 = AT+CGDCONT=1,"IP","live.vodafone.com"
Phone = *99#
New PPPD = yes
Username = vodafone
Password = vodafone
Stupid Mode = 1
Baud = 460800

Now a bad hack has to be made to make this wvdial start at boot time. First the modem has to be initialized with a pincode. Thist can take a while, so a sleep 20 is invoked before the real dialup accurs in the connect section.
edit /etc/rc.local
sudo vi /etc/rc.local
add lines:
wvdial init &
sleep 20
wvdial connect &

got the hsdpa dongel to work….

1. a working internet connection:

$ sudo wvdial vodafone
--> WvDial: Internet dialer version 1.61
--> Initializing modem.
--> Sending: ATZ ATZ OK
--> Sending: ATZ ATZ OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 OK
--> Sending: AT+CGDCONT=1,"IP","live.vodafone.com" AT+CGDCONT=1,"IP","live.vodafone.com" OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier. ATDT*99# CONNECT 21000000
--> Carrier detected. Starting PPP immediately.
--> Starting pppd at Tue Apr 9 23:44:36 2013
--> Pid of pppd: 8003
--> Using interface ppp0
--> local IP address 10.173.51.172
--> remote IP address 10.64.64.64
--> primary DNS address 62.140.140.251
--> secondary DNS address 62.140.138.233
^CCaught signal 2: Attempting to exit gracefully...
--> Terminating on signal 15
--> Connect time 6.0 minutes.
--> Disconnecting at Tue Apr 9 23:50:35 2013

2. sending simultaneously and sms
$gammu sendsms TEXT +31650xxxxxx -text "Knilluz sent you this sms!!"

————————–

How did i do that

$cat sudo apt-get install wvdial

$cat /etc/udev/rules.d/alcatelmobile.rules
ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="0017" ,RUN+="/sbin/modprobe usbserial vendor=0x1bbb product=0x0017"
ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="0017", RUN+="/usr/local/bin/usbAlcatel"
ATTRS{idVendor}=="1bbb", ATTRS{idProduct}=="0017", RUN+="/sbin/modprobe option"

KERNEL!="ttyUSB[0-9]*|ttyACM[0-9]*", GOTO="alcatel_end"

ENV{ID_MODEL_ID}=="0017", ENV{ID_VENDOR_ID}=="1bbb" , SYMLINK+="alcatelmodem$env{ID_USB_INTERFACE_NUM}"

LABEL="alcatel_end"

$ cat /usr/local/bin/usbAlcatel
#!/bin/sh
echo 1bbb 0017 > /sys/bus/usb-serial/drivers/option1/new_id

$ cat /etc/wvdial.conf
[Dialer Defaults]
Dial Command = ATDT
ISDN = 0
Modem Type = Analog Modem
Modem = /dev/alcatelmodem03
Baud = 460800

[Dialer init]
Init1 = AT+CPIN=0000

[Dialer vodafone]
Init2 = ATZ
Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init4 = AT+CGDCONT=1,"IP","live.vodafone.com"
Phone = *99#
New PPPD = yes
Username = vodafone
Password = vodafone
Stupid Mode = 1

$ cat ~/.gammurc
[gammu]
port = /dev/alcatelmodem05
model =
connection = at
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =

Search for installable versions of a package (apt-get)

For a project I had to downgrade the xorg to a lower version.

To know what versions are available, the mansion option comes in handy.

$sudo apt-cache madison xserver-xorg-core

Results in my case (ubuntu 12.04.1) in:

xserver-xorg-core | 2:1.11.4-0ubuntu10.12 | ...
xserver-xorg-core | 2:1.11.4-0ubuntu10.6 | ...
xserver-xorg-core | 2:1.11.4-0ubuntu10 | ...
xorg-server | 2:1.11.4-0ubuntu10 | ...
xorg-server | 2:1.11.4-0ubuntu10.12 | ...
xorg-server | 2:1.11.4-0ubuntu10.6 | ...

There also exists a program rmadison in the devscripts
install with:

$sudo apt-get install devscripts

To use this program run:

$sudo rmadison xserver-xorg-core

Now the output will gives back more ‘historical’ versions:

xserver-xorg-core | 2:1.4.1~git20080131-1ubuntu9 |         hardy | amd64, hppa,...
xserver-xorg-core | 2:1.4.1~git20080131-1ubuntu9.3 | hardy-security | amd64, hp...
xserver-xorg-core | 2:1.4.1~git20080131-1ubuntu9.3 | hardy-updates | amd64, hpp...
xserver-xorg-core | 2:1.7.6-2ubuntu7 |         lucid | amd64, armel, i386, ia64...
xserver-xorg-core | 2:1.7.6-2ubuntu7.10 | lucid-security | amd64, armel, i386, ...
xserver-xorg-core | 2:1.7.6-2ubuntu7.11 | lucid-updates | amd64, armel, i386, i...
xserver-xorg-core | 2:1.10.4-1ubuntu4 |       oneiric | amd64, armel, i386, pow...
xserver-xorg-core | 2:1.10.4-1ubuntu4.1 | oneiric-security | amd64, armel, i386...
xserver-xorg-core | 2:1.10.4-1ubuntu4.3 | oneiric-updates | amd64, armel, i386,...
xserver-xorg-core | 2:1.11.4-0ubuntu10 |       precise | amd64, armel, armhf, i...
xserver-xorg-core | 2:1.11.4-0ubuntu10.6 | precise-security | amd64, armel, arm...
xserver-xorg-core | 2:1.11.4-0ubuntu10.12 | precise-updates | amd64, armel, arm...
xserver-xorg-core | 2:1.13.0-0ubuntu6 |       quantal | amd64, armel, armhf, i3...
xserver-xorg-core | 2:1.13.0-0ubuntu6.1 | quantal-updates | amd64, armel, armhf...
xserver-xorg-core | 2:1.13.2-0ubuntu3 |        raring | amd64, armhf, i386, pow...

let’s combine with grep (I need only the ones which include an armhf version)

$sudo rmadison xserver-xorg-core | grep armhf

xserver-xorg-core | 2:1.11.4-0ubuntu10 |       precise | amd64, armel, armhf, ...
xserver-xorg-core | 2:1.11.4-0ubuntu10.6 | precise-security | amd64, armhf,   ...
xserver-xorg-core | 2:1.11.4-0ubuntu10.12 | precise-updates | amd64, armhf, i3...
xserver-xorg-core | 2:1.13.0-0ubuntu6 |       quantal | amd64, armel, armhf, i...
xserver-xorg-core | 2:1.13.0-0ubuntu6.1 | quantal-updates | amd64, armel, armh...
xserver-xorg-core | 2:1.13.2-0ubuntu3 |        raring | amd64, armhf, i386, po...

But to make things less complicated:

$ sudo apt-cache show xserver-xorg-core

Will result in a long output. To filter only the version numbers available:

$ sudo apt-cache show xserver-xorg-core | grep Version

Results in a nice readable list:

Version: 2:1.11.4-0ubuntu10.12
Version: 2:1.11.4-0ubuntu10.6
Version: 2:1.11.4-0ubuntu10

To install the proposed version (2:1.11.4-0ubuntu10) the rule is:

$ sudo apt-get install packagname=version

$ sudo apt-get install xserver-xorg-core=2:1.11.4-0ubuntu10

Turn raspberry pi quickly in an accesspoint

I bought a very cheap wifi dongle on ebay. With a ralink rt5370 (get them for 4 euros a piece).

First thing I did edit the /etc/network/interface, that now looks like:

 auto lo
 iface lo inet loopback
 auto eth0
 iface eth0 inet dhcp
 auto wlan0
 iface wlan0 inet static
 address 10.0.0.1
 netmask 255.255.255.0

Now I installed hostapd and dnsmasq

$sudo apt-get install hostapd
$sudo apt-get install dnsmasq

Now do some setup

first the hostapd

edit the file /etc/default/hostapd by uncommenting and eddit the line:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Now hostapd will be started at boottime and will read the mentioned configurationfile. But that has to be created first by $sudo vi /etc/hostapd/hostapd.conf

I added these lines (for a full open accesspoint)

interface=wlan0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=RaspAP
hw_mode=g
channel=8
beacon_int=100
auth_algs=3
wmm_enabled=1

After the hostapd setup I did the dnsmasq setup. $sudo vi /etc/dnsmasq.d/dnsmasq.conf

interface=wlan0
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h

At last I added a line to /etc/hosts
10.0.0.1 rpi

Now do restart everything (restart services networking,hostapd and dnsmasq).

I took my android phone connected wifi to RaspAp. Opened a browser, typed in http://rpi and… Miracly I got the webpage of the raspberry pi.

WPA2

Now let’s secure the connection with some wpa2.

Therefore I added these lines to the hostapd.conf:

wpa=2 
wpa_key_mgmt=WPA-PSK 
wpa_pairwise=CCMP 
rsn_pairwise=CCMP 
wpa_passphrase=very-secret-password

The passphrase must be a string between 8 and 63 characters.
There are ways to masquerade the passphrase. But I don’t care at this moment.

Who is connected to my access point

$iw dev wlan0 station dump:

 

wordpress and the javascripts

Just building a simple website for my childrens hairdresser. Took the last wordpress. Found some nifty good looking template. And started to rebuild the template a bit. That is a good bit of plugins and third party thingy’s.

First of jQuery: a javascript library.

Superfish: a jquery plugin to do some fancy things with menu’s

prettyPhoto: A simple plugin to conveniently add prettyPhoto lightbox / modal overlay functionality to your WordPress posts and pages.

flexslider: An awesome, fully responsive jQuery slider toolkit.

masonry: I realy like this one, it makes everything move, like real magic. A dynamic layout plugin for jQuery
The flip-side of CSS floats

Poshy Tip – jQuery Plugin for Stylish Tooltips

lessgrid : simply said. make my site fit on a small screen by moving things around (a one site fits all devices idea)

modernizr:  a JavaScript library that detects HTML5 and CSS3 features in the user’s browser. (but what it does???)

The template I started with: vibe livre

rsync

My files are archived to another machine with rsync. Using a command like:

$rsync -avh [from dir] [knilluz@server:/to dir]

There is only one annoying issue with this command. The trailing slash.

rsync -avh /home/knilluz/dirtobackup/ knilluz@zerver:/backup/xxx

will lead to another result than:

rsync -avh /home/knilluz/dirtobackup knilluz@zerver:/backup/xxx

In one case the name of the directory ‘dirtobackup’ will be included in the destination, in the other case only the files in the dirtobackup will be archived. Confusing. In this blog I will show the results of all combination of the trailing slash.

And the results are: the slash in the to dir is of no meaning. If the dir exists it will be used, if it not exists it will be created. But the slash in the from dir is very meaningfull: if used the data in the dir will be copied. if NO trailing slash is used, ALSO the dirname will be copied.

So if you sync with this command:

rsync -avh /home/knilluz/fotos knilluz@remote:/home/knilluz/fotos

at remote site the result will be /home/knilluz/fotos/fotos/[lots of jpg’s]

In this case a trailing slash should be used.

rsync-experiment