Hi António,

Based on the previous mail exchange I would expect your code to look
something like the code I appended. You would have to make sure that you
use a different AM type for the new kind of message that you created.
Sending messages should be quite easy.

Cheers,
Urs


// ----------------------------------------
package net.tinyos.main;

import java.awt.event.ActionEvent;
import net.tinyos.message.*;
import net.tinyos.packet.*;
import net.tinyos.util.*;
import net.tinyos.util.PrintStreamMessenger;

public class Contoller {
  private MessageReceive  msgRcv;
  private MoteIF mote;

  public Contoller(){
    mote = new MoteIF();
    mote.registerListener(new MultiMsg(), msgRcv = new MessageReceive());
    mote.registerListener(new QueryMsg(), qryMsg = new QueryMessage());
  }

  public void sendQuery(int query) {
    QueryMsg msg = new QueryMsg();
    msg.set_query(query);
    try {
      mote.send(MoteIF.TOS_BCAST_ADDR, msg);
    } catch(IOException ioe) {
      ioe.printStackTrace();
    }
  }

  public static void main(String[] args) {
    Contoller c = new Contoller();
    // let's wait for 20 seconds so we have a chance to receive some
messages
    try { Thread.sleep(20 * 1000); } catch(InterruptedException ie) {}
    c.sendQuery(0);
    try { Thread.sleep(20 * 1000); } catch(InterruptedException ie) {}
  }

  class MessageReceive implements MessageListener {
    public void messageReceived(int Id, Message message){
      MultiMsg msg = (MultiMsg)message;
      // we should be able to identify that messages
      // printed on the terminal originate from this
      // statement if the line starts with
      // ">>> Msg: ".
      System.out.println(">>> Msg: " + msg.toString());
    }
  }

  class QueryMessage implements MessageListener {
    public void messageReceived(int Id, Message message){
      QueryMsg msg = (QueryMsg)message;
      // we should be able to identify that messages
      // printed on the terminal originate from this
      // statement if the line starts with
      // ">>> Query: ".
      System.out.println(">>> Query: " + msg.toString());
    }
  }
}
// ----------------------------------------


António Oliveira Gonga schrieb:
> Hey Urs,
> I finally solved the problem, Thanks a lot for your help.My new problem
> now is regarding to sending messages to the motes using the
> MoteIF.send(id, message).
> 
> I'm using a class for receiving messages but I'd like to register
> another class for querying the motes...but it's not working...I also
> used the same class that I use for receiving messages to send messages
> but once again it's not working...
> 
> -Antonio
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to