[Tinyos-help] I can not receive messages in a remote node.

Juan Antonio López Riquelme ja.lopez.riquelme at gmail.com
Tue Oct 30 03:08:39 PDT 2007


Hello all.



I try to built an application to receive in the computer data from analog to
digital converts (ADC0 and ADC1) in the tmote sky expansion port. Also I
wish to change the sample time (to read the ADCs) the remote node from the
computer.



All con TinyOS 2.



I have node with BaseStation application plugged in the computer.



*I have the following .h file:*



enum {

  AM_MOTETORADIOMSG = 6,     //Message from remote node to computer

  TIMER_PERIOD_MILLI = 250,

  AM_RADIOTOMOTEMSG = 10,   //Message from computer to remote node

};



//This is the payload to send from remote node to computer.

typedef nx_struct MoteToRadioMsg {

  nx_uint16_t nodeid;

  nx_uint16_t ADC0;

  nx_uint16_t ADC1;

} MoteToRadioMsg;



//This is the payload to send from computer to remote node.

typedef nx_struct RadioToMoteMsg {

  nx_uint16_t nodeid;

  nx_uint8_t periodo;    //Sample time

} RadioToMoteMsg;



*In the configuration of remote node I have: *



components new AMSenderC(AM_MOTETORADIOMSG);

components new AMReceiverC(AM_RADIOTOMOTEMSG);

…

App.Packet -> AMSenderC;

App.AMPacket -> AMSenderC;

App.AMSend -> AMSenderC;

App.AMControl -> ActiveMessageC;

App.Receive -> AMReceiverC;



*And in the module:*



uses interface Packet;

uses interface AMPacket;

uses interface AMSend;

uses interface SplitControl as AMControl;

uses interface Receive;

…

void Enviar()

{

  if (!RadioBusy)

   {

    MoteToRadioMsg* btrpkt = (MoteToRadioMsg*)(call Packet.getPayload(&pkt,
NULL));

     btrpkt->nodeid = TOS_NODE_ID;

     btrpkt->ADC0 = ADC0;

     btrpkt->ADC1 = ADC1;
     if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(MoteToRadioMsg))
== SUCCESS)
    {
      RadioBusy = TRUE;
      report_sent();
    }

   }

}



…



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


  {

    RadioToMoteMsg* btrpkt;

    report_received();  //Led 2 Blink

    if (len == sizeof(RadioToMoteMsg))

    {

      report_received();

      //RadioToMoteMsg* btrpkt = (RadioToMoteMsg*)payload;

      btrpkt = (RadioToMoteMsg*)payload;

      if(btrpkt -> nodeid == TOS_NODE_ID)

      {

        Periodo = btrpkt -> periodo;

        Periodo = Periodo*60*1000;

        KillTimer = TRUE;

      }

    }

    return msg;

  }



I get MoteToRadio and RadioToMote Java classes with mig tool. In the
computer I do a Java program following the skel of
TestSerial.javaapplication with some changes. I paste them:



//Listener for the messages that coming from the remote node
public TestSerial(MoteIF moteIF) {

    this.moteIF = moteIF;

    this.moteIF.registerListener(new MoteToRadioMsg(), this);

  }

…


//I try to change the sample every 5 seconds.
public void sendPackets() {

    int counter = 0;

    RadioToMoteMsg payload = new RadioToMoteMsg();



    try {

      while (true) {

      //if(counter == 20){

            System.out.println("Change the sample rate " + counter);

            payload.set_nodeid(1);

            short aux = 1;

            payload.set_periodo(aux);

            moteIF.send(0, payload);

      //}

      counter++;

      try {Thread.sleep(5000);}

      catch (InterruptedException exception) {}

      }



…


//Method to receive messages from remote node.
public void messageReceived(int to, Message message) {

    MoteToRadioMsg msg = (MoteToRadioMsg)message;

    System.out.println("El nodo " + msg.get_nodeid() + " manda el valor del
ADC0 de " + msg.get_ADC0() + " y el otro " + msg.get_ADC1());

  }



Finally say that i received well the data from ADCs, but i can not change
the sample time in the remote node. Moreover at the beginning of event to
receive data I have a call to led2 toggle, but this led never toggle, then I
think that the remote node never gets messages from computer. When run Java
program I do not get warning and/or errors.


Other ask: in the event receive I must define RadioToMoteMsg outside of if
block. If I try to do inside I had errors and I do not understand why.

Thanks in advances.

A greeting,
Juan Antonio.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20071030/2e6b3b67/attachment-0001.htm


More information about the Tinyos-help mailing list