June 18, 2011 · Don't Forget telosb

Altering telosb transmission range in TinyOS 2.0

It all started when I read this post, where it stated the obvious (to reduce the transmission range you have to reduce the transmission power). And although it provided some basic instructions, I thought I would just put up some more code for those who aren’t as savvy as most.

The first option in Tinyos 2, with a platform with the cc2420 (such as MicaZ and the Tmotes), is to statically set a flag in the makefile:

CFLAGS += "-DCC2420_DEF_RFPOWER=1"

An option, but not the one I was looking for. To set it dynamically for every packet, this is what we need to do. In your main configuration, wire in the CC2420PacketC:

implementation
{
components CC2420PacketC;
App.CC2420Packet -> CC2420PacketC;
}

In your main application:

module ClientAppP @safe()
{
uses interface CC2420Packet;
}

And finally, the call to CC2420Packet.setPower() passing in the power with values within the range of 0 to 31. (Although with my motes, it only worked from 1 up)

ClientPacket* msg = (ClientPacket*)(call Packet.getPayload(&pkt, NULL));
...
call CC2420Packet.setPower(&pkt, 1);
if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(ClientPacket)) == SUCCESS)