Monday, March 25, 2019

Asterisk PBX common errors and Solution

Asterisk PBX common errors and Solution


1. Got this error during IAX2 communication, for Asterisk to Asterisk communication

[Mar 26 11:36:48] WARNING[4529][C-00000002]: /usr/src/asterisk-certified-13.21-cert3/include/asterisk/crypto.h:147 __stub__ast_aes_set_encrypt_key: AES encryption disabled. Install OpenSSL.
[Mar 26 11:36:48] WARNING[4529][C-00000002]: /usr/src/asterisk-certified-13.21-cert3/include/asterisk/crypto.h:159 __stub__ast_aes_set_decrypt_key: AES encryption disabled. Install OpenSSL.
[Mar 26 11:36:48] WARNING[4529][C-00000002]: /usr/src/asterisk-certified-13.21-cert3/include/asterisk/crypto.h:159 __stub__ast_aes_set_decrypt_key: AES encryption disabled. Install OpenSSL.
    -- Hungup 'IAX2/receiver-14602'


Solution:
  1. yum install openssl openssl-devel 
  2. Compile, make menuselect with Resource Module->res_crypto enabled and Install asterisk
  3. Load res_crypto module if not loaded by default (module load res_crypto)

Thursday, October 18, 2018

Installing PHP 7.2.11 in CentOS 7.4 with Pthreads enabled

Installing PHP 7.2.11 in CentOS 7.4 with pthreads enabled

This steps are meant for PHP CLI threading applications.  So web related appications are not installed along with.

OS Version: CentOS Linux release 7.4.1708 (Core)

First we need to install  PHP. Version used is php-7.2.11

1. Download php-7.2.11.tar.gz source from http://php.net/get/php-7.2.11.tar.gz/from/a/mirror
2. Extract to /usr/src
 
3. cd /usr/src/php-7.2.11
4. ./configure --with-config-file-path=/usr/local/lib --with-tsrm-pthreads --enable-pthreads=shared --enable-maintainer-zts --enable-sockets
5. make
6. make test
7. make install
8. To see the php version installed
     php -v

Now we need to install Pthreads. Source is taken from Github.

1. Download from https://github.com/krakjoe/pthreads.git
2. Extract to /usr/src/php-7.2.11/ext
3. This step may not be required, but this is how it got worked for me and i didnt tried the other way.      Rename the extracted file from pthreads-master to pthreads.
      mv /usr/src/php-7.2.11/ext/pthreads-master /usr/src/php-7.2.11/ext/pthreads
4. cd /usr/src/php-7.2.11/ext/pthreads
5. phpize
6. ./configure
7. make
8. make test
9. make install

Now we require to Rebuild our PHP installation

1. cd /usr/src/php-7.2.11
2. make clean
3. rm -f configure && ./buildconf --force
4. ./configure --with-config-file-path=/usr/local/lib --with-tsrm-pthreads --enable-pthreads=shared --enable-maintainer-zts --enable-sockets
5. make
6. make test
7. make install
   At end of make install note this path
    Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-zts-20170718/

Next is the important and final step, to edit the configuration file (php.ini)
1. Give command -> php --ini
   Output ->
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         (none)
    Scan for additional .ini files in: (none)
    Additional .ini files parsed:      (none)

2. Copy file from /usr/src/php-7.2.11 to /usr/local/lib and rename the file to php.ini
    cp /usr/src/php-7.2.11/php.ini-development /usr/local/lib/php.ini

3. Give command -> php --ini
   Output ->
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: (none)
    Additional .ini files parsed:      (none)

   Now the Configuration file is loaded

4. Add this line to /usr/local/lib/php.ini below
    extension=/usr/local/lib/php/extensions/no-debug-zts-20170718/pthreads.so



5. Shows the modules loaded
     php -m

    In the loaded modules you shoud be able to see the pthreads


Thursday, June 7, 2018

Steps for importing csv / text data to Postgres database table in Ubuntu / Linux

Steps for importing csv / text data to Postgres database table in Ubuntu / Linux


  • If the file is too big to process in one step, cut the file into multiple files
    • split -l 250000 filename.txt  // Will split the file into multiple files with 250000 lines
  • In case if all columns are not required to be imported, create a new file with required number of columns. Mind the delimiter used.
    • cut -d'|' -f1,3,6,33,34,35 file_name.txt >> out.txt
  • Next two lines are specific to my case
    • sed -e '/^[a-z,A_Z]/d' test.txt > test_1.txt  // To delete the lines which starts with a character.
    • sed -i '/^$/d' file.txt   //To delete empty lines
  • Copy the first line which is the column names to all the splitted file outputs, except the first file. Use "vim".
  • I used a python program to delete lines which contains number of columns not equal to three.
#Python Program
fh = open('test.txt')      # Open the Original file
f = open("test_2.txt","w") # Create a new file to store the output
for line in fh:
    countLine = line.count("|")
    if countLine == 2:
       f.write(line)
fh.close()
  • Create a table with requited columns. Better to give data type as character varying and size as larger than reqired for all columns (eg character varying (400))
  • Copy the formatted txt / csv to postgres table. Here delimiter used is '|'.
    • COPY table_name(phone_no,subscriber_name,address,pincode,place,district) FROM 'local_location/filename.txt' DELIMITER '|' CSV HEADER;
  • Possible Errors
    • Error telling some special characters present, so not able to copy.  /*  "UTF8": 0xbf   */
    • Here i have deleted the lines with that special characters. Go this website and figure out the special character.
    • https://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=0x       ¿
    • Using vim editor search for the special character in file and delete it manually.
  • After copying the file, do the required process in the table
    • --delete FROM table_name WHERE length(phone_no)!=10;
    • --delete FROM table_name WHERE length(phone_no)=0;
    • --delete FROM table_name WHERE phone_no is null
    • --delete FROM table_name WHERE length(subscriber_name)>95;
    • --delete FROM table_name WHERE length(address)>295;
  • Alter the column datatype to required one
    • ALTER TABLE table_name ALTER COLUMN phone_no TYPE bigint USING (phone_no::bigint);  //Column name is phone_no
  • Fill unfilled column in database table with value from another column, delemited value
    • update table_name set pincode = ( SELECT split_part(address, '!', 3));
  • Update Column by replacing occurance of a string
    • UPDATE SET = REPLACE ( , 'string1', 'string2' );

Steps for take postgres table dump and import to another Postgres database

  • Login as root user
    • sudo su
  • Login as postgres user
    • su - postgres
  • Take dump of the table to file named output.sql
    • pg_dump -p 5432 --column-inserts --data-only --table=table_name database_name > output.sql
  • Copy output.sql to postgres/data folder of the machine where it is to be ported.
  • Create table at destination with same table name and properties
  • Go inside the /postgres/data folder and give this command
    • psql -p 5444 -d database_name -f output.sql  
      • -p is for port number
      • -d for database name

