Suraj Acharya
Suraj Acharya

Reputation: 57

How do I have a two way communication in sensor node using tinyOS?

Sending a packet over the radio is acheived by using AMSend.send(AM_BROADCAST_ADDR, msg, len). In receive.receive I can check from which node did I get the message. But how do I send the message back to the same node from which I received message. I have the node ID, how can I get the network address of the one from which I received data and send back to it. Not just only acknowledging the packet. I need to send data once I receive it. Any help will be appreciated.

Upvotes: 2

Views: 404

Answers (1)

maral
maral

Reputation: 1471

The signature of AMSend.send is:

command error_t send(am_addr_t addr, message_t* msg, uint8_t len);

where addr is documented as address to which to send the packet. AM_BROADCAST_ADDR is a constant denoting broadcast address: packets sent to that address are received by all nodes in radio range. Once you received a packet and obtained sender's id (by AMPacket.source), provide is as addr to AMSend.send. It has the same type am_addr_t which is basically an integer (8- or 16-bit).

Note that an id is typically assigned during compilation or programming a node (see this presentation, slide 61) and usually all nodes have by default the same id unless you assign one explicitly.

Upvotes: 1

Related Questions