Raspberry Pi HOWTO




vers 0.1 ACa 21DEC2012
vers 0.2 ACa 21APR2013
vers 0.3 ACa 06AUG2013
vers 0.4 ACa 15SEP2013
vers 0.5 ACa 01DEC2013
vers 0.6 ACa 06APR2014
vers 0.7 ACa 24AUG2014
vers 0.8 ACa 31AUG2014
vers 0.9 ACa 27DEC2014
vers 0.91 ACa 08FEB2015
vers 0.92 ACa 31DEC2015
vers 0.93 ACa 12FEB2016 - moved to Evernote
vers 0.94 ACa 13MAR2016 - clean up, added info in RPI3


Preparing SD card

(extracted from http://elinux.org/RPi_Easy_SD_Card_Setup)

I'm doing all the following under MacOS from the console.

Download the latest image from http://www.raspberrypi.org/downloads
which right now is 2012-12-16-wheezy-raspbian.zip

Check the download is ok by typeing:
$ shasum ./Downloads/2012-12-16-wheezy-raspbian.zip
to verify that the hash key is the same as the one on the download site

Unzip it. You will get the image file 2012-12-16-wheezy-raspbian.img.
Insert SD card.

$ df

With this command you indentify the correct device, for example /dev/disk1s1
Be careful not to reformat your hard drive!!!

$ sudo diskutil unmount /dev/disk2s1
$ sudo dd bs=1m if=[imagefile] of=/dev/rdisk2

This command take some minutes and you have no feedback. At the end:

$ sudo diskutil eject /dev/rdisk2

Insert your SD card into the RaspberryPI. You're done with this step.


First time installation

Login via ssh, user/passwd pi/raspberry - then change password

The following script is automatically called at first login, or you 
call it manually:

$ sudo raspi-config 

-> expand_rootfs to extend the / partition to fill the SD card - then reboot
-> set locale, use en_US.UTF-8 as the default
-> set timezone: Rome
-> memory split: set to 16MB to GPU only 
-> no overclock
-> no desktop at boot
-> update - sync latest packages

...then reboot

Finally add the following line in .bashrc:
export LC_ALL=C


Nice and useful tools that I like to have

$ sudo apt-get update           # need to sync
$ sudo apt-get upgrade          # upgrade installed packages to latest versions
$ sudo apt-get install htop     # htop - nicer "top"
$ sudo apt-get install nmap     # network scanning tool
$ sudo apt-get install emacs    # editor



How to enable IPV6

To enable it immediately:
$ sudo modprobe ipv6
If you want it to automatically be enabled at boot, 
just add ipv6 on a line by itself at the end of /etc/modules.



WiringPI

This is a library to interface with GPIO pins
See http://wiringpi.com/

$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build

Now you can have a detailed info on all pins:
$ gpio readall

You also need the following:
$ sudo apt-get install i2c-tools

More examples on the above WEB site

[to be continued]



Low Energy Bluetooth

http://www.elinux.org/RPi_Bluetooth_LE

Tested with the USB stick "CSL USB Bluetooth Nano Stick", BT 4.0

Need to build Bluez 5.4 first

$ sudo apt-get install libdbus-1-dev libglib2.0-dev libdbus-glib-1-dev
$ sudo apt-get install libusb-dev libudev-dev libreadline-dev libical-dev

$ mkdir -p work/bluepy
$ cd work/bluepy
$ wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.4.tar.xz
$ xz -d bluez-5.4.tar.xz
$ tar xvf bluez-5.4

$ cd bluez-5.4
$ ./configure --disable-systemd
$ make
$ sudo make install

Then, to check that everything is OK:

$ lsusb 
(…)
Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
(…)

$ hciconfig
hci0:    Type: BR/EDR  Bus: USB
    BD Address: 00:1A:7D:DA:71:0B  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING 
    RX bytes:38812 acl:1472 sco:0 events:1616 errors:0
    TX bytes:19317 acl:1472 sco:0 commands:80 errors:0

$ sudo hciconfig hci0 up

$ sudo hcitool lescan

How to read TI SensorTag:

$ git clone https://github.com/IanHarvey/bluepy.git
$ cd bluepy/bluepy
$ make

$ python btle.py BC:6A:29:AE:D3:98 
$ python sensortag.py -t 60 -T -H -B BC:6A:29:AE:D3:98 


Installing mbus tools

$ sudo apt-get install subversion autoconf libtool sqlite3
$ svn checkout https://github.com/rscada/libmbus
$ cd libmbus/trunk
$ ./build.sh
$ sudo make install

or (to be checked)

$ sudo apt-get install subversion autoconf libtool sqlite3
$ git clone https://github.com/rscada/libmbus.git 
$ cd libmbus/
$ ???


Interfacing 1-wire thermometer directly on a RPi

See the following links:

http://www.sdyoung.com/home/using-1-wire-ds18b20par-sensors-in-parasitic-mode-on-raspi-with-custom-gpio-pin/
http://www.iz8mbw.net/raspberrypi/1wire/
http://www.raspberrypi.org/forums/viewtopic.php?f=37&t=27241

Apparently there are some issues with this method, depending on the sensor you are using. Sensors recognized as 10-* appears to work
better than the ones with ID 28-*. In any case PULLUP is required to read something with is not 8500. But very often the reading returns 8500.
This is particularly true when more than one sensor is present on the bus, I never managed to read correctly all sensors in the same operation.
Used pull-up of 5K7 and 3V3, but also tried pull-up on 5V without any change.


Using 3G USB dongle to connect to Internet

http://lawrencematthew.wordpress.com/2013/08/07/connect-raspberry-pi-to-a-3g-network-automatically-during-its-boot/
http://www.mattiasnorell.com/blog/send-sms-from-a-raspberry-pi/
http://wiki.darknet.co.za/pmwiki.php/Posts/Sakis3gUsbModem

I have a 3G modem from Huawei, recognized by OS as:
$ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem

Furst of all install usb-modeswitch (http://www.draisberghof.de/usb_modeswitch/).
This is needed because "Several new USB devices have their proprietary Windows drivers onboard, most of them WAN dongles. 
When plugged in for the first time, they act like a flash storage and start installing the Windows driver from there.  
If the driver is already installed, it  makes  the storage device disappear and a new device, mainly composite with modem ports, shows up".
$ sudo apt-get install usb-modeswitch
(Note that this is not the case with my dongles because I already fix this a few years ago by sending some appropriate AT command to the dongle,
but I can't remember it now)

Then I install ppp:
$ sudo apt-get install ppp

Then I install sakis3G with the following command, an "out-of-the-box working script for most of huawei devices"
$ wget "http://darknet.co.za/wiki/uploads/Posts/sakis3g.tar.gz"
$ tar -xvzf sakis3g.tar.gz

Then I need to configure sakis3G:
$ sudo ./sakis3g --interactive

Once you know your default settings, you can write them in the /etc/sakis3g.conf file, which looks like this:
USBDRIVER="option"
USBINTERFACE="3"
APN="internet.wind"
APN_USER=" "
APN_PASS=" "
MODEM="12d1:1001"

To connect, just type:
$ sudo ./sakis3g connect

To disconnect:
$ sudo ./sakis3g disconnect


Using Gammu to send SMS and much more

Taken from: http://www.mattiasnorell.com/blog/send-sms-from-a-raspberry-pi/

Install gammu:
$ sudo apt-get install gammu

Then configure it - I'm not sure if I need to run these commands with sudo or not…:
$ gammu-config
Here you just need to set /dev/ttyUSB0

If the device is locked by PIN:
$ gammu --entersecuritycode PIN -
(type yout PIN here)

Some useful commands:
$ sudo gammu --identify   
Device               : /dev/ttyUSB0
Manufacturer         : Huawei
Model                : E1750 (E1750)
Firmware             : 11.126.11.00.00
IMEI                 : 359767032657323
SIM IMSI             : 228021504097027


Testing the SD card

See here: http://oss.digirati.com.br/f3/
[never used yet]


Protection agains brute force attacks

This tool will protect your computer against brute
force attacks via internet:
$ sudo apt-get install sshguard


How to install "dig"

dig is a DNS lookup utility. To install it:
$ sudo apt-get install dnsutils

How to use it:
dig @8.8.8.8 rpi01.dyndns.biz any



Setup Raspberry Pi as a dynamic DNS client

Install the client (ddclient):
$ sudo apt-get install ddclient
ddclient does not support IPv6!

Install another client which should support IPv6 (inadyn-mt):

$ sudo apt-get install libao-dev
download inadyn-mt from http://sourceforge.net/projects/inadyn-mt
unpack, then ./configure, make, sudo make install

To run it in background and only to update IPv6 address:
$ inadyn-mt  -u [username] -p [password] --ip_server_name checkip6.zerigo.com -a [alias] ip6 --background

Better define a config file /etc/inadyn-mt.conf, then simply run it in this way:
$ inadyn-mt

# Basic configuration file for inadyn
#
# /etc/inadyn.conf
#
update_period_sec 600
username [username]
password [password]
#dyndns_system dyndns@dyndns.org
ip_server_name checkip6.zerigo.com
alias rpi01.dyndns.biz
background


How to change host name

Change the name in /etc/hostname and /etc/hosts


How to upgrade the kernel

Check current kernel:
$ uname -a
Linux old-rpi01 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux

Install toll for the upgrade:
sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
sudo chmod +x /usr/bin/rpi-update

You need first to install GIT:
sudo apt-get install git-core

Executing it:
$ sudo rpi-update
(downloads 40MB, unpack, backup, ... take some time)

In no errors, then you can reboot:
$ sudo reboot

Check new kernel:
$ uname -a
Linux old-rpi01 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux 


Backup your SD card

Check wich is your SD card:
df

$ sudo diskutil unmount /dev/disk4s1
$ sudo dd bs=1m if=/dev/rdisk4 of=SD_backup.img
$ sudo diskutil eject /dev/rdisk4


Modbus

http://libmodbus.org/

$ sudo apt-get install libmodbus5 libmodbus-dev

To compile the examples:
$ cd /usr/share/doc/libmodbus-dev/examples
$ sudo gzip -d *.gz
$ sudo gcc [program_name].c -o [executable_name] `pkg-config --libs --cflags libmodbus`


RPi Video Camera

Install it: remove kapton protection from connector sitting close to ethernet port,
unlock it, slide in the flexible flat with contacts on the other side of ethernet connector,
lock it, power on the RPi.

In raspi-config enable camera use, this should set the memory sharing to 128M for the GPU.

There are many ways to strema a video.

1) via vlc using http as protocol: type the following command on RPi...

$ raspivid -rot 180 -fps 25 -n -w 1920 -h 1080 -b 8000000 -t 999999999 -o - | cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8554}' :demux=h264

...then connect, using VNC, to http://[node]:8554 to see the video stream.

Some notes: apparently 25 fps provides the smoothest video experience (???), even at 1920x1080 resolution. But
it will be much worse at 30 fps, 15 fps (not clear why...).


Use RPi as a Surveillance Camera

Many info found on the web: these are 2 interesting links:

http://www.codeproject.com/Articles/665518/Raspberry-Pi-as-low-cost-HD-surveillance-camera
http://jawwig.wordpress.com/2013/11/19/setting-up-raspberry-pi-security-cam-on-model-a-or-b-with-minimal-armhf-image/

Here are the important things:

- Case: a suggestion I found on the web was to use one of these halogen lamp cases to host the camera. It also has the bracket
to attach it, so it seems quite a good idea - investigating...


Bluetooth

$ sudo apt-get install bluez                    # bluetooth basic stuff
$ sudo apt-get install bluetooth bluez-utils    # other stuff - why one would want to install cups for all this? 


i2c

From https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

In raspi-config enable i2c load at startup, then reboot.

Install i2c-tools:
$ sudo apt-get install i2c-tools

Then do this also:
$ sudo nano /etc/modules
Add the following two lines:
i2c-bcm2708 
i2c-dev

Reboot

Now the following command should work:
$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                        

This is normal - I have no i2c attached slaves


Sensirion SHT7x

These devices cannot be addressed with the i2c protocol, but they can be connected to an i2c bus
without interfering with the other devices connected to the bus.

In order to use this sensors you need to use the bcm2835 low-level functions to directly access to
the GPIO pins (see http://www.open.com.au/mikem/bcm2835/). Unpack the .zip file, then perform
the usual ./configure; make; make installl procedure. Library will be here: /usr/local/lib/libbcm2835.a

Example on how to access the SHT7x sensors can be find here:
http://www.john.geek.nz/2012/11/update-reading-data-from-a-sensirion-sht1x-with-a-raspberry-pi/

Compile the program with: gcc -lm -lrt -o testSHT1x ./RPi_SHT1x.c testSHT1x.c -lbcm2835



SMATOOL

(instructions here: http://code.google.com/p/sma-bluetooth/wiki/Installation)

Copy latest version from http://code.google.com/p/sma-bluetooth/
unzip the package
cp smatool.conf.new smatool.conf    # smatool.conf is the one really used

You need to edit smatool.conf to suit your installation!

You need more packages before you can compile:

$ sudo apt-get install libbluetooth-dev         # bluetooth.h
$ sudo apt-get install libcurl4-gnutls-dev      # curl.h
$ sudo apt-get install libmysqlclient-dev       # mysql.h

then compile:

$ gcc -lbluetooth -lcurl -lmysqlclient -g -o smatool smatool.c

You need mysql for saving data:

$ sudo apt-get install mysql-server        # this will also install the client and other stuff
(??? mysql-client mysql-query-browser)

then try it:

$ ./smatool -v -from "2012-12-22 00:00:00" -to  "2012-12-22 11:30:00"

if you get some data all is OK

$ ./smatool --INSTALL          # installs the smatool table in mysql
(optional: here you can restore a previous mySQL backup - see below)

Now you can check the DB. Some useful examples are shown below:

mysql -p -u root
show databases;
use smatool;
show tables;
select * FROM DayData;            # this will dump a lot of data
select * FROM DayData where DateTime >= "2012-12-03 07:00:00" and DateTime <= "2012-12-03 17:59:59";    # dump with some selection
update DayData set ChangeTime="2012-12-01 00:00:00" where DateTime <= "2012-12-02 00:00:00";            # updates all fields ChangeTime with some selection
update DayData set ChangeTime="2012-12-01 00:00:00" where DateTime <= "2012-12-02 00:00:00";            # updates all fields ChangeTime with some selection
exit

update DayData set ChangeTime="2015-02-18 16:02:05" where DateTime <= "2015-02-17 17:45:00";
update DayData set PVOutput="2015-02-18 16:02:05" where DateTime <= "2015-02-17 17:45:00";

2015-02-18 16:02:05 
Remember, if you are in toubles, that PVOutput only accepts live data 7 days in the past !!!!


This command could be executed to run smatool from a cron job:
cd /home/pi/SMA/sma-bluetooth-18; ./smatool 2>&1 | logger -t smatool -p local5.info; ./smatool 2>&1 | logger -t smatool -p local5.info

In crontab file add the following lines (log to /var/log/messages):

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/pi/SMA/sma-bluetooth-18
*/5 * * * * cd /home/pi/SMA/sma-bluetooth-18; ./smatool 2>&1 | logger -t smatool -p local5.info;


mySQL

(from http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/)

to backup/restore the smatool database:

$ mysqldump -u root -p smatool > smatool.sql
$ mysql -u root -p smatool < smatool.sql


OWFS

$ sudo apt-get install owfs-fuse    # 1-wire stuff via fuse 
$ sudo apt-get install owfs         # 1-wire stuff via fuse and much more stuff

Check file /etc/owfs.conf at least to eliminate fake devices

Uncomment allow_other in /etc/fuse.conf

We here suppose that we have the interface HA7S
This command starts owfs in foreground mode with a lot of debug information:
$ sudo owfs --ha7e=/dev/ttyUSB0 -m /mnt/1wire --timeout_volatile=5 --allow_other --foreground --error_level=3

or, if you have "ebay" interface USB9097:
$ sudo owfs --dev=/dev/ttyUSB0 -m /mnt/1wire --timeout_volatile=5 --allow_other --foreground --error_level=3

-----------------------
Automatizing OWFS stuff
-----------------------
(extracted from http://hallard.wikidot.com/owfs)

Copy the following script in the file /etc/init.d/owfs:

#-------------------------------------------------------------
#! /bin/sh
case "$1" in
  start)
        # remember to put your owserver server hostname here 
        /usr/bin/sudo owfs --ha7e=/dev/ttyUSB0 -m /mnt/1w/ --timeout_volatile=5 --allow_other
        ;;
  stop)
        killall owfs
        ;;
  *)
        echo "Usage: $N {start|stop}" >&2
        exit 1
        ;;
esac
#-------------------------------------------------------------

$ chmod +x /etc/init.d/owfs
$ cd /etc/init.d
$ update-rc.d owfs defaults
(if you want to remove from autostart: $ update-rc.d owfs remove)

Some interesting aliases to be copied in .bashrc :

# ACa aliases
alias rm='/bin/rm -i'
alias cp='/bin/cp -i'
alias mv='/bin/mv -i'
alias ls1w='grep . /mnt/1w/uncached/*.*/type'
alias ls1wpio='grep . /mnt/1w/uncached/*.*/PIO.A /mnt/1w/uncached/*/PIO.B'
alias ls1wtemp='grep . /mnt/1w/uncached/*.*/temperature'


Using FUSE to create files

This program allows you to create an user filesystem containing "virtual" files and directories,
that can be mounted as any other filesyste. 

For example, you can periodically read some values from some hardware and update some specific files which
will contain the values read from the HW. The final user could access these values by looking at the content
of these files (this is how OWFS works...).

First of all you should have: fuse, libfuse-dev, fuse-utils

Then you can try this example: http://fuse.sourceforge.net/helloworld.html

Compile it:
gcc -Wall hello.c `pkg-config fuse --cflags --libs` -o hello

It will only run as root. 
You can enable user "XXX" to run it in the following way:
$ sudo usermod -aG fuse XXX
$ reboot


USB WEBCAM

Insert your webcam. I have an old Logitech which get recognized as 
$ lsusb
(...)
Bus 001 Device 006: ID 046d:092f Logitech, Inc. QuickCam Express Plus
(...)

$ sudo apt-get install motion
check that you have a video device. On my system: /dev/video0
Edit file /etc/motion/motion.conf to suit your needs

I have some prolems - cannot get any image - debugging:

sudo apt-get install v4l-utils
sudo apt-get install fswebcam

$ v4l2-ctl --all
Driver Info (not using libv4l2):
    Driver name   : spca561
    Card type     : Camera
    Bus info      : usb-bcm2708_usb-1.2
    Driver version: 3.2.27
    Capabilities  : 0x05000001
        Video Capture
        Read/Write
        Streaming
Format Video Capture:
    Width/Height  : 352/288
    Pixel Format  : 'S561'
    Field         : None
    Bytes per Line: 352
    Size Image    : 50688
    Colorspace    : SRGB
Video input : 0 (spca561: ok)
Streaming Parameters Video Capture:
    Frames per second: invalid (0/0)
    Read buffers     : 2

Testing fswebcam (will acquire at its default resolution):
fswebcam -v -d /dev/video0 test.png

fswebcam works. But motion doesn't, it cannot find the correct palette.

Allora leggi (http://forum.ubuntu-it.org/viewtopic.php?t=493568):
sudo apt-get install libv4l-dev
nel mio caso la libreria che serve e' qui: /usr/lib/arm-linux-gnueabihf/libv4l/v4l1compat.so
scrivere uno script che fa partire motion in questo modo:

export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l1compat.so
motion

In questo modo la telecamera vecchia viene riconosciuta

Ricordarsi di cambiare il seguente parametro in motion.conf to OFF:
webcam_localhost off
altrimenti l server e' accessibile solo da localhost

ATTENTION!!!
------------

For some reason I get problem on ethernet chip when usign motion (???).
This is what I see in the system log file:

Jan  6 12:52:40 rpi01 motion: [1] cap.driver: "uvcvideo"
Jan  6 12:52:40 rpi01 motion: [1] cap.card: "UVC Camera (046d:0991)"
Jan  6 12:52:40 rpi01 motion: [1] cap.bus_info: "usb-bcm2708_usb-1.2.1"
Jan  6 12:52:40 rpi01 motion: [1] cap.capabilities=0x04000001
Jan  6 12:52:40 rpi01 motion: [1] - VIDEO_CAPTURE
Jan  6 12:52:40 rpi01 motion: [1] - STREAMING
Jan  6 12:52:40 rpi01 kernel: [  366.194125] smsc95xx 1-1.1:1.0: eth0: Failed to write register index 0x00000014
Jan  6 12:52:40 rpi01 kernel: [  366.194156] smsc95xx 1-1.1:1.0: eth0: Failed to write HW_CFG_LRST_ bit in HW_CFG register, ret = -110
Jan  6 12:52:45 rpi01 motion: [1] Config palette index 6 (YUYV) doesn't work.
Jan  6 12:52:45 rpi01 motion: [1] Supported palettes:
Jan  6 12:52:45 rpi01 motion: [1] 0: MJPG (MJPEG)
Jan  6 12:52:45 rpi01 motion: [1] 1: YUYV (YUV 4:2:2 (YUYV))
Jan  6 12:52:45 rpi01 motion: [1] Selected palette YUYV
Jan  6 12:52:46 rpi01 kernel: [  372.194336] smsc95xx 1-1.1:1.0: eth0: Failed to write register index 0x00000014
Jan  6 12:52:46 rpi01 kernel: [  372.194369] smsc95xx 1-1.1:1.0: eth0: Failed to write HW_CFG_LRST_ bit in HW_CFG register, ret = -110
Jan  6 12:52:52 rpi01 kernel: [  378.194533] smsc95xx 1-1.1:1.0: eth0: Failed to write register index 0x00000014
Jan  6 12:52:52 rpi01 kernel: [  378.194565] smsc95xx 1-1.1:1.0: eth0: Failed to write HW_CFG_LRST_ bit in HW_CFG register, ret = -110

... then I lost connection to the system...

(?????????)

09-02-2013: the above issue seem to be connected to the kernel



Wireless1

(extracted from https://wiki.debian.org/rtl819x#Installation)

My WIFI dongle is based on rtl8192cu and is a 
Belkin Components F7D1102 N150/Surf Micro Wireless Adapter v1000 [Realtek RTL8188CUS]


$ sudo apt-get install firmware-realtek
wget ftp://ftp.dlink.com/Wireless/dwa130_revC/Drivers/dwa130_revC_drivers_linux_006.zip
$ unzip dwa130_revC_drivers_linux_006.zip
$ sudo mkdir -p /usr/local/lib/firmware/RTL8192U
$ sudo cp rtl8192u_linux_2.6.0006.1031.2008/firmware/RTL8192U/* /usr/local/lib/firmware/RTL8192U

In /etc/network/interfaces add the following:

auto wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

In /etc/wpa_supplicant/wpa_supplicant.conf add the following:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="Your SSID Here"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="YourPresharedKeyHere"
}

Then: 

$ sudo ifdown wlan0
$ sudo ifup wlan0

-----------------------
WARNING WARNING WARNING
-----------------------

In case of frequent dropouts you should:

$ sudo nano /etc/modprobe.d/8192cu.conf

and paste the following two lines: 

# Disable power saving
options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1


Works perfectly on my surveillance camera.


Wireless2

(extracted from http://wiki.debian.org/prism54)

My WIFI dongle is based on isl3887usb

$ mkdir /usr/local/lib/firmware
$ wget -O /usr/local/lib/firmware/isl3887usb http://daemonizer.de/prism54/prism54-fw/fw-usb/2.13.25.0.lm87.arm
$ modprobe -r p54usb ; modprobe p54usb

Now in with dmesg you should see that something has happened!

Scan for your wireless network:

$ sudo iwlist wlan0 scan      # scanning is a privileged operation, you have to sudo!

To connect to a WPA2 network: 
(from http://kerneldriver.wordpress.com/2012/10/21/configuring-wpa2-using-wpa_supplicant-on-the-raspberry-pi/)
$ sudo /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="Your SSID Here"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="YourPresharedKeyHere"
}

$ sudo /etc/network/interfaces

allow-hotplug wlan0            # this will bring the interface up automatically at boot
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp        # using DHCP


fsck

I've sometime run into disk problems, and the RPi would not boot.

So I put the SD card into an USB reader into another RPi.

There are 2 partitions on the SD card:
/dev/sda1 --> vfat
/dev/sda2 --> ext2

I have problems in /dev/sda2. To solve it I launched the command:
$ sudo fsck -v /dev/sda2

I get this:

fsck from util-linux 2.20.1
e2fsck 1.42.5 (29-Jul-2012)
/dev/sda2: recovering journal
Error reading block 197117 (Attempt to read block from filesystem resulted in short read).  Ignore error<y>? yes
Force rewrite<y>? yes
Clearing orphaned inode 2695 (uid=109, gid=114, mode=0100600, size=0)
Clearing orphaned inode 1321 (uid=109, gid=114, mode=0100600, size=0)
Clearing orphaned inode 1187 (uid=109, gid=114, mode=0100600, size=0)
Clearing orphaned inode 781 (uid=109, gid=114, mode=0100600, size=0)
Clearing orphaned inode 727 (uid=109, gid=114, mode=0100600, size=0)
Setting free inodes count to 423412 (was 423406)
Setting free blocks count to 1471706 (was 1471576)
/dev/sda2: clean, 76300/499712 files, 507302/1979008 blocks

One can also force the full filesystem check like this:

$ sudo fsck -f -v /dev/sda2


DVB-T receiver

(some support info here: http://www.linuxtv.org/wiki/index.php/Pinnacle_PCTV_Hybrid_Pro_Stick_340e)

I have a Pinnacle System PCTV 340e SE, identified as:

$ lsusb
(...)
Bus 001 Device 009: ID 2304:023e Pinnacle Systems, Inc. PCTV 340e SE
(...)

At first the system log file complained because the fw file could not be found. 
I google for firmware file "dvb-usb-dib0700-1.20.fw", download it from http://linuxtv.org/downloads/firmware/
Then from http://istvanv.users.sourceforge.net/v4l/xc4000.html#downloads I got the second firmware file I needed 
and renamed it to "dvb-fe-xc4000-1.4.fw" - this is the file the system is looking for
I copied both firmware files to /lib/firmware/

(n.b.: one should get similar firmware files with command sudo apt-get install firmware-linux-nonfree)

Now everything seems ok:

$ dmesg
[ 1982.704442] usb 1-1.2.2: new high-speed USB device number 10 using dwc_otg
[ 1982.805314] usb 1-1.2.2: New USB device found, idVendor=2304, idProduct=023e
[ 1982.805345] usb 1-1.2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1982.805362] usb 1-1.2.2: Product: PCTV 340e SE
[ 1982.805374] usb 1-1.2.2: Manufacturer: YUANRD
[ 1982.805386] usb 1-1.2.2: SerialNumber: 06007B362A
[ 1982.809837] dvb-usb: found a 'Pinnacle PCTV Hybrid Stick Solo' in cold state, will try to load a firmware
[ 1982.874884] dvb-usb: downloading firmware from file 'dvb-usb-dib0700-1.20.fw'
[ 1983.081651] dib0700: firmware started successfully.
[ 1983.584477] dvb-usb: found a 'Pinnacle PCTV Hybrid Stick Solo' in warm state.
[ 1983.584772] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[ 1983.585432] DVB: registering new adapter (Pinnacle PCTV Hybrid Stick Solo)
[ 1984.447688] DVB: registering adapter 0 frontend 0 (DiBcom 7000PC)...
[ 1984.448483] xc4000 1-0061: creating new instance
[ 1984.453937] xc4000: Successfully identified at address 0x61
[ 1984.453957] xc4000: Firmware has not been loaded previously
[ 1984.481740] Registered IR keymap rc-dib0700-rc5
[ 1984.482438] input: IR-receiver inside an USB DVB receiver as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/rc/rc2/input2
[ 1984.482764] rc2: IR-receiver inside an USB DVB receiver as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.2/rc/rc2
[ 1984.483065] dvb-usb: schedule remote query interval to 50 msecs.
[ 1984.483096] dvb-usb: Pinnacle PCTV Hybrid Stick Solo successfully initialized and connected.


Let's now install some DVB stuff:
$ sudo apt-get install dvb-apps       # it will install the utility "scan"

Interesting command for Italy:
$ scan -a 0 /usr/share/dvb/dvb-t/it-All 
 ... but it doesn't work, config file is huge and also something is wrong

!!! Found it! discovered that GUARD_INTERVAL has to be set to AUTO and not to 1/32 (don't know what it means...)

Now my configuration file (muxCAG) is the following (from http://www.sardegnahertz.it/serpeddi.html):

#-------------------------------------------
# ACa, 13/01/2013
# DVB-T MUXes frequencies for Serpeddi
#-------------------------------------------
# RAI
T 205500000 7MHz 2/3 NONE QAM64 8k AUTO NONE
# La3
T 482000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# TCS various
T 490000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Videlina Mux2
T 506000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# TIMB3
T 514000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Rete A2
T 522000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# DVBH
T 538000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Tesar
T 546000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Rete A1
T 562000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Videolina
T 594000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Sardegna TV
T 618000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Sardegna DTT
T 626000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# RAI
T 634000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Mediaset5
T 642000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# RAI
T 650000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Mediaset2
T 674000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# RAI
T 682000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# RAI
T 698000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Mediaset1
T 706000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Mediaset4
T 722000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# DFree
T 730000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# Site - 1
T 746000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# TIMB1
T 754000000 8MHz 2/3 NONE QAM64 8k AUTO NONE
# TIMB2
T 786000000 8MHz 2/3 NONE QAM64 8k AUTO NONE

Perform full channel search returned 235 services (FTA and scrambled TV channels, radios):
$ scan -a 0  ./muxCAG > CAG-FTA.conf

Create a directory .tzap in your home directory, and in there create a link
pointing to file CAG-FTA.conf (or copy that file in there)

This command will tune the detector to a specific channel
$ tzap -r "Rai 1"

This command will save the video stream to file:
$ tzap -o [outputfile] -r "Rai 1"

Once you tuner is locked on a specific channel the video stream is available here: /dev/dvb/adapter0/dvr0 


Streaming video on LAN

(under development...)
$ sudo apt-get install mumudvb
(… this was never studied feel enough, more info (maybe) here: http://www.mumudvb.net/)


>>> This approach may be more interesting (updated 11/05/2014):

From: http://angrytechnician.wordpress.com/2010/07/23/how-to-stream-every-channel-from-freeview-onto-your-network/
… and: http://angrytechnician.wordpress.com/2011/10/25/how-to-stream-freeview-hd-dvb-t2-over-multicast-using-dvblast-you-idiots/


0) plug in your favorite DVB-T receiver, check dmesg for something like this:
(…)
[    3.279457] usb 1-1.3: new high-speed USB device number 4 using dwc_otg
[    3.422223] usb 1-1.3: New USB device found, idVendor=0bda, idProduct=2838
[    3.434672] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.444065] usb 1-1.3: Product: RTL2838UHIDIR
[    3.450169] usb 1-1.3: Manufacturer: Realtek
[    3.455989] usb 1-1.3: SerialNumber: 00000013
(…)

1) Install dvb-apps
$ sudo apt-get install dvb-apps

2) install bitstream
$ git clone git://git.videolan.org/bitstream
$ cd bitstream
$ sudo make install

3) install dvblast
$ git clone git://git.videolan.org/dvblast
$ cd dvblast
$ make
$ sudo make install

4) install minisapserver
$ sudo apt-get install minisapserver

edit /etc/sap.conf and add something like this:

##################################################################
# sap.cfg - Configuration file of the mini SAP server

# Global miniSAPserver options
[global]

# Number of seconds between announces. 5 is default. Internet announces better use 30.
sap_delay=5

# The network interface on which to stream.
interface=eth0

[program]
type=rtp
name=Rai HD
user=DVBlast
machine=192.168.1.46
#site=http://www.domain.org
address=239.255.0.50
port=5004
playlist_group=RAI

[program]
type=rtp
name=Rai Storia
user=DVBlast
machine=192.168.1.46
#site=http://www.domain.org
address=239.255.0.51
port=5004
playlist_group=RAI

[program]
type=rtp
name=Rai 5
user=DVBlast
machine=192.168.1.46
#site=http://www.domain.org
address=239.255.0.52
port=5004
playlist_group=RAI
##################################################################

By default SAP server is not automatically started, so enable it:
$ sudo nano /etc/default/minisapserver
replace RUN="no" with RUN="yes"

Now start sap server:
$ sudo /etc/init.d/minisapserver restart



Now scan for transmissions:
$ scan -a 0 /usr/share/dvb/dvb-t/it-All > channels.txt
As of 11/05/2014 I found 301 services, 9 of which containing the label "HD" in the name.

Ok, now you've got some MUX you are interested in, for example the following one:
# RAI
T 682000000 8MHz 2/3 NONE QAM64 8k AUTO NONE

Create a configuration file for dvblast, for example mrai.cfg, containing the following lines
239.255.0.50:5004     1     8595
239.255.0.51:5004     1     8596
239.255.0.52:5004     1     8597

each program ID is associated to a multicast address in your network.

Start dvblast with the following parameters:
sudo /usr/local/bin/dvblast -i 1 -f 682000000 -c ~/DVB-T/mrai.cfg

Then open VLC and open the following network address:
rtp://239.255.0.50 and you will see PID "8595"

Or find your stream in "Local network" > "Network Streams (SAP)" and play it.

Enjoy! 


SDR

Software radio software for REaltek RTL2838 USB receivers
(from http://sdr.osmocom.org/trac/wiki/rtl-sdr#Software)
(isntructions from from http://sdr.osmocom.org/trac/wiki/rtl-sdr)

Prerequisites:
$ sudo apt-get install git
$ sudo apt-get install cmake
$ sudo apt-get install libusb-1.0     # needs libusb-1.0-0-dev

SDR software:
$ git clone git://git.osmocom.org/rtl-sdr.git

Compilation:
$ cd rtl-sdr/
$ mkdir build
$ cd build
$ cmake ../        # or use this command: cmake ../ -DINSTALL_UDEV_RULES=ON if you want to use the dongle from a non-root user
$ make
$ sudo make install
$ sudo ldconfig

One might need a reboot to have the possibility of running the above program without root privileges (???)


Using the SDR

As an example:
$ sudo rtl_tcp -a 192.168.1.36

In this way you transmit the IQ samples over IP


rtl_433

Get the package:
$ git clone git://github.com/merbanan/rtl_433.git

Make it:
$ cd rtl_433
$ mkdir build
$ cd build
$ cmake ../
$ make
$ sudo make install

Works but does not decode oregon data...


dump1090

git clone git://github.com/antirez/dump1090.git
make
sudo cp ./dump1090  /usr/local/bin/.


MOSQUITTO

MQTT (Telemetry Transport) is a protocol designed for sending telemetry from devices in situations where bandwidth is very limited.

$ sudo apt-get install mosquitto python-mosquitto mosquitto-clients

For an example see here: http://michaelconnors.net/article/462/hello-mqtt


NFC

(this is just a placeholder with some random info)

https://github.com/nfc-tools/libnfc
http://nfc-tools.org/index.php?title=Libnfc:configuration
http://www.backtrack-linux.org/wiki/index.php/RFID_Cooking_with_Mifare_Classic



Some instructions here: https://www.firefart.at/how-to-crack-mifare-classic-cards/

I’m using PN532 breakout board, connected with USB to UART adapter

$ apt-get install autoconf libtool libusb-dev libpcsclite-dev build-essential
$ sudo apt-get install libnfc-dev

$ mkdir libnfc
$ cd libnfc
$ git clone https://github.com/nfc-tools/libnfc.git


$ wget http://dl.bintray.com/nfc-tools/sources/libnfc-1.7.1.tar.bz2


tar -jxvf libnfc-1.7.1.tar.bz2
cd libnfc-1.7.1
autoreconf -vis
./configure --with-drivers=all --sysconfdir=/etc --prefix=/usr
make
sudo make install
sudo mkdir /etc/nfc
sudo mkdir /etc/nfc/devices.d



Netgear A6100 WIFI dongle

$ lsusb
Bus 001 Device 002: ID 0846:9052 NetGear, Inc.

Funziona perfettamente, ovviamente ci vuole un sacco di tempo per compilare tutto il kernel.

Qui si trovano un sacco di 8812au.ko precompilati per vari kernel:

How to force 5GHz:

Tutte le info sui parametri del file di configurazione del driver  (ci sono varie versioni e non sono tutte uguali):

Lo stato dei parametri attivi e’ visibile qui:  /sys/module/8812au/parameters

I parametri possono essere definiti qui:  /etc/modprobe.d/8812au.conf

Questo e’ un esempio di file che sto usando:
options 8812au rtw_bw_mode=33 rtw_vht_enable=1 rtw_ht_enable=1 rtw_power_mgnt=0 rtw_enusbss=0


# iwconfig
wlan0     IEEE 802.11bgn  ESSID:"butangas"  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency:2.412 GHz  Access Point: C0:25:06:B5:B6:75  
          Bit Rate:65 Mb/s   Sensitivity:0/0 
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:****-****-****-****-****-****-****-****   Security mode:open
          Power Management:off
          Link Quality=96/100  Signal level=89/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

def params in  /etc/modprobe.d/8812au.conf + rtw_ht_enable=0

# iwconfig
wlan0     IEEE 802.11an  ESSID:"butangas"  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency:5.22 GHz  Access Point: C0:25:06:B5:B6:71  
          Bit Rate:54 Mb/s   Sensitivity:0/0 
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:****-****-****-****-****-****-****-****   Security mode:open
          Power Management:off
          Link Quality=96/100  Signal level=89/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

def params in  /etc/modprobe.d/8812au.conf

# iwconfig
wlan0     IEEE 802.11an  ESSID:"butangas"  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency:5.18 GHz  Access Point: C0:25:06:B5:B6:71  
          Bit Rate:150 Mb/s   Sensitivity:0/0 
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:****-****-****-****-****-****-****-****   Security mode:open
          Power Management:off
          Link Quality=92/100  Signal level=91/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

Non chiaro se c’e’ una connessione tra quello che si ottiene e i parametri del file… comunque quei 150 Mb/s dovrebbe essere il massimo ottenibile

Questo e’ quanto vedo da fritz!box:


Netgear A6210 WIFI dongle

From /var/log/messages

Mar  6 19:23:22 rpi07 kernel: [  180.189801] usb 1-1.4: new high-speed USB device number 5 using dwc_otg
Mar  6 19:23:22 rpi07 kernel: [  180.291687] usb 1-1.4: New USB device found, idVendor=0846, idProduct=9053
Mar  6 19:23:22 rpi07 kernel: [  180.291726] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar  6 19:23:22 rpi07 kernel: [  180.291748] usb 1-1.4: Product: A6210
Mar  6 19:23:22 rpi07 kernel: [  180.291767] usb 1-1.4: Manufacturer: NETGEAR
Mar  6 19:23:22 rpi07 kernel: [  180.291784] usb 1-1.4: SerialNumber: 100

$ lsusb
Bus 001 Device 004: ID 0846:9053 NetGear, Inc.


First have the correct headers: So this is a way:
$ sudo dpkg -i linux-headers-4.1.8+_4.1.8+-2_armhf.deb


So this is a better way (see https://github.com/notro/rpi-source/wiki):

sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
$ rpi-source

(takes a looooong time, as it download more than 120 MB, then it unpack it….)

$ cd /home/pi/linux
$ sudo ln -s /home/pi/linux /lib/modules/$(uname -r)/build


To build the driver these are the instructions:

$ cd Netgear-A6210
$ make

(There WAS a problem in the file ../../os/linux/cfg80211/cfg80211.c !!!
To compile it an #ifdef in function CFG80211_OpsStaDel should be commented out, otherwise pMacAddr is NOT DEFINED)

$ sudo make install

It Works!!!

$ iwconfig
wlan0     Ralink STA  ESSID:"butangas"  Nickname:"mt7612u_sta"
          Mode:Managed  Frequency=2.412 GHz  Access Point: C0:25:06:B5:B6:75  
          Bit Rate=130 Mb/s  
          RTS thr:off   Fragment thr:off
          Link Quality=72/100  Signal level:-91 dBm  Noise level:-99 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

$ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr dc:ef:09:e2:00:5b 
          inet addr:192.168.1.49  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::deef:9ff:fee2:5b/64 Scope:Link
          inet6 addr: 2001:1418:263:0:5f75:b766:e81a:6fa6/64 Scope:Global
          inet6 addr: 2001:1418:263:0:deef:9ff:fee2:5b/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2102 errors:0 dropped:0 overruns:0 frame:0
          TX packets:290 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:469879 (458.8 KiB)  TX bytes:43308 (42.2 KiB)


Now we need to understand how to properly configure the parameters of this driver.
Configuration file is /etc/Wireless/RT2870STA/RT2870STA.dat
See the following README for help with the parameters: https://github.com/jurobystricky/Netgear-A6210/blob/master/README_STA_usb


Heat Sink

I’ve seen that the rpi3 gets pretty hot, with temperatures up to 70C, when all 4 cores are running at 100%. It’s probably useful to use a dissipator, like the following one.