Wednesday, September 5, 2012

Get back your privilege for your Ubuntu.

Recently, I lost my sudo privilege for linux system, which make me feel panic. I don't want to reinstall the system again. I got no time to do this.
However, I was lucky enough to find a solution.

In fact it is easy. Restart the system and select recovery mode from grub menu.

Next step, just select fsck so that you can mount / as a writeable directory.

When you finish the step above, select enter the system as root.

sudo addgroup your-username sudo

Now you are fine.

Sunday, June 17, 2012

How to use Rssi value to calculate Distance

Before we start to explain the formula. We have to make it clear about db and dbm.
db is just a kind of ratio between two value. db=10*lg(x/y)
so dbm is a ratio between a power value and 1 mWatt.

0dbm=10*lg(x/1mWatt), so x=1mWatt.
10dbm=10*lg(y/1mWatt), so y=10mWatt.

Thus, the difference between 2 two value in dbm is in db.


Now lets look at the Log-distance path loss model:

PL\;=P_{Tx_{dBm}}-P_{Rx_{dBm}}\;=\;PL_0\;+\;10\gamma\;\log_{10} \frac{d}{d_0}\;+\;X_g,     (1)

PTxdbm is the transmitted power in dbm, and PRxdbm is the received power in dbm.
so the path loss PL is in db.

Path loss, in fact, can be calculated in this formula:

L = 10\ n\ \log_{10}(d)+C    (2)

If we add a reference path loss into the formula, we can have:

PL = PL0 - 10*n*lg(d0) + 10*n*lg(d) + C = PL0 + 10*n*lg(d/d0) + C   (3)

(3) is as same as (1).

We now can use the data from experiment to calculate the distance from Rssi.

Note: PTxdbm is the initial power P for sending the message. PRxdbm is the Rssi value.

First, choose a reference distance d0 and corresponding Rssi value. calculate the PL0 = PTxdbm - PRxdbm

Then, use the other data to make more formulas. We can use this formulas to get the value of γ and Xg

Finally, we can get a function between Rssi and d

Rssi(d) =  P - PL0 - 10*γ*lg(d/d0) + Xg

P is the transmitted power.
PL0 is the reference path loss.
d0 is the reference distance.
 γ is the path loss exponent.


Thursday, May 24, 2012

TinyOS-2.1.1 Installation on Ubuntu 12.04 and Hello World

I am working on TinyOS and nesc recently, but installation confused me for a long time.
Finally, I found a way to make it.
Install TinyOS-2.1.1 on Ubuntu 12.04

  1. add TinyOS-2.1.1 to source list.
    You can open the /etc/apt/source.list to edit the file.
    sudo gedit /etc/apt/sources.list

    and add
     deb natty main

    or you can open ubuntu software centre and choose edit, choose software sources, other software, add, put the above sentence in the dialog. 

  2. open your terminal, type in
    sudo apt-get update
  3. install tinyos
     sudo apt-get install tinyos
  4. add the following lines to ~/.bashrc
    source /opt/tinyos-2.1.1/
    export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.

After you finish the above steps, you get TinyOS-2.1.1 successfully on your host. However, when you go to  /opt/tinyos-2.1.1/apps/Blink to compile your first program

make telosb

you may get error like this:

mkdir -p build/telosb
compiling BlinkAppC to a telosb binary
ncc -o build/telosb/main.exe -Os -O -mdisable-hwmul -fnesc-separator=__ -Wall -Wshadow -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DDEFINED_TOS_AM_GROUP=0×22 -DIDENT_APPNAME=\”BlinkAppC\” -DIDENT_USERNAME=\”liruan\” -DIDENT_HOSTNAME=\”liruan-desktop\” -DIDENT_USERHASH=0x93f2e5efL -DIDENT_TIMESTAMP=0x4e98142bL -DIDENT_UIDHASH=0x40bf25adL -lm
In file included from /opt/tinyos-2.1.1/tos/platforms/telosa/,
from /opt/tinyos-2.1.1/tos/system/,
In component `HplMsp430GeneralIOC’:
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ syntax error before `;’
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P30′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P31′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P31′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P32′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P33′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P33′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P34′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P35′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P50′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P51′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P52′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P53′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P36′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P37′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P60′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P61′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P62′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P63′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P64′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P65′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P66′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P67′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P66′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P67′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P67′
/opt/tinyos-2.1.1/tos/chips/msp430/pins/ cannot find `P57′
In component `PlatformLedsC’:
/opt/tinyos-2.1.1/tos/platforms/telosa/ cannot find `Port54′
/opt/tinyos-2.1.1/tos/platforms/telosa/ cannot find `Port55′
/opt/tinyos-2.1.1/tos/platforms/telosa/ cannot find `Port56′
make: *** [exe0] Error 1

It is the problem of msp430 packages. The 2.1.1 is good to compile mica, but not telos. 
So, we have to remove msp430 packages and install the old packages.

remove msp430

sudo apt-get autoremove --purge msp430-tinyos

sudo apt-get autoremove --purge msp430-gcc-tinyos

download old packages from here:
double click them in the following order:

or you can use the following commands(all for 32 bits):

sudo dpkg -i msp430-tinyos-base_2.1-20080806_all.deb 
sudo dpkg -i msp430-binutils-tinyos_2.17-20080806_i386.deb
sudo dpkg -i msp430-gcc-tinyos_3.2.3-20080806_i386.deb
sudo dpkg -i msp430-libc-tinyos_20060801cvs-20080806_i386.deb 
sudo dpkg -i msp430-tinyos_2.1-20080806_all.deb
sudo dpkg -i msp430-optional-tinyos_2.1-20090326_all.deb

Now, you can compile the packages successfully.

Well, when you trying to move the program to the chips, you may run the following command:

make telosb reinstall bsl,DEVICE

where DEVICE is the USB Device path provided from motelist command. example: make telosb reinstall bsl,/dev/ttyUSB0
you may still get errors. mainly because of the permission to access the Device. what you can do is to add the user to the group tty

sudo gpasswd -a username tty

and then give the user the permission to access to the Device

sudo chmod 666 /dev/ttyUSB0

if your Device is ttyUSB0

Now you can find your program copy to the chip.