Tuesday, September 1, 2015

Garmin GPS 18x USB with Ubuntu

1. Install GPS babel, driver for the garmin device
      sudo apt-get install gpsbabel

2. dmesg to the device is detected

3. lsusb

4. ls -l /dev/bus/usb/001/002

5. sudo adduser ubuntu lp

6. modprobe -r garmin_gps

7. gpsbabel -T -i garmin -f usb: -o kml -F xxx.kml

8. Give permission to normal user in Ubuntu for using GPSBabel

    sudo /etc/udev/rules.d/51-garmin.rules

    Enter this line and save file

   SYSFS{idVendor}=="091e", SYSFS{idProduct}=="0003", MODE="666"


GSM AF-007 Modem with Ubuntu 

1. apt-get install gammu

2. gammu-config

   a. set port to /dev/ttyUSB0
   b. Connection to at115200
   C. Save setting

3.gammu sendsms TEXT 09790847087 -text "Lati:15.76454 Longi:9.07564356" 

Monday, August 31, 2015

Install Ubuntu in Beaglebone Black and setup network with Ethernet connection


Installation of Ubuntu in BBB

1. Download prebuilt image of Ubuntu (*.img.xz) from http://elinux.org/BeagleBoardUbuntu#eMMC:_BeagleBone_Black

2. Extract the image

3. Write image to a microSD card using Win32DiskImager (Used Windows 7 Professional).

4. Insert the SD card into poweredoff beaglebone. Keep pressed the boot button and Power on the board (used 5 V adapter to Power ON).

5. Keep the boot button pressed till the indicator leds start blinking. Wait for about 10 to 15 min till all the indicator leds stays ON.

6. Power off the board, take out the SD card and power it on again with USB connected to your computer (Can remove the 5 V adapter now).

7. ssh to ubuntu@192.168.7.2 using terminal in linux or putty in windows. Password is "temppwd".

8. You are logged in to the Ubuntu OS in Beaglebone black.

Setup Network with Ethernet connection

The set up explained here is specific for my network, where  a static ip is set to the beagle board.

1. Connect power, usb and ethernet cable to BBB.

2. ssh to the board with 192.168.7.2 (for usb connection)
      ssh ubuntu@192.168.7.2
      password: temppwd

3.  Set static IP to the primary n/w interface, which is eth0.
       a. nano /etc/network/interface
       b. Add below lines in primary n/w interface part
             # The primary network interface
             auto eth0
             iface eth0 inet static
                address 10.184.36.6  // Contact system admin for ip informations.
                netmask 255.255.255.0
                gateway 10.184.36.1

4. Now logout of the terminal and ssh to the board with 10.184.36.6 (assigned static IP)
      ssh ubuntu@10.184.36.6
      password: temppwd

5. Assign name server (This step is needed to be done each time the BBB is rebooted, Or else do something to make this change permanent).
      a. nano /etc/resolv.conf
      b. Commend all lines and add below line
            nameserver 10.184.0.11 // Contact system admin for ip informations.

6. Update by giving below command and enjoy.
      sudo apt-get update

Friday, August 21, 2015

Linux useful commands and informations

1. In debian based OS apt-get install command will download the .deb package in the below folder before installation.

    /var/cache/apt/archives/

2. To format disk in commandline

      sudo cfdisk /dev/sdb

   One another option is

     sudo mkfs.ext4 /dev/sdb1

3. Find User ID (uid) of the current user in Linux system.

      id -u [USER_NAME]

      eg:  id -u root  (which will be 0).

4. Change ownership of a folder for specific user.

      chown -R [UID_OF_USER] [PATH_TO _FOLDER]

      eg: chown -R 1000 /opt/tinyos-2.x/

5. Find a file or directory in specific place.

      find [PATH_TO_SEARCH] -name [FILE_NAME]

      eg: find /opt -name tinyos.sh

6. Install grub due to some error in grub.

      grub-install --root-directory=/dev/sda

7. Write OS image (*.img) into USB/ microSD in linux (Ubuntu).
     Create bootable USB/ microSD from image file (.img)

      sudo dd if=./BBB*.img of=/dev/sdX

      sdX, here X denote where the device is mounted.

8. SSh connection failure due to the error "Host key verification failed."

     ssh-keygen -R



9. Find baud rate of a serial device through commanline

    sudo stty -F /dev/ttyUSB0    //replace ttyUSB0

Monday, June 1, 2015

PostgreSQL Useful commands


PostgreSQL Useful commands

  • To copy a table to create new one
    • CREATE TABLE table_name_2 ( like table_name_2 including all)
  • Insert columns from one table to another
    • insert into table_name (phone_no,subscriber_name,address,pincode,place,district) select phone_no,subscriber_name,address,pincode,place,district from tabele_2;
  • Insert column of one table from another table, where second table colum length is less than 95
    • insert into table_back 
    • (
    •   phone_no,subscriber_name,address,pincode,place,district
    • ) select phone_no,subscriber_name,address,pincode,place,district from table_2 where length (subscriber_name) > 95;
  • Delete complete content from table
    • DELETE FROM table_name;
  • Delete a column from table
    • DELETE FROM table_name WHERE phone_no = 7382613796;
  • Change table name
    • ALTER TABLE table_name RENAME TO TABLE_NAME_2;
  • Change column datatype
    • ALTER TABLE table_name ALTER COLUMN phone_no TYPE bigint USING (phone_no::bigint); 
      • phone_no is the column name.
  • Delete row when length of a column not equal to 10
    • delete FROM table_name WHERE length(phone_no)!=10;
  • Update column by its first n characters, if the character length is to be reduced
    • update test_1 set subscriber_name = left(subscriber_name,10);
  • To create new table from old table, sorted by systemtime
    • create table new_racktemp as select * from racktemp order by systemtime;
  • Alter/ Update existing table by inserting new column, setting it with primary key and insert the column with serial numbers starting from 1.
    • alter table new_racktemp add column slno bigserial primary key;
  • For creating sequence number and updating column with that (not tested)
    • CREATE SEQUENCE seq;
    • ALTER SEQUENCE seq RESTART WITH 1;
    • UPDATE racktemp SET slno=nextval('seq');
  • Dump and restore for command line
    • Go to "cmd"
    • Change directory to the Postgres Bin folder      
    • cd // cd C:\Program Files\PostgreSQL\9.3\bin
    • Use pg_dump to backup
      • pg_dump.exe -U postgres -t "table_name" "Data_base_name" > "Path&Name_Backup"
      • //pg_dump.exe -U postgres -t consotable hpc > C:\Users\CFD\Desktop\consot.backup
  • Use psql to restore to another database
    • psql.exe -U postgres "DB_name" < "Path for backup file"
    • //psql.exe -U postgres testdb < C:\Users\CFD\Desktop\consot.backup
  • Get values of the last updated row inreference to serial number
    • SELECT * from table_name order by slno desc limit 1

