Shop OBEX P1 Docs P2 Docs Learn Events
Javelin Stamp - receive data w/ Zigbee — Parallax Forums

Javelin Stamp - receive data w/ Zigbee

rfman78rfman78 Posts: 12
edited 2008-02-19 07:22 in General Discussion
Hi all,
hoping someone could provide some insight as far as using the Javelin stamp in coordination with the Zigbee modules.

Is there any sample code showing how to receive data using the Javelin stamp? I've found samples on how to transmit , and those were quite helpful.

Any help or direction is greatly appreciated.


PS: A little background information: for now, just to get familiar with the Javelin stamp and the Zigbee's, I'm trying to create a simple wireless chat client (just using the terminal to enter messages to be sent, and show messages being received.).

Thanks.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-02-17 10:45
    If zigbee is·related to xbee, take a look at his thread:
    http://forums.parallax.com/showthread.php?p=705802

    regards peter
  • rfman78rfman78 Posts: 12
    edited 2008-02-19 03:11
    Hello All,
    A general question here when receiving data via the XBee and Javelin.

    For my application, I will be receiving both int and Strings as data. I am stuck as to how to determine which one is in the buffer before actually manipulating it. As of now, my code in the main application looks like:

    while (true)
    {
    while (!node1.byteAvailable())
    {
    }

    System.out.println("Data Available! \n");
    System.out.println("message: " + node1.getStringData() + "\n");
    }
    }

    My question is, if there is an integer in the buffer, how would I know, so that i can call node1.getIntData() instead of the getStringData method.
  • Jon KeinathJon Keinath Posts: 146
    edited 2008-02-19 03:50
    rfman,

    As each character is held in the buffer, the easiest way to check if it is an digit (or part of the integer) I do something like this...

    ...
        data = rx.receiveByte();
        while (isDigit(data))
          {
          db = 10 * db + (data - '0');
          data = rx.receiveByte();
          }
    ...
    

    where the isDigit function is as follows...

      public static boolean isDigit(int ch)
        {
        return ch<='F' && ch>='0';                     //between 0 and 15
        }
    

    You may have to modify this slightly if you do not know whether it is going to be an int or a string, as the code above is expecting a chunk of digits to come at a specific point.·

    What i am trying to say is that I just use everthing as chars then convert them to ints or stings (or stringbuffers) as needed.

    Hopefully that will help.

    ---
    As a side not don't do things like
    System.out.println("message: " + node1.getStringData() + "\n")
    

    as that will cause overflows eventually use a stingbuffer or if just using for terminal use...
    System.out.print("message: ");
    System.out.print(node1.getStringData());
    System.out.println("\n");
    

    Hope this didn't confuse you more...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Jon
    www.jonkeinath.com
  • rfman78rfman78 Posts: 12
    edited 2008-02-19 04:22
    Hi,
    I've got another idea...... Please tell me if you think this would work, or would eventually fail due to timing/xmit issues.

    I can include a header in the transmitted data that tells what it's going to be. for example:
    int!xyz = an integer is everything that comes after the !
    str!abc = everything after the ! is going to be a string

    Please share your thoughts!
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-02-19 07:22
    If you have no control on how the transmitter formats its data, you must
    use the protocol dictated by the transmtter.

    If you·have full control on how the transmitter formats its data,
    like when you have the source for the transmitter program,
    then you can choose whatever protocol you like.
    For example: you can decide that numbers are transmitted
    in hex digits like Jon said, or just decimal digits. Put a '#' in front
    of numbers to mark the start of a number. Put a '$' in front of a text message.
    It just means you cannot use # and $ in text messages.
    If that is a problem you can use some control character (ascii code < 32),
    like STX and ETX surrounding a text message, or use a escape character like \,
    so to use \, # or $ in a text message, send \\, \# or \$ respectively.

    regards peter
Sign In or Register to comment.