After years of TI technical support middleware expert (and any offers received after a job interview that I had in june) it’s now time to explore new horizons, so I’m searching some new job.
In the meantime I’ll do the very minimum here at TI: I’ll turn my phone off and no more extra help to anyone.
NOTE1: never say the truth to job interviews;
NOTE2: never help heads and collegues;
NOTE3: never say you know something more or you’ll get new work for free;
NOTE4: always be cynic
This is how to get the device mapper name (dm-1, dm-2, etc) associated to each LVM logical volume:
lvdisplay|awk '/LV Name/{n=$3} /Block device/{d=$3; sub(".*:","dm-",d); print d,n;}'
After I bought a new TSL2561 digital light sensor from Adafruit, I found that the very cool and small device cannot be accessed directly from linux (rasbian doesn’t have it’s kernel module compiled). Since I didn’t want to cross recompile my whole raspberry pi kernel just to have the tsl2563.ko driver enabled, and since it seems that raspbian does not relase genuine kernel headers to just compile custom kernel modules, I decided to write a user space simple library driver in C.
I found out that Adafruit relases proof of concept libraries written in C++ and python to access its hardware devices, the problem is that the c++ version is ready for arduino but it was not so directly usable for my raspberry pi. It also makes use of an adafruit unified sensor library and other external stuff. Since I am too lazy I decided yesterday to write a new simple library in plain C without external dependencies, just ready for my raspberry pi.
This is the arduino version that inspired me: https://github.com/adafruit/TSL2561-Arduino-Library
This is another cool blog post that inspired me (it now seems dead!!): http://russelldavis.org/2013/03/23/raspberryhunt-part-2/
This is an example:
/* prepare the sensor (the first parameter is the raspberry pi i2c master controller attached to the TSL2561, the second is the i2c selection jumper) The i2c selection address can be one of: TSL2561_ADDR_LOW, TSL2561_ADDR_FLOAT or TSL2561_ADDR_HIGH */ TSL2561 light1 = TSL2561_INIT(1, TSL2561_ADDR_FLOAT); /* initialize the sensor */ rc = TSL2561_OPEN(&light1); /* sense the luminosity from the sensor (lux is the luminosity taken in "lux" measure units) the last parameter can be 1 to enable library auto gain, or 0 to disable it */ rc = TSL2561_SENSELIGHT(&light1, &broadband, &ir, &lux, 1); TSL2561_CLOSE(&light1);
Compile:
gcc -Wall -O2 -o TSL2561.o -c TSL2561.c
gcc -Wall -O2 -o TSL2561_test.o -c TSL2561_test.c
gcc -Wall -O2 -o TSL2561_test TSL2561.o TSL2561_test.o
The output is like this:
root@rasponi:~/test/gpio# ./TSL2561_test
Test. RC: 0(Success), broadband: 141, ir: 34, lux: 12
As you can see it’s very easy at this point to get the light measures in C. Just include TSL2561.c and TSL2561.h inside your project and use the public APIs to setup and sense the IC.
I decided to release the code with the liberal apache v2 license, so feel free to include it into your commercial projects if you like.
It’s useful for me, and I hope that it can be useful to you too. Obviously it comes with absolutely no warranty.
p.s.1: I left the hardware stuff out of this article (just attach +vcc, gnd and i2c bus to the sensor
p.s.2: you have to load two kernel modules to get i2c bus working on you Raspberry pi:
modprobe i2c_bcm2708
modprobe i2c_dev
Ciao, Dino.
TSL2561.c
TSL2561.h
TSL2561_test.c
This is an example on how to use all 3 sensors on the same i2c bus:
#include <stdio.h> #include <string.h> #include "TSL2561.h" int main() { int i; int rc; uint16_t broadband, ir; uint32_t lux=0; TSL2561 lights[3]; // we can handle 3 sensors // prepare the sensors // (the first parameter is the raspberry pi i2c master controller attached to the TSL2561, the second is the i2c selection jumper) // The i2c selection address can be one of: TSL2561_ADDR_LOW, TSL2561_ADDR_FLOAT or TSL2561_ADDR_HIGH // prepare all sensors /* cannot assign that way lights[0] = TSL2561_INIT(1, TSL2561_ADDR_LOW); lights[1] = TSL2561_INIT(1, TSL2561_ADDR_FLOAT); lights[2] = TSL2561_INIT(1, TSL2561_ADDR_HIGH); */ // initialize at runtime instead // FIRST SENSOR --> TSL2561_ADDR_LOW lights[0].adapter_nr=1; // change this according to your i2c bus lights[0].sensor_addr=TSL2561_ADDR_LOW; // don't change this lights[0].integration_time=TSL2561_INTEGRATIONTIME_402MS; // don't change this lights[0].gain=TSL2561_GAIN_16X; // don't change this lights[0].adapter_fd=-1; // don't change this lights[0].lasterr=0; // don't change this bzero(&lights[0].buf, sizeof(lights[0].buf)); // don't change this // SECOND SENSOR --> TSL2561_ADDR_FLOAT lights[1].adapter_nr=1; // change this according to your i2c bus lights[1].sensor_addr=TSL2561_ADDR_FLOAT; // don't change this lights[1].integration_time=TSL2561_INTEGRATIONTIME_402MS; // don't change this lights[1].gain=TSL2561_GAIN_16X; // don't change this lights[1].adapter_fd=-1; // don't change this lights[1].lasterr=0; // don't change this bzero(&lights[1].buf, sizeof(lights[1].buf)); // don't change this // THIRD SENSOR --> TSL2561_ADDR_HIGH lights[2].adapter_nr=1; // change this according to your i2c bus lights[2].sensor_addr=TSL2561_ADDR_HIGH; // don't change this lights[2].integration_time=TSL2561_INTEGRATIONTIME_402MS; // don't change this lights[2].gain=TSL2561_GAIN_16X; // don't change this lights[2].adapter_fd=-1; // don't change this lights[2].lasterr=0; // don't change this bzero(&lights[2].buf, sizeof(lights[2].buf)); // don't change this // initialize the sensors for(i=0; i<3; i++) { rc = TSL2561_OPEN(&lights[i]); if(rc != 0) { fprintf(stderr, "Error initializing TSL2561 sensor %i (%s). Check your i2c bus (es. i2cdetect)\n", i+1, strerror(lights[i].lasterr)); return 1; } // set the gain to 1X (it can be TSL2561_GAIN_1X or TSL2561_GAIN_16X) // use 16X gain to get more precision in dark ambients, or enable auto gain below rc = TSL2561_SETGAIN(&lights[i], TSL2561_GAIN_1X); // set the integration time // (TSL2561_INTEGRATIONTIME_402MS or TSL2561_INTEGRATIONTIME_101MS or TSL2561_INTEGRATIONTIME_13MS) // TSL2561_INTEGRATIONTIME_402MS is slower but more precise, TSL2561_INTEGRATIONTIME_13MS is very fast but not so precise rc = TSL2561_SETINTEGRATIONTIME(&lights[i], TSL2561_INTEGRATIONTIME_101MS); } // you can now sense each sensor when you like for(i=0; i<3; i++) { // sense the luminosity from the sensors (lux is the luminosity taken in "lux" measure units) // the last parameter can be 1 to enable library auto gain, or 0 to disable it rc = TSL2561_SENSELIGHT(&lights[i], &broadband, &ir, &lux, 1); printf("Test sensor %i. RC: %i(%s), broadband: %i, ir: %i, lux: %i\n", i+1, rc, strerror(lights[i].lasterr), broadband, ir, lux); } // when you have finisched, you can close things for(i=0; i<3; i++) { TSL2561_CLOSE(&lights[i]); } return 0; }
If you are using IPv6 (like me) you can see that this blog is reachable via IPv6. Pretty cool!
As you may know, LVM make it possible to create live snapshots of running logical volumes.
Imagine a guest virtual machine that has its virtual disk backed on a LVM logical volume on the host system.
You may create a live hot backup of your virtual machine on the fly, while it is working.
To do this, I created a small script that makes a compressed backup of all the logical volumes on the /dev/vg0 volume group.
The script make use of the standard LVM utilities to have the snapshot, the pv utility to get a cool progress bar and pigz utility to compress (gzip) using all of your processors.
If everything went ok, when the script finishes you’ll find your LVM hot backups on the /backups directory, and the temporary lvm snapshots removed.
This is how I make hot backups of some of my virtual machines (lvm_hot_backup.sh):
#!/bin/bash
for lv in `lvdisplay /dev/vg0 | grep ‘LV Name’ | awk ‘{print $3}’`
do
LV_SIZE=”`lvs –units m –noheadings –nosuffix $lv | cut -d’ ‘ -f7 | cut -d. -f 1`” # LV size in MB
LV_UUID=”`lvdisplay $lv | grep ‘LV UUID’ | awk -F’LV UUID’ ‘{print $2}’ | sed ‘s/^ *//g’`”
LV_SNAPNAME=”SNAP_`basename $lv`”echo “LVM Logical Volume: $lv”
echo “Size: $LV_SIZE MB”
echo “UUID: $LV_UUID”
echo “Snapshot name: $LV_SNAPNAME”
echo “Removing old snapshot (if any)…”
lvremove -f “/dev/vg0/$LV_SNAPNAME”
echo “Creating snapshot…”
lvcreate -L+2G –snapshot -n”$LV_SNAPNAME” “$lv”
sleep 4
echo “Backing up snapshot…”
dd if=”/dev/vg0/$LV_SNAPNAME” bs=512k of=/dev/stdout | pv -pterbW -i 2 –buffer-size 512k –size “$LV_SIZE”m | /usr/bin/pigz -9 -b 256 > “/backups/$LV_SNAPNAME.lv.gz”
echo “Removing snapshot…”
lvremove -f “/dev/vg0/$LV_SNAPNAME”
echo “–”
done
If your SSH connection is slow, it may depends on your SSH server that is executing reverse DNS lookups to try to identify your details.
Try setting the parameter below to your /etc/ssh/sshd_config and restart your ssh server daemon:
UseDNS no
It worked perfectly for me, it may work perfectly with you too.
You may know that the PHP version coming with debian squeeze is 5.3. Since the 5.3 version of PHP breaks some compatibility with 5.2 you may find that an old PHP application is no longer working with the new version of PHP on squeeze.
The steps required to install PHP 5.2 on debian squeeze are very simple, you just need to setup APT to install the PHP packages coming with debian lenny.
The first thing to do is to add the lenny repository to the end of /etc/apt/sources.list:
deb http://archive.debian.org/debian lenny main contrib non-free
Then you need to make sure that your favourite PHP packages will be downloaded from lenny instead of squeeze. You can do this creating the file /etc/apt/preferences.d/lenny, with this stuff inside:
Explanation: choose Lenny as installation source if the package is not already installed and not available from Squeeze
Package: *
Pin: release n=lenny*
Pin-Priority: 100Explanation: choose Lenny as installation source for those packages
Package: libapache2-mod-php5 php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-cli php5-mhash php5-xsl php5-imap php5-xmlrpc php5-sqlite
Pin: release n=lenny*
Pin-Priority: 999
After that, remove any previously installed PHP 5.3 package, for example with the command
apt-get remove –purge php5\*
and then install the PHP 5.2 packages from lenny:
apt-get update
apt-get clean
apt-get install libapache2-mod-php5 php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-cli php5-mhash php5-xsl php5-imap php5-xmlrpc php5-sqlite
That procedure saved my life twice, I hope it will save yours too!
This is the end of this year. Fuck you 2012, and welcome to 2013!!
Tonight at 03.00 GTM the NuvolaBase team publicly released the new NuvolaBase Dashboard.
As you may know, with NuvolaBase you can handle your private database on the cloud.
The new dashboard aims to be simple, stable and powerful. You can login using your google, twitter, facebook, linkedin account.
In the next days the NuvolaBase guys will release many new cool features like a powerful REST API to handle your databases in the cloud from your application.
This is the official article on the NuvolaBase blog: http://nuvolabase.blogspot.it/2012/12/nuvolabase-dashboard-upgrade.html