Monday, December 22, 2014

PCB Design with CADSTAR






Tuesday, November 18, 2014

PostgresQL Database connection with MATLAB

Configuration Steps

Steps:

1. Download and copy JDBC driver for Postgres version from this link
http://jdbc.postgresql.org/download.html

2. Follow this link to edit JDBC driver path to Matlab java class path.
http://in.mathworks.com/help/database/ug/postgresql-jdbc-windows.html

3. Follow above link to complete the connection.


Matlab Data Retrieval from PostgresQL 

1. Connect to database

DataBase =  database('hpc','postgres','postgres','Vendor','PostgreSQL')

2. Conver num to string for comparison

startdate= num2str('2014-11-02');
endddate=num2str('2014-11-08');

3. SQL query and execute the query

sqlquery = ['select temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8 from racktemp where nodeid = 7 and systemtime BETWEEN (''',startdate,''') and (''',endddate,''')'];
curs = exec(DataBase,sqlquery);

4. Fetch the data and store in an array

curs = fetch(curs);
Data = curs.Data;
Data(15,2)

5. Close connection

close(DataBase);

6. Use integer variable inside Postgres query in Matlab

are = 10
sqlquery = ['select loadavg1min from punecpuload where sno =' num2str(are)]

7. Use string variable inside Postgres query in Matlab

nodeL = num2str('r4-c1-n1');
sqlquery = ['select count(*) FROM consotabletemp where node_id =(''',nodeL,''')'];

Wednesday, July 4, 2012

Select the Channel for transmission in TinyOS, NesC

Here i have described how to change the channel for Zigbee transmission in TinyOS. Programs i have done are for TelosB mote and so the methods are applicable to the Zigbee CC2420 only. I believe for other motes the methods are more or less the same.

By default in TinyOS the channel used for CC2420 transmission is 26th channel, and it is defined in CC2420.h file. Here i have described about three methods for selecting the channel.

(1) Change the channel by Makefile

  Add this line in Makefile and enjoy.
CFLAGS += -DCC2420_DEF_CHANNEL=25
Where 25 is the required channel.

(2) Change the channel dynamically in NesC programming

  Use the command CC2420Config.setChannel() in interface "CC2420Config", which is provided by the component "CC2420ControlC". Sample program is given below.

Configuration
configuration ChannelAppC {
}

implementation {
  components ChannelC;
  components MainC;
  components LedsC;
  components new TimerMilliC() as Timer;
  components CC2420ControlC;  //Component for Channel selection

  ChannelC.Boot -> MainC;
  ChannelC.Led  -> LedsC.Leds;
  ChannelC.Timer -> Timer;

  components ActiveMessageC;
  components new AMSenderC(6);

  ChannelC.SplitControl -> ActiveMessageC;
  ChannelC.Packet    -> AMSenderC;
  ChannelC.AMPacket  -> AMSenderC;
  ChannelC.AMSend    -> AMSenderC;

  ChannelC.CC2420Config -> CC2420ControlC; //Wiring for Channel selection
}

Module
#include "printf.h"

module ChannelC {
  uses interface Boot;
  uses interface Leds as Led;
  uses interface Timer;

  uses interface SplitControl;
  uses interface Packet;
  uses interface AMPacket;
  uses interface AMSend; 
  uses interface CC2420Config;
}

implementation {

  enum {
    AM_SIZE = 6,
  };

  typedef nx_struct MessageDef {
    nx_uint16_t counter;
  } MessageDef;

  uint16_t counter = 0;
  bool busy = FALSE;
  message_t pkt;
  uint8_t len;
  uint8_t channel;
  
  event void Boot.booted() {
    call SplitControl.start();
  }

  event void SplitControl.startDone(error_t err) {
    call CC2420Config.setChannel(25);
    call CC2420Config.sync();
    call Timer.startPeriodic(500);
  }

  event void Timer.fired() {
    MessageDef* ptrpkt = (MessageDef*)(call Packet.getPayload(&pkt, len));
    counter++;
    call Led.led0Toggle();
    ptrpkt -> counter = counter;
    if (!busy) {
      if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(MessageDef)) == SUCCESS) busy = TRUE;
    }
  }

  event void AMSend.sendDone(message_t* msg, error_t error) {
    if (&pkt == msg) {
      busy = FALSE;
      call Led.led1Toggle();
      channel = call CC2420Config.getChannel();
      printf("Channel : %d\n", channel);
      printf("Counter = %d\n\n",counter);
      printfflush();
    }
  }
  
  event void SplitControl.stopDone(error_t err) {
  }
  event void CC2420Config.syncDone( error_t error ) {
  }
}

(3) Change the channel in the TinyOS source

By default CC2420 is using 26th channel for transmission and it is defined in CC2420.h header file in /opt/tinyos-2.x/tos/chips/cc2420/. So by editing that header file and recompiling the program will change the channel. Edit the below given line
#ifndef CC2420_DEF_CHANNEL
#define CC2420_DEF_CHANNEL 25
#endif
 Where 25 is the required channel.

Sunday, July 1, 2012

GIO Input and Output of TelosB

This program can be used as a reference for the usage of General Input Output pin(GIO) of TelosB. Here i a have used the GIO output of TelosB to connect a buzzer and trigger it in every 2 seconds, making it on and off.

General input/output pin details of TelosB is given below.

GIO No.
TeloB Pin out
MSP430 processor Pin out
Note
GIO-0
10 (10 pin connector)
20
Have to short R16 in TelosB
GIO-1
7 (10 pin connector)
21
Have to short R14 in TelosB
GIO-2
3 (6 pin connector)
23

GIO-3
4 (6 pin connector)
26


In my program i have used GIO3 and hence i have connected the positive of buzzer to 4th pin of 6 pin expansion connector and negative to Gnd of TelosB.


This is the configuration for the application.
configuration BuzzerAppC {
}

implementation{
   components BuzzerC, MainC;
   components HplMsp430GeneralIOC;
   components BusyWaitMicroC;
   components new TimerMilliC() as Timer;
   components LedsC;

   BuzzerC.Boot -> MainC.Boot;
   //BuzzerC.indication2 -> HplMsp430GeneralIOC.Port23; For input
   BuzzerC.indication3 -> HplMsp430GeneralIOC.Port26; 
   BuzzerC.Timer -> Timer;
   BuzzerC.delay -> BusyWaitMicroC;
   BuzzerC.Leds -> LedsC;
}

This is the module for the application.
module BuzzerC{
   uses interface Boot;
   uses interface HplMsp430GeneralIO as indication3;
   uses interface BusyWait as delay;
   uses interface Timer as Timer;
   uses interface Leds;
}

implementation{
  uint16_t value;
  uint16_t i;
  event void Boot.booted() {
    call Timer.startPeriodic(2000);
  }
  event void Timer.fired() {
    call Leds.led0Toggle();
    call indication3.makeOutput();
    call indication3.set();
    for (i=0;i<100;i++) {
      call delay.wait(10000);
    }
    call indication3.clr();
    for (i=0;i<100;i++) {
      call delay.wait(10000);
    }
  }  
}

Monday, June 11, 2012

Calculate execution time of code in TinyOS

Here i have used the interface "LocalTime" and component "LocalTimeMilliC" for calculating the execution time.

This is the Configuration for calculating the execution time. Here i have given a sample code and it is not complete in sense of a complete application.
configuration TMP102AppC {
}
implementation {
  components LocalTimeMilliC, TMP102C as App;
  App.LocalTime -> LocalTimeMilliC; 

 ---Other Configurations---
}

This is the module for the application.
#include "printf.h"

module TMP102C {
   uses interface LocalTime <tmilli>;
     ---Other Interfaces---
}

implementation {
uint32_t start_time;
uint32_t stop_time;

 ---Other Code---

start_time = call LocalTime.get();  // Put this line where you want to start count.
   
---Other Code---

 stop_time = call LocalTime.get();  // Put this line where you want to stop count.
 printf("Execution Time = %d\n",(stop_time-start_time));  //Print the execution time.
    
}

Thursday, May 31, 2012

Networking concepts


Hub, Repeater, Switch, Bridge, Router and Gateway

   Major differences between different networking devices are mentioned in this table.



Network Devices
OSI layer corresponds to the Device
Functions
Hub
Physical
Multiport repeater.
Any electrical signal that comes into one port, goes out of all other ports.
Does not examine or manage traffic.
Repeater
Physical
Regenerates the signal.
Connects two segments of a network cable.
Extends physical length of network.
Is a re-generator not an amplifier.
Active hubs.
Switch
Data link
Connects n/w segments or n/w devices.
Is a multipoint network bridge(bridge with numerous o/p ports).
Process and routes data to the intended receiver.
Intelligent than hub.
Multilayer switch works on Data link and Network layer.
Reduces traffic and divide the collision domain into segments.
Uses MAC address for communication.
Bridge
Data link
A combination of hardware and software to link two similar networks.
Divides a large network to smaller segments.
Very much alike switch.
Does data filtering and separating the collision domain like switch.
Slower compared to switch since it uses s/w for switching.
Controls congestion and isolation.
Uses MAC address for communication.
Router
Network
Route data packets between different networks of same type.
Can connect networks with different architecture like Token Ring and Ethernet.
Cannot connect networks of different protocols like TCP/IP and IPX/SPX.
Controls both collision domains and broadcast domains.
Uses IP address for communication.
Ability to identify best route for the packet to travel using a routing table.
Gateway
Application, Network, Session
Interconnects networks with different network protocol technologies by performing the required protocol conversions.
Very intelligent device
Works at network layer and above, but mostly work at application layer.
Mostly it is a software installed in router.

Tuesday, May 29, 2012

Multiple sensors interfacing to Telosb through I2C connection

   Here i have interfaced two sensors, accelerometer and temperature sensor with Telosb mote using parallel I2C connection. Zigbee part is also integrated with the program.

Connection

TMP102 GND   -> TELOSB 9 pin (GND)
TMP102 VCC    -> TELOSB 1 pin (VCC)
TMP102 SDA    -> TELOSB 8 pin (SDA)
TMP102 SCL    -> TELOSB 6 pin (SCL)
TMP102 ADD0 -> TELOSB 9 pin (GND)
TMP102 ALT    -> Left unconnected

ADXL345 GND -> TELOSB 9 pin (GND)
ADXL345 VCC  -> TELOSB 1 pin (VCC)
ADXL345 CS     -> TELOSB 1 pin (VCC)
ADXL345 SDA  -> TELOSB 8 pin (SDA)
ADXL345 SCL  -> TELOSB 6 pin  (SCL)
ADXL345 SDO  -> TELOSB 9 pin (GND)


The circuit i created for interfacing the sensors with Telosb is given below. I have used an intermediate interfacing board for connection.





Program

   Transmitter Program

      Programming is done with Nesc in TinyOS. Four main files are here I2CAPPC.nc, , I2CC.nc, I2CRadio.h and Makefile.


I2CAPPC.nc
#include "I2CRadio.h"

configuration I2CAppC{
}

implementation {
   components MainC, I2CC as App;
   App.Boot -> MainC;

   components LedsC;
   App.Leds -> LedsC;

   components new TimerMilliC() as I2CTimer;
   App.I2CTimer -> I2CTimer;

   components new ADXL345C();
   App.axis -> ADXL345C.XYZ;
   App.AccelControl -> ADXL345C.SplitControl;

   components new SimpleTMP102C();
   App.Temp -> SimpleTMP102C.Read;

   components new AMSenderC(AM_I2C);
   App.Packet -> AMSenderC;
   App.AMPacket -> AMSenderC;
   App.AMSend -> AMSenderC;

   components ActiveMessageC;
   App.AMControl -> ActiveMessageC.SplitControl;

   components new AMReceiverC(AM_I2C);
   App.Receive -> AMReceiverC;
}

I2CAPPC.nc
#include "printf.h"
#include "ADXL345.h"
module I2CC {
   uses {
      interface Boot;
      interface Leds;
      interface Timer as I2CTimer;
      interface Read as axis;
      interface SplitControl as AccelControl;
      interface Read as Temp;

      interface Packet;
      interface AMPacket;
      interface AMSend;
      interface SplitControl as AMControl;

      interface Receive;
   }
}

implementation {

   bool busy = FALSE;
   message_t pkt;
   uint16_t counter = 0;

   nx_uint16_t X;
   nx_uint16_t Y;
   nx_uint16_t Z;
   nx_uint16_t Tem;

   event void Boot.booted() {
      call AccelControl.start();
   }

   event void AccelControl.startDone(error_t err) {
      printf("\n\n------Accelerometer started-----\n\n");
      call I2CTimer.startPeriodic(1000);
   }

   event void AccelControl.stopDone(error_t err) {
   }

   event void I2CTimer.fired() {
      counter++;
      call Leds.led0Toggle();
      call axis.read();
   }

   event void axis.readDone(error_t result, adxl345_readxyt_t data) {
      if (result == SUCCESS) {
         X = data.x_axis;
         Y = data.y_axis;
         Z = data.z_axis;
         printf("\nX [%d] Y [%d] Z [%d]\n",X,Y,Z);
         call Temp.read();
      }
      else printf("Error in reading Accelerometer sensor\n");
   }

   event void Temp.readDone(error_t err, uint16_t temp) {
      if (err == SUCCESS) {
         call Leds.led1Toggle();
         temp=temp*6.25;
Tem=temp;
         printf("Temperature = %d.%d\n\n",temp/100, temp%100);
         printfflush();
         call AMControl.start();
      }
      //***************AM Part********************
      else printf("Error in reading Temperature sensor\n");
   }
   
   event void AMControl.startDone(error_t res) {
      if (res == SUCCESS) {
 //        printf("****AM STARTED****\n");
         if (!busy) {
            I2CRadioMsg* i2cpkt=(I2CRadioMsg*)(call Packet.getPayload(&pkt,sizeof(I2CRadioMsg)));
            i2cpkt -> counter = counter;
            i2cpkt -> xaxis = X;
            i2cpkt -> yaxis = Y;
            i2cpkt -> zaxis = Z;
            i2cpkt -> temp = Tem;
            if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(I2CRadioMsg)) == SUCCESS) {
               busy = TRUE;
               call Leds.led2Toggle();
            }
         }
      }
      else {
         call AMControl.start();
      }
   }

   event void AMControl.stopDone(error_t error) {
   }

   event void AMSend.sendDone(message_t* msg, error_t error) {
      if (&pkt == msg) busy=FALSE;
      call AMControl.stop();
   }

   event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
   }
}

I2CRadio.h
#ifndef I2CRADIO_H
#define I2CRADIO_H

typedef nx_struct I2CRadioMsg {
   nx_uint16_t counter;
   nx_uint16_t xaxis;
   nx_uint16_t yaxis;
   nx_uint16_t zaxis;  
   nx_uint16_t temp;  
}I2CRadioMsg;

enum {
   AM_I2C = 7,
};
#endif

Makefile
COMPONENT=I2CAppC
CFLAGS += -I$(TOSDIR)/lib/printf
CFLAGS += -I$(TOSDIR)/chips/adxl345
CFLAGS += -I$(TOSDIR)/chips/tmp102

include $(MAKERULES) 

Monday, April 30, 2012

TMP102 temperature sensor integration with TelosB mote

Here is a very simple NesC code for getting temperature value from TMP102 digital Temperature sensor with Telosb mote.

Connection
 
TMP102 GND   -> TELOSB 9 pin
TMP102 VCC    -> TELOSB 1 pin
TMP102 ADD0  -> TELOSB 9 pin
TMP102 SDA    -> TELOSB 8 pin 
TMP102 SCL    -> TELOSB 6 pin  

Apart from this connect pull-up resistor(10 KOhm) from SDA &SCL to VCC.

Program

Program has  three main files Accelerometer345AppC.nc, Accelerometer345C.nc and Makefile.

TMP102AppC.nc
configuration TMP102AppC {
}

implementation {
  components MainC, TMP102C as App;
  App.Boot -> MainC;

  components LedsC;
  App.Leds -> LedsC;
  
  components new TimerMilliC() as TimerTemp;
  App.TimerTemp -> TimerTemp;

  components new SimpleTMP102C();
  App.Temp -> SimpleTMP102C.Read;
}

TMP102C.nc
#include "printf.h"

module TMP102C {
  uses {
    interface Boot;
    interface Leds;
    interface Timer as TimerTemp;
    interface Read as Temp;
  }
}

implementation {

  event void Boot.booted() {
    printf("Temperature sensor starting..\n\n");
    call TimerTemp.startPeriodic(1000);
  }

  event void TimerTemp.fired() {
    call Leds.led0On();
    call Temp.read();
  }  

  event void Temp.readDone(error_t result, uint16_t temp) {
    temp=temp*0.0625;
    if (result == SUCCESS) printf("Temperature = %d \n", temp);
    else printf("Error..\n");
    printfflush();
    call Leds.led0Off();
  }
}

Makefile
COMPONENT=TMP102AppC
CFLAGS += -I$(TOSDIR)/lib/printf
CFLAGS += -I$(TOSDIR)/chips/tmp102

include $(MAKERULES)



Files SimpleTMP102C and SimpleTMP102P can be downloaded from TinyOS trunk or use these files given below.

SimpleTMP102C
generic configuration SimpleTMP102C() {
  provides interface Read;
}
implementation {
  components SimpleTMP102P;
  Read = SimpleTMP102P;

  components new TimerMilliC() as TimerSensor;
  SimpleTMP102P.TimerSensor -> TimerSensor;

  components new TimerMilliC() as TimerFail;
  SimpleTMP102P.TimerFail -> TimerFail;

  components new Msp430I2CC();
  SimpleTMP102P.Resource -> Msp430I2CC;
  SimpleTMP102P.ResourceRequested -> Msp430I2CC;
  SimpleTMP102P.I2CBasicAddr -> Msp430I2CC;     
}

SimpleTMP102C 
#include "TMP102.h"

module SimpleTMP102P {
   provides interface Read;
   uses {
    interface Timer as TimerSensor;
    interface Timer as TimerFail;
    interface Resource;
    interface ResourceRequested;
    interface I2CPacket as I2CBasicAddr;        
  }
}

implementation {
  
  uint16_t temp;
  uint8_t pointer;
  uint8_t temperaturebuff[2];
  uint16_t tmpaddr;
  
  norace uint8_t tempcmd;
    
  task void calculateTemp(){
    uint16_t tmp = temp;
    signal Read.readDone(SUCCESS, tmp);
  }
  
  command error_t Read.read(){
 call TimerSensor.startOneShot(100);
 return SUCCESS;
  }

  event void TimerSensor.fired() {
 call Resource.request();  
  }
  
  event void TimerFail.fired() {
   signal Read.readDone(SUCCESS, 0);
  }

  event void Resource.granted(){
    error_t error;
    pointer = TMP102_TEMPREG;
    tempcmd = TMP_READ_TMP;
    error= call I2CBasicAddr.write((I2C_START | I2C_STOP), TMP102_ADDRESS, 1, &pointer); 
    if(error){
      call Resource.release();
      signal Read.readDone(error, 0);
    }
  }
  
  async event void I2CBasicAddr.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t *data){
    if(call Resource.isOwner()) {
 uint16_t tmp;
 for(tmp=0;tmp<0xffff;tmp++); //delay
 call Resource.release();
        printf("\nMSB = %d  ",data[0]);
        printf("LSB = %d\n",data[1]);
 tmp = data[0];
 tmp = tmp << 8;
 tmp = tmp + data[1];
 tmp = tmp >> 4;
 atomic temp = tmp;
 post calculateTemp();
 }
  }

  async event void I2CBasicAddr.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t *data){
    if(call Resource.isOwner()){
      error_t e;
      e = call I2CBasicAddr.read((I2C_START | I2C_STOP),  TMP102_ADDRESS, 2, temperaturebuff);
      if(e){
        call Resource.release();
        signal Read.readDone(error, 0);
       }
     }
  }   
  
  async event void ResourceRequested.requested(){ }
  async event void ResourceRequested.immediateRequested(){ }   
  
}

TMP102.h
#ifndef TMP102_H
#define TMP102_H
#define TMP102_ADDRESS          0x48
#define TMP102_TEMPREG          0x00
#define TMP102_CONFREG          0x01
#define TMP_READ_TMP    1

#endif

Thursday, April 19, 2012

ADXL345 accelerometer integration with TelosB mote

Here is a very simple NesC code for getting X, Y and Z axis value from ADXL345 digital accelerometer with Telosb mote.

Connection
 
ADXL345 GND -> TELOSB 9 pin
ADXL345 VCC  -> TELOSB 1 pin
ADXL345 CS     -> TELOSB 1 pin
ADXL345 SDA  -> TELOSB 8 pin 
ADXL345 SCL  -> TELOSB 6 pin  

Apart from this connect pull-up resistor(10 KOhm) from SDA &SCL to VCC.

Program

Program has  three main files Accelerometer345AppC.nc, Accelerometer345C.nc and Makefile.

Acclerometer345AppC.nc
configuration Accelerometer345AppC {
}

implementation {
  components MainC, Accelerometer345C as App;
  App.Boot -> MainC;
  
  components LedsC;
  App.Leds -> LedsC;

  components new TimerMilliC() as TimerAccel;
  App.TimerAccel -> TimerAccel;

  components new ADXL345C();
  App.Xaxis -> ADXL345C.X;
  App.Yaxis -> ADXL345C.Y;
  App.Zaxis -> ADXL345C.Z;
  App.AccelControl -> ADXL345C.SplitControl;
}

Accelerometer345C.nc
#include "printf.h"

module Accelerometer345C {
  uses {
    interface Boot;
    interface Leds;
    interface Timer<TMilli> as TimerAccel;
    interface Read<uint16_t> as Xaxis;
    interface Read<uint16_t> as Yaxis;
    interface Read<uint16_t> as Zaxis;
    interface SplitControl as AccelControl;
  }
}

implementation {
  event void Boot.booted() {
    call AccelControl.start();
  }

  event void AccelControl.startDone(error_t err) {
    printf("\n\n-----Accelerometer Started-----\n\n");
    call TimerAccel.startPeriodic(1000);
  }

  event void AccelControl.stopDone(error_t err) {
  }

  event void TimerAccel.fired() {
    call Leds.led0Toggle();
    call Xaxis.read();   
  }

  event void Xaxis.readDone(error_t result, uint16_t data) {
    printf("X [%d]  ",data);
    call Yaxis.read();
  }

  event void Yaxis.readDone(error_t result, uint16_t data) {
    printf("Y [%d]  ",data);
    call Zaxis.read();
  }
  event void Zaxis.readDone(error_t result, uint16_t data) {
    printf("Z [%d]\n\n",data);
    printfflush();
  }
} 

Makefile
COMPONENT=Accelerometer345AppC
CFLAGS += -I$(TOSDIR)/lib/printf
CFLAGS += -I$(TOSDIR)/chips/adxl345

include $(MAKERULES) 

Monday, March 26, 2012

Certain Simple C Concepts

C Preprocessor Directives


    C Preprocessor is a separate program invoked by the compiler as first part of the compilation. It includes the directives for source file inclusion (ie #include), macro definition (#define) and conditional inclusion (ie #if).

    Preprocessor directives starts with a "#" sign, and that statement will be executed prior to the actual compilation of the code.

  (1) Source code inclusion

    #include Directive
      Preprocessor will replace the #include directive by entire content of the specified file.
     If the file name is enclosed in angle brackets, compiler will search the file in standard directories where it is configured to search.
 #include < stdio.h> 
     If the file name is enclosed in single quotes, compiler will search the file first in current directory and then if not found search in standard directories.
 #include "Timer.h" 
     Inorder to search in directories other than standard directories, use -I flag in the Makefile.
 CFLAGS += -I$(TOSDIR)/lib/printf

  (2) Macro definition 


    "#define" Directive

       #define Directive Defines the processor to replace all subsequent occurrence of a macro with a specific token.
 #define ADXL345_DEVID 0x00 
     The above example causes the preprocessor to replace the subsequent occurrence of the identifier "ADXL345_DEVID" with constant hex value 0x00.

     "#undef"Directive
        Defines macros are not affected by the block structure of C. A macro once defined will last until a "#undef" directive for that particular token. After undefining you can again redefine that token.
 #define ADXL345_DEVID 0x00 
 #undef ADXL345_DEVID 
 #define ADXL345_DEVID 0x01 

  (3) Conditional Inclusions

         Allows to include or discard certain code based on some conditions.

       #ifdef
 #ifdef NUM
 int amount [NUM];
 #endif
        Here the middle line will be compiled only if the NUM variable is already defined with #define.

        #ifndef
 #ifndef NUM
 #define NUM 46
 int amount [NUM];
 #endif
        Here the NUM variable will be defined only if it is not previously defined.

       #if, #else, #elif
 #if NUM>100
 #undef NUM
 #define NUM 100
 
 #elif NUM<50
 #undef NUM
 #define NUM 50

 #else
 #undef NUM
 #define NUM 200
 #endif 
       Here depending on certain condition the code is compiled.

Race condition

   Usually occurs in threaded programs. When two or more threads try to access same resource and change its value at same time, race condition occurs. Inorder to avoid this condition put a lock around the variable before using.

Printing in C


     To print the remainder

Use % for printing remainder of a division operation.
printf("%d",564%10);

rvalue Vs lvalue


   rvalue: rvalue of a variable is the value stored in that variable.
   lvalue: lvalue of a variable is the value of its address (where it is stored).
j=6;
k=j;

   Here in first line 'j' is at the left side of the equation and it denotes the address to which value 6 is to be copied. In the second line 'j' is at the right side of the equation and it denotes the value stored in 'j' to be copied to the address denoted by 'k'.

Function Pointer

   Declaring function pointer


      "ptFunction" is the function pointer declared and initialized to Null value.
int (*pt2Function)(float, char, char) = NULL; 

   Defining function pointer


      "ptFunction" is initialized to "DoIt" function whose definition is given below
ptFunction = DoIt;        // short form
ptFunction = &DoIt;   // correct assignment using address operator

void DoIt(float a, char b, char c) { }

   Comparing function pointer 


      This checks whether the  "ptFunction" is defined or not.
if(ptFunction >0) { }

   Calling function using function pointer 


       Both the methods will work.
int result1 = ptFunction(12, 'a', 'b'); 
int result2 = (*ptFunction) (12, 'a', 'b');

   Pass function pointer as argument 


       Both the function call and the function definition are given below.
PassPtr(&DoIt);  //Call the function

void PassPtr(int (*pt2Func)(float, char, char)) { } // Definition for the called function

Enumerations (enum)


   It is a set of named integer constants. Is defined like structures.

   Enum definition


enum coin {penny, dollar, paisa=15, dime, quater}

   Each of the enum symbol stands for an integer value starting from 0.

   Printing the values

printf("%d %d %d %d %d\n",penny,dollar,paisa,dime,quater);
   Here penny=0, dollar=1, paisa=15, dime=16 and quater=17.

   Declare variable


enum coin money;
   "money" is an object of type coin. 

   Initialize the variable

money = paisa;
   "money" is initialized to value "paisa". Printing money will print value 15.

Tuesday, March 20, 2012

NesC programming concepts.

Components


   Two kinds of components.

1. Singletons components

    Only one instant can exist. Renaming not possible.
configuration MainC {
}//  Singletons components module
components MainC; //Instantiating a Singletons component.

2. Generic components

    Can have multiple instants.
generic configuration TimerMilliC() {

 }   //  Generic components module

 //Instantiating a Generic component and renaming it.
 components new TimerMilliC() as TimerAccel;

 //Instantiating a Generic component without renaming.
 components new TimerMilliC(); 

Data types


uint8_t  :   Unsigned 8 bit integer.
uint16_t  :   Unsigned 16 bit integer.
uint32_t  :   Unsigned 32 bit integer.
uint8_t var1 =250;
printf("Value1 = %u", var1);
 
uint16_t var2 =65000;
printf("Value2 = %u", var2);

uint32_t var3 =4294960000;
printf("Value3 = %lu", var3);
 

Printf


   In NesC "printf" library will provides the terminal printing functionality for motes connected to PC through serial interface.

For using printf() in your NesC program:
  1. Include "printf.h" header in the component where it is being used.
#include "printf.h"

  2. Give path for the printf library in Makefile.
        CFLAGS += -I$(TOSDIR)/lib/printf   where $TOSDIR=/opt/tinyos-2.x/tos
COMPONENT=PrintfAppC
CFLAGS += -I$(TOSDIR)/lib/printf
include $(MAKERULES) 

 3. For explicit flushing of the printf output use the function printfflush().
printfflush(); 

  4. Default buffer size for the printf is 250 bytes as defined in the printf.h library in /opt/tinyos-2.x/tos/lib/printf/2_0_2/. For changing the buffer size edit the Makefile.
CFLAGS += -DPRINTF_BUFFER_SIZE={NEW_SIZE} 

Adding libraries or drivers in "Makefile" 


1. For adding libraries or drivers into your NesC program, add this line in your Makefile.
 CFLAGS += -I${PATH_OF_LIBRARY} 

2. If you want to add more than one library files, this line can be used repeatedly.
COMPONENT=PrintfAppC
CFLAGS += -I$(TOSDIR)/lib/printf
CFLAGS += -I$(TOSDIR)/chips/adxl345
include $(MAKERULES)

Commands and Events


   In NesC communication between two components are possible by using the interfaces. An interface will be provided by the provider component and used by the used component.
The user component make use of an interface provided by provider component, by making request (calls commands) to provider component. The provider component will make callbacks (signals events) as response to the user component.

  Commands
    Set of functions to be defined and implemented by interface's provider.
 return call Timer.startPeriodic(1000); //Call for the function Timer to start.
  Events
    Set of functions to be defined by interface's provider and implemented by interface's user.
 event result_t Timer.fired() {
} // Event is signaled once the Timer is fired 

"SplitControl" Interface


   This interface is used for switching between ON and OFF power states of the component providing it. If the command returns SUCCESS then corresponding startDone() or stopDone() event must be signalled.

SplitControl is similar to StdControl. StdControl is single-phase with only commands, while SplitControl is split-phase with commands and command completion events.

    Commands
 command error_t start()  // Start this component and all its subcomponents.
 command error_t stop()  //  Start this component and all its subcomponents. 
    Events
 event void startDone(error_t error) // Notify caller that component is 
  started and ready to receive other commands.
 event void stopDone(error_t error) // Notify caller that component has
  been stopped.

Task


   Task is a light weight procedure call. It can be posted at any time and posted task are executed later, one at a time by the TinyOS scheduler. A Task has following features.
    Has return value of void
    Takes no parameters
    Declared with task keyword.
    Task can be called by post operator.
    Posting task will always return success unless the task is pending.

Task declaration
 task void sendEvent1(); 
Task definition
 task void sendEvent1() {
 } 
Post a task
post sendEvent1();

Platform independent Data types


   Tinyos introduces platform independent data format that can be easily accessed and used. Usage of nx_ prefix or nxle_prefix on keywords such as struct and uint16_t or unint32_t means that they are external types, which have same representation on all hardware platforms.
typedef nx_struct BlinkToRadio{
   nx_uint16_t nodeid;            // Big endian 16 bit value
   nxle_uint8_t length;            // Little endian 8 bit value
}

Thursday, March 15, 2012

Manual Installation of Tiny OS in Ubuntu 11.10 from RPM


 The procedure given is for setting up Tiny OS 2.x in Ubuntu 11.10.

  I had followed the TinyOS wiki page and these are the exact steps i followed for Tiny OS installation for my TelosB mote which is using TIMSP430 processor.

After the installation, i dealt  with an error while compiling the TestSerial application for serial communication. It seems the issue is due to the Ubuntu 11.10 version OS.

1. Install Java

    (1) Install "python-software-properties" package.
apt-get install python-software-properties 
    (2) Add proper Repo for Java package.
           Log out from the current terminal and open a new one.
add-apt-repository ppa:ferramroberto/java 
    (3) Update your local package index.
 apt-get update 
    (4) Now install java packages.
 apt-get install sun-java6-jdk sun-java6-plugin 

2. Install  "rpm" package for installing RPM packages in Ubuntu.
 apt-get install rpm 

3. Install compilers for TIMSP430

      (1) Download msp430tools-base from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-base-0.1-20050607.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-base-0.1-20050607.i386.rpm 
      (2) Download msp430tools-python-tools from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-python-tools-1.0-1.noarch.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-python-tools-1.0-1.noarch.rpm 
      (3) Download msp430tools-binutils from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-binutils-2.16-20050607.i386.rpm
      Install it using this command.
rpm -Uvh --force --nodeps msp430tools-binutils-2.16-20050607.i386.rpm 
      (4) Download msp430tools-gcc from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-gcc-3.2.3-20050607.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-gcc-3.2.3-20050607.i386.rpm 
      (5) Download msp430tools-libc from here.
        http://www.tinyos.net/dist-2.1.0/tools/linux/msp430tools-libc-20080808-1.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-libc-20080808-1.i386.rpm 
      (6) Downloadmsp430tools-jtag-lib from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-jtag-lib-20031101cvs-20050610.i386.rpm
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-jtag-lib-20031101cvs-20050610.i386.rpm 
      (7) Download msp430tools-gdb from here.
        http://www.tinyos.net/dist-2.0.0/tools/linux/msp430tools-gdb-6.0-20050609.i386.rpm   
      Install it using this command.
 rpm -Uvh --force --nodeps msp430tools-gdb-6.0-20050609.i386.rpm 

4. Install TinyOS toolchain.

      (1) Download nesc from here.
        http://tinyos.stanford.edu/tinyos-rpms/nesc-1.3.1-1.fc9.i386.rpm
      Install it using this command.
 rpm -Uvh --ignoreos --nodeps nesc-1.3.1-1.fc9.i386.rpm 
      (2) Download tinyos-deputy from here.
        http://www.tinyos.net/dist-2.1.0/tinyos/linux/tinyos-deputy-1.1-1.fc9.i386.rpm
      Install it using this command.
 rpm -Uvh --ignoreos --nodeps tinyos-deputy-1.1-1.fc9.i386.rpm 
      (3) Download tinyos-tools from here.
        http://tinyos.stanford.edu/tinyos-rpms/tinyos-tools-1.4.0-3.ubuntu.i386.rpm          Install it using this command.
rpm -Uvh --ignoreos --nodeps tinyos-tools-1.4.0-3.ubuntu.i386.rpm 

5. Install TinyOS 2.x source tree.

      (1) Download tinyos source from here.
        http://tinyos.stanford.edu/tinyos-rpms/tinyos-2.1.1-3.ubuntu.noarch.rpm
      Install it using this command.
 rpm -Uvh --ignoreos --nodeps tinyos-2.1.1-3.ubuntu.noarch.rpm 

6. Add path.

      (1) Open bashrc file.
 vim ~/.bashrc 
      (2) Add the following lines to end of the bashrc file.
export TOSROOT=/opt/tinyos-2.x
export TOSDIR=$TOSROOT/tos
export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.
export MAKERULES=$TOSROOT/support/make/Makerules
export PATH=/opt/msp430/bin:/opt/jflashmm:$PATH 

7. Graphviz installation.

       (1) You can download graphviz and its dependency libgraphviz from this location.
         http://www.graphviz.org/Download_linux_ubuntu.php
       (3) liblasi0 is a dependency which i installed from ubuntu repo for graphviz.
 apt-get install liblasi0 
       (2) Install graphviz and its dependency.
 dpkg -i libgraphviz4_2.28.0-1_i386.deb

dpkg -i graphviz_2.28.0-1_i386.deb 
      

Errors

(1) Error while compiling the TestSerial application for serial communication.
/apps/tests/TestSerial# make telosb

mkdir -p build/telosb
mig java -target=null -I/opt/tinyos-2.x/tos/lib/T2Hack
-DIDENT_APPNAME=\"TestSerialAppC\" -DIDENT_USERNAME=\"root\"
-DIDENT_HOSTNAME=\"ubuntu\" -DIDENT_USERHASH=0xa3473ba6L
-DIDENT_TIMESTAMP=0x4f634feeL -DIDENT_UIDHASH=0x185584f2L -java-
classname=TestSerialMsg TestSerial.h test_serial_msg -o TestSerialMsg.java
two source files specified (PLATFORM_NULL and IDENT_APPNAME="TestSerialAppC")
failed to parse message file TestSerial.h

make: *** [TestSerialMsg.java] Error 1 

Solution:

  Couldn't solve the issue. It seems  the issue is with the ubuntu version 11.10. I solved the issue by switching back to Ubuntu 10.04 LTS version.

(2) Error with the java files.
        java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb

Exception in thread "main" java.lang.NoClassDefFoundError: net/tinyos/tools/Listen

Caused by: java.lang.ClassNotFoundException: net.tinyos.tools.Listen
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: net.tinyos.tools.Listen.  Program will exit.

Solution:

  1. Download of whole "java" as tarball from Tiny OS CVS repository.
      http://tinyos.cvs.sourceforge.net/viewvc/tinyos/tinyos-2.x/support/sdk/java/
  2. Replace the "java" file from /opt/tinyos-2.x/support/sdk/ with the extracted java file, from the downloaded tarball file.
  3. Go inside the java folder in terminal and give "make" command.
  4. Enjoy.

(3) Error in installing rpm packages.
rpm -Uvh --force --nodeps msp430tools-base-0.1-20050607.i386.rpm

rpm: please use alien to install rpm packages on Debian, if you are really sure use --force-debian switch. See README.Debian for more details.

Solution:
  Use this command instead.
rpm -Uvh --force-debian --nodeps msp430tools-base-0.1-20050607.i386.rpm


(3) Error in "make "
make telosb
make: *** No rule to make target `telosb'.  Stop.

Solution:

This is because you have done the installation as root user and trying to "make" as a different user.
Solve this by doing "make" as root user or give proper permission for that particular user.
sudo chown prasanth:prasanth -R /opt/tinyos-2.x/

Monday, March 12, 2012

Data Transmission message sequence Chart – Recipient


  1. MLME-RX-ENABLE.request (TRUE or FALSE (Receiver enable for this superfra or until next), 0 x 000000–0 x ffffff (RxOnTime ), 0 x 000000–0 x ffffff (RxOnDuration ) )
        → Higher to MAC
  1.  PLME-SET-TRX-STATE.request (RX_ON)
        → MAC to PHY
  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

Note: Receives data.

  1. PD-DATA.indication ( psduLength(<=127, msdu length) psdu(set of octets), 0 x 00 to 0x ff(ppduLinkQuality) )  
        → PHY to MAC
  1. MCPS-DATA.indication (0 x 00–0 x 03(SrcAddrMode ), 0 x 000–0 x ffff (SrcPANId ) SrcAddr (As specified by the SrcAddrMode ) 0 x 00–0 x 03 (DstAddrMode ) 0 x 0000–0 x ffff (DstPANId ) DstAddr(As specified by the DstAddrMode )msduLength, msdu, 0 x 00–0 x ff (mpduLinkQuality), TRUE or FALSE (Security), 0 x 00–0 x 08 (ACL entry) )
          → MAC to Higher level.

  1. PLME-SET-TRX-STATE.request (TX_ON)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC

  1. PD-DATA.request ( psduLength((<=127, msdu length)), psdu(set of octets) )
        → MAC to PHY

Note: Sent Acknowledgment.

  1. PD-DATA.confirm (SUCCESS)
        → PHY to MAC

  1. PLME-SET-TRX-STATE.request (TRX_OFF)
        → MAC to PHY

  1. PLME-SET-TRX-STATE.confirm (SUCCESS)
        → PHY to MAC