Tuesday, April 14, 2009

TinyOS: setting transmission power for telosb (cc2420 chips)

A homework asked us to localize a mobile mote using RSSI. In short range, the RSSI is inaccurate. To reduce the interference between motes, I reduced the transmission power of mobile mote. It worked very well. Only close neighbors received the signal from the mobile mote. Here is the mobile mote code.
------------------------------------
File: LowPowerSendAppC.nc

/*
* Setting Transmission Power for CC2420 Chips (Telosb, Micaz)
*
* Author: Anwar Mamat anwar at cse.unl.edu
* 04/01/2009
*/


enum {
AM_RSSIMSG = 10
};

typedef nx_struct RssiMsg{
nx_int16_t rssi;
} RssiMsg;

configuration LowPowerSendAppC{

}
implementation {
components ActiveMessageC, MainC;
components new AMSenderC(AM_RSSIMSG) as RssiMsgSender;
components new TimerMilliC() as SendTimer;
components CC2420ActiveMessageC;

components LowPowerSendC as App;


App.Boot -> MainC;
App.SendTimer -> SendTimer;

App.RssiMsgSend -> RssiMsgSender;
App.RadioControl -> ActiveMessageC;
App-> CC2420ActiveMessageC.CC2420Packet;
}

-------------------------------------
File: LowPowerSendC.nc

module LowPowerSendC{
uses interface Boot;
uses interface Timer as SendTimer;
uses interface AMSend as RssiMsgSend;
uses interface SplitControl as RadioControl;
uses interface CC2420Packet;

}
implementation{

message_t msg;
uint16_t SEND_INTERVAL_MS = 100;
uint8_t TRANS_POWER = 3;

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

event void RadioControl.startDone(error_t result){
call SendTimer.startPeriodic(SEND_INTERVAL_MS);
}

event void RadioControl.stopDone(error_t result){}


event void SendTimer.fired(){
call CC2420Packet.setPower(&msg, TRANS_POWER);
call RssiMsgSend.send(AM_BROADCAST_ADDR, &msg, sizeof(RssiMsg));
}

event void RssiMsgSend.sendDone(message_t *m, error_t error){}
}

--------------------------------
File: Makefile

COMPONENT=LowPowerSendAppC
include $(MAKERULES)

No comments: