Hi!
I needed to monitor the RSSI values to detemine the noise level for mica2 as
part of my thesis. Browsing through postings gave me only a vague idea. Having
thus, I used the OscilloscopeRF app and the TOSBase apps to obtain those values
with modifications to each of them.
What I have basically done is to attach those values to an incoming
oscilloscopeRF data packet at the base mote and have another app (a Labview vi
specifically) read them.
1.) Increased the length of the data field in the OscopeMsg.h to 12 instead of
the default 10 to accomodate the 16 bit RSSI and the 16 bit battery voltage
that is required to calculate rssi in dBm.
enum {
BUFFER_SIZE = 10
};
struct OscopeMsg
{
uint16_t sourceMoteID;
uint16_t lastSampleNumber;
uint16_t channel;
uint16_t data[12/*BUFFER_SIZE*/];
/*************************************** Changed to accomodate RSSI and Voltage
***************************************/
}; /**************** Remember to
change the size of TOSH_DATA_LENGTH in tos/types/AM.h to 2*12 +9 or more to
//////////////////////////////////////////////////////////////////////////////////////////////////////////////accomodate
the increased packet length */
struct OscopeResetMsg
{
/* Empty payload! */
};
enum {
AM_OSCOPEMSG = 10,
AM_OSCOPERESETMSG = 32
};
2.) Changed size of TOSH_DATA_LENGTH in tos/types/AM.h from 29 to 2*12 +9 = 33
or more. to accomodate the increased data field.
3.)Modified TOSBaseM.nc to inject the rssi and battery voltage values. Voltage
values are from VoltageC.nc module and gives the battery voltage in milli volts.
configuration TOSBase {
}
implementation {
components Main, TOSBaseM, RadioCRCPacket as Comm, FramerM, UART, LedsC,
VoltageC;
Main.StdControl -> TOSBaseM;
TOSBaseM.UARTControl -> FramerM;
TOSBaseM.UARTSend -> FramerM;
TOSBaseM.UARTReceive -> FramerM;
TOSBaseM.UARTTokenReceive -> FramerM;
TOSBaseM.RadioControl -> Comm;
TOSBaseM.RadioSend -> Comm;
TOSBaseM.RadioReceive -> Comm;
TOSBaseM.Leds -> LedsC;
TOSBaseM.Voltage -> VoltageC;
TOSBaseM.Get_Voltage -> VoltageC;
FramerM.ByteControl -> UART;
FramerM.ByteComm -> UART;
}
#ifndef TOSBASE_BLINK_ON_DROP
#define TOSBASE_BLINK_ON_DROP
#endif
module TOSBaseM {
provides interface StdControl;
uses {
interface StdControl as UARTControl;
interface BareSendMsg as UARTSend;
interface ReceiveMsg as UARTReceive;
interface TokenReceiveMsg as UARTTokenReceive;
interface StdControl as RadioControl;
interface BareSendMsg as RadioSend;
interface ReceiveMsg as RadioReceive;
interface Leds;
interface StdControl as Voltage;
interface ADC as Get_Voltage;
}
}
implementation
{
enum {
UART_QUEUE_LEN = 12,
RADIO_QUEUE_LEN = 12,
};
uint16_t Batt_Voltage;
TOS_Msg uartQueueBufs[UART_QUEUE_LEN];
uint8_t uartIn, uartOut;
bool uartBusy, uartCount;
TOS_Msg radioQueueBufs[RADIO_QUEUE_LEN];
uint8_t radioIn, radioOut;
bool radioBusy, radioCount;
task void UARTSendTask();
task void RadioSendTask();
void failBlink();
void dropBlink();
void processUartPacket(TOS_MsgPtr Msg, bool wantsAck, uint8_t Token);
command result_t StdControl.init() {
result_t ok1, ok2, ok3, ok4;
uartIn = uartOut = uartCount = 0;
uartBusy = FALSE;
radioIn = radioOut = radioCount = 0;
radioBusy = FALSE;
ok1 = call UARTControl.init();
ok2 = call RadioControl.init();
ok3 = call Leds.init();
ok4 = call Voltage.init();
dbg(DBG_BOOT, "TOSBase initialized\n");
return rcombine3(ok1, ok2, ok3);
}
command result_t StdControl.start() {
result_t ok1, ok2, ok4;
ok1 = call UARTControl.start();
ok2 = call RadioControl.start();
ok4 = call Voltage.start();
return rcombine(ok1, ok2);
}
command result_t StdControl.stop() {
result_t ok1, ok2, ok4;
ok1 = call UARTControl.stop();
ok2 = call RadioControl.stop();
ok4 = call Voltage.stop();
return rcombine(ok1, ok2);
}
result_t err_v;
async event result_t Get_Voltage.dataReady (uint16_t V_batt) {
atomic {
Batt_Voltage = V_batt;
}
return SUCCESS;
}
event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr Msg) {
dbg(DBG_USR1, "TOSBase received radio packet.\n");
if (call Get_Voltage.getData() == SUCCESS) {
err_v = SUCCESS;
}
if ((!Msg->crc) || (Msg->group != TOS_AM_GROUP) || !err_v || Batt_Voltage
== 0xffff)
return Msg;
if (uartCount < UART_QUEUE_LEN) {
/******************************************************************************************************************************************************/
atomic {
Msg->data[26]=Batt_Voltage>>8 & 0xff;
Msg->data[27]=Batt_Voltage>>0 & 0xff;
#ifdef PLATFORM_MICA2
Msg->data[28]=(Msg->strength>>8) & 0xff;
#endif
Msg->data[29]=(Msg->strength>>0) & 0xff;
#ifdef PLATFORM_MICAZ
Msg->data[28]=Msg->lqi;
#endif
}
/*********************************************************************************************************************************************************/
memcpy(&uartQueueBufs[uartIn], Msg, sizeof(TOS_Msg) + 2);
uartCount++;
if( ++uartIn >= UART_QUEUE_LEN ) uartIn = 0;
if (!uartBusy) {
if (post UARTSendTask()) {
uartBusy = TRUE;
}
}
} else {
dropBlink();
}
return Msg;
}
task void UARTSendTask() {
dbg (DBG_USR1, "TOSBase forwarding Radio packet to UART\n");
if (uartCount == 0) {
uartBusy = FALSE;
} else {
if (call UARTSend.send(&uartQueueBufs[uartOut]) == SUCCESS) {
call Leds.greenToggle();
} else {
failBlink();
post UARTSendTask();
}
}
}
event result_t UARTSend.sendDone(TOS_MsgPtr msg, result_t success) {
if (!success) {
failBlink();
} else {
uartCount--;
if( ++uartOut >= UART_QUEUE_LEN ) uartOut = 0;
}
post UARTSendTask();
return SUCCESS;
}
event TOS_MsgPtr UARTReceive.receive(TOS_MsgPtr Msg) {
processUartPacket(Msg, FALSE, 0);
return Msg;
}
event TOS_MsgPtr UARTTokenReceive.receive(TOS_MsgPtr Msg, uint8_t Token) {
processUartPacket(Msg, TRUE, Token);
return Msg;
}
void processUartPacket(TOS_MsgPtr Msg, bool wantsAck, uint8_t Token) {
bool reflectToken = FALSE;
dbg(DBG_USR1, "TOSBase received UART token packet.\n");
if (radioCount < RADIO_QUEUE_LEN) {
reflectToken = TRUE;
memcpy(&radioQueueBufs[radioIn], Msg, sizeof(TOS_Msg));
radioCount++;
if( ++radioIn >= RADIO_QUEUE_LEN ) radioIn = 0;
if (!radioBusy) {
if (post RadioSendTask()) {
radioBusy = TRUE;
}
}
} else {
dropBlink();
}
if (wantsAck && reflectToken) {
call UARTTokenReceive.ReflectToken(Token);
}
}
task void RadioSendTask() {
dbg(DBG_USR1, "TOSBase forwarding UART packet to Radio\n");
if (radioCount == 0) {
radioBusy = FALSE;
} else {
radioQueueBufs[radioOut].group = TOS_AM_GROUP;
if (call RadioSend.send(&radioQueueBufs[radioOut]) == SUCCESS) {
call Leds.redToggle();
} else {
failBlink();
post RadioSendTask();
}
}
}
event result_t RadioSend.sendDone(TOS_MsgPtr msg, result_t success) {
if (!success) {
failBlink();
} else {
radioCount--;
if( ++radioOut >= RADIO_QUEUE_LEN ) radioOut = 0;
}
post RadioSendTask();
return SUCCESS;
}
void dropBlink() {
#ifdef TOSBASE_BLINK_ON_DROP
call Leds.yellowToggle();
#endif
}
void failBlink() {
#ifdef TOSBASE_BLINK_ON_FAIL
call Leds.yellowToggle();
#endif
}
}
4.) Counting from 0 from the start of the data payload,
For Mica2:
byte: 26 27 28
29
value: Vbatt_MSB Vbatt_LSB RSSI_MSB RSSI_LSB
For Micaz
byte: 26 27 28
29
value: Vbatt_MSB Vbatt_LSB LQI RSSI
Vbatt in millivolts.
####IMP#######
Refer CC1000 datasheet for the o/p specifications of the RSSI pin.
5.) The formula for calculating the values in dBm are
V_rssi (volts) = V_batt (volts) * adcCounts / 1024.0;
RSSI_dBm = -50.0 * V_rssi - 45.5; // for CC1000 at 915 MHz!
where adcCounts is the 16 bit RSSI value obtained.
whew! that was a long one.
good luck.
Phaneeth
> Message: 4
> Date: Tue, 24 Jul 2007 12:57:23 -0600
> From: Michael Schippling <[EMAIL PROTECTED]>
> Subject: Re: [Tinyos-help] TOSBase / OscilloscopeRF - rssi reading
> Plzzz help
> To: Brian Mulanda <[EMAIL PROTECTED]>
> Cc: TINYOS Help <[email protected]>
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Sending your reply only to me doesn't help the original poster....
> I'm cc'ing it back to the list.
>
> Anyway, good catch. I didn't study all the code and it appears that
> there are more changes to the std TOSBase (vis T1 at least) than I saw.
>
> As to the original problem, I would go back to a working TOSBase and
> just add the MSG->strength overlay hack and see if it works...This comes
> up so much that I'm tempted to actually try it myself...
>
> MS
>
> Brian Mulanda wrote:
>> There doesn't seem to be any call to the lines of code that forward
>> packets to the UART.
>> Furthermore, there doesn't seem to be any connection between
>> gRxBufPoolTbl
>> and outgoing messages. Also, gRxBufPoolTbl might not have been
>> initialized (possible
>> segfault in receive()).
>>
>> *There could be other problems.
>>
>>
>> -Brian
>>
>> On 7/23/07, *Michael Schippling* < [EMAIL PROTECTED]
>> <mailto:[EMAIL PROTECTED]>> wrote:
>>
>> Assuming that this line in RadioReceive.receive()
>> is the only change you made:
>> gRxBufPoolTbl[gRxHeadIndex] ->data[20] = Msg->strength;
>> It oughta work...but I wonder if the CRC needs to be recalculated?
>> Look through the UART send code and see if it thinks it can just
>> leave it alone. If so you'll have to figure out how to recalculate
>> it.
>>
>> The data[20] thing may walk on some byte of data in the
>> message payloads being sent, so it's not a transparent solution...
>>
>> MS
>>
>> vinayak elangovan wrote:
>> > Hi Every1,
>> >
>> > I am trying to get the signal strength reading from the motes and
>> so i
>> > modified the TOSBase program with reference to the available
>> source
>> > codes in the net. the program is getting compiled but i am not
>> getting
>> > any result when i run the OscilloscopeRF program. Its getting
>> struck,
>> > [EMAIL PROTECTED]:57600 <mailto:[EMAIL PROTECTED] <mailto:[EMAIL
>> PROTECTED]>:57600>
>> resynchronising..... and
>> > its not printing anything.
>> >
>> > Can any1 please verify the code and let me know what the mistake
>> is.
>> > Since i am very new to tinyOS, i need lot of help from you all.
>> > Thanks All in advance.
>> >
>> >
>> >
>> > #ifndef TOSBASE_BLINK_ON_DROP
>> > #define TOSBASE_BLINK_ON_DROP
>> > #endif
>> >
>> > module TOSBaseM {
>> > provides interface StdControl;
>> > uses {
>> > interface StdControl as UARTControl;
>> > interface BareSendMsg as UARTSend;
>> > interface ReceiveMsg as UARTReceive;
>> > interface TokenReceiveMsg as UARTTokenReceive;
>> >
>> > interface StdControl as RadioControl;
>> > interface BareSendMsg as RadioSend;
>> > interface ReceiveMsg as RadioReceive;
>> >
>> > interface Leds;
>> > }
>> > }
>> >
>> > implementation
>> > {
>> > enum {
>> > UART_QUEUE_LEN = 12,
>> > RADIO_QUEUE_LEN = 12,
>> > QUEUE_SIZE = 5,
>> > };
>> >
>> > TOS_Msg uartQueueBufs[UART_QUEUE_LEN];
>> > TOS_MsgPtr uartQueue[UART_QUEUE_LEN];
>> > TOS_MsgPtr gRxBufPoolTbl[QUEUE_SIZE];
>> > uint16_t gRxHeadIndex;
>> > uint8_t uartIn, uartOut;
>> > bool uartBusy, uartFull;
>> >
>> > TOS_Msg radioQueueBufs[RADIO_QUEUE_LEN];
>> > TOS_MsgPtr radioQueue[RADIO_QUEUE_LEN];
>> > uint8_t radioIn, radioOut;
>> > bool radioBusy, radioFull;
>> > uint16_t strength;
>> >
>> >
>> > task void UARTSendTask();
>> > task void RadioSendTask();
>> > task void RadioRcvdTask();
>> > void failBlink();
>> > void dropBlink();
>> >
>> > command result_t StdControl.init() {
>> > result_t ok1, ok2, ok3;
>> > uint8_t i;
>> >
>> > for (i = 0; i < UART_QUEUE_LEN; i++) {
>> > uartQueue[i] = &uartQueueBufs[i];
>> > }
>> > uartIn = uartOut = 0;
>> > uartBusy = FALSE;
>> > uartFull = FALSE;
>> >
>> > for (i = 0; i < RADIO_QUEUE_LEN; i++) {
>> > radioQueue[i] = &radioQueueBufs[i];
>> > }
>> > radioIn = radioOut = 0;
>> > radioBusy = FALSE;
>> > radioFull = FALSE;
>> >
>> > ok1 = call UARTControl.init ();
>> > ok2 = call RadioControl.init();
>> > ok3 = call Leds.init ();
>> >
>> > dbg(DBG_BOOT, "TOSBase initialized\n");
>> >
>> > return rcombine3(ok1, ok2, ok3);
>> > }
>> >
>> > command result_t StdControl.start() {
>> > result_t ok1, ok2;
>> >
>> > ok1 = call UARTControl.start();
>> > ok2 = call RadioControl.start();
>> >
>> > return rcombine(ok1, ok2);
>> > }
>> >
>> > command result_t StdControl.stop() {
>> > result_t ok1, ok2;
>> >
>> > ok1 = call UARTControl.stop();
>> > ok2 = call RadioControl.stop();
>> >
>> > return rcombine(ok1, ok2);
>> > }
>> >
>> > event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr Msg) {
>> > TOS_MsgPtr pBuf;
>> >
>> > dbg(DBG_USR1, "TOSBase received radio packet.\n");
>> >
>> > if (Msg->crc) {
>> > if(Msg->group != TOS_AM_GROUP)
>> > return Msg;
>> >
>> > atomic {
>> > pBuf = gRxBufPoolTbl[gRxHeadIndex];
>> > if (pBuf->length == 0) {
>> > gRxBufPoolTbl[gRxHeadIndex] = Msg;
>> > gRxBufPoolTbl[gRxHeadIndex] ->data[20] = Msg->strength;
>> > gRxHeadIndex++; gRxHeadIndex %= QUEUE_SIZE;
>> > }
>> > else{
>> > pBuf = NULL;
>> > }
>> > }
>> > if (pBuf){
>> > post RadioRcvdTask();
>> > }
>> > else {
>> > pBuf = Msg;
>> > }
>> > }
>> > else {
>> > pBuf = Msg;
>> > }
>> > return pBuf;
>> > }
>> >
>> >
>> > task void UARTSendTask() {
>> > bool noWork = FALSE;
>> >
>> > dbg (DBG_USR1, "TOSBase forwarding Radio packet to UART\n");
>> >
>> > atomic {
>> > if (uartIn == uartOut && uartFull == FALSE) {
>> > uartBusy = FALSE;
>> > noWork = TRUE;
>> > }
>> > }
>> > if (noWork) {
>> > return;
>> > }
>> >
>> > if (call UARTSend.send(uartQueue[uartOut]) == SUCCESS) {
>> > call Leds.greenToggle();
>> > } else {
>> > failBlink();
>> > post UARTSendTask();
>> > }
>> > }
>> >
>> > event result_t UARTSend.sendDone(TOS_MsgPtr msg, result_t
>> success) {
>> >
>> > if (!success) {
>> > failBlink();
>> > } else {
>> >
>> > atomic {
>> > if (msg == uartQueue[uartOut]) {
>> > if( ++uartOut >= UART_QUEUE_LEN ) uartOut = 0;
>> > if (uartFull) {
>> > uartFull = FALSE;
>> > }
>> > }
>> > }
>> > }
>> >
>> > post UARTSendTask();
>> >
>> > return SUCCESS;
>> > }
>> >
>> > event TOS_MsgPtr UARTReceive.receive(TOS_MsgPtr Msg) {
>> > return Msg;
>> > }
>> >
>> > event TOS_MsgPtr UARTTokenReceive.receive(TOS_MsgPtr Msg,
>> uint8_t Token) {
>> > TOS_MsgPtr pBuf = Msg;
>> > bool reflectToken = FALSE;
>> >
>> > dbg(DBG_USR1, "TOSBase received UART token packet.\n");
>> >
>> > atomic {
>> > if (!radioFull) {
>> > reflectToken = TRUE;
>> > pBuf = radioQueue[radioIn];
>> > radioQueue[radioIn] = Msg;
>> > if( ++radioIn >= RADIO_QUEUE_LEN ) radioIn = 0;
>> > if (radioIn == radioOut)
>> > radioFull = TRUE;
>> >
>> > if (!radioBusy) {
>> > if (post RadioRcvdTask()) {
>> > radioBusy = TRUE;
>> > }
>> > }
>> > } else {
>> > dropBlink();
>> > }
>> > }
>> >
>> > if (reflectToken) {
>> > call UARTTokenReceive.ReflectToken(Token);
>> > }
>> >
>> > return pBuf;
>> >
>> > }
>> >
>> > task void RadioRcvdTask() {
>> >
>> > bool noWork = FALSE;
>> >
>> > dbg (DBG_USR1, "TOSBase forwarding UART packet to Radio\n");
>> >
>> > atomic {
>> > if (radioIn == radioOut && radioFull == FALSE) {
>> > radioBusy = FALSE;
>> > noWork = TRUE;
>> > }
>> > }
>> > if (noWork)
>> > return;
>> >
>> > radioQueue[radioOut]->group = TOS_AM_GROUP;
>> >
>> > if (call RadioSend.send(radioQueue[radioOut]) == SUCCESS) {
>> > call Leds.redToggle();
>> > } else {
>> > failBlink();
>> > post RadioRcvdTask();
>> > }
>> > }
>> >
>> > event result_t RadioSend.sendDone(TOS_MsgPtr msg, result_t
>> success) {
>> >
>> > if (!success) {
>> > failBlink();
>> > } else {
>> > atomic {
>> > if (msg == radioQueue[radioOut]) {
>> > if( ++radioOut >= RADIO_QUEUE_LEN ) radioOut = 0;
>> > if (radioFull)
>> > radioFull = FALSE;
>> > }
>> > }
>> > }
>> >
>> > post RadioRcvdTask();
>> > return SUCCESS;
>> > }
>> >
>> > void dropBlink() {
>> > #ifdef TOSBASE_BLINK_ON_DROP
>> > call Leds.yellowToggle();
>> > #endif
>> > }
>> >
>> > void failBlink() {
>> > #ifdef TOSBASE_BLINK_ON_FAIL
>> > call Leds.yellowToggle();
>> > #endif
>> > }
>> > }
>> >
>> >
>> >
>>
>> ------------------------------------------------------------------------
>> >
>> > _______________________________________________
>> > Tinyos-help mailing list
>> > [email protected]
>> <mailto:[email protected]>
>> >
>>
>> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>> _______________________________________________
>> Tinyos-help mailing list
>> [email protected]
>> <mailto:[email protected]>
>>
>> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>
>> <https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help>
>>
>>
>
>
> ------------------------------
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
> End of Tinyos-help Digest, Vol 51, Issue 113
> ********************************************
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help