This examples sends back any data received.

It can be useful for setup of your XBee modules, in order to make sure they can communicate to each other.


First make sure you have built the project. Next, if you have a look at the examples/echo/target/appassembler directory, you will find a complete distribution of the example.


A few settings are required in order to get the gateway to run properly. If you launch xbee-echo with no arguments, the usage will be displayed.

Here is below a list of the parameters:

CLI arg Description
-b Bauds (optional, by default 9600)
serial port Serial port to use: one Windows something like COM3, on Unix machines something like /dev/tty.usbmodem123


Depending on your OS you either need to run sh bin/xbee-echo or bin\xbee-echo.bat. Do not forget the required CLI parameters for this example to work.


This library provides you a Netty handler which is able to decode data from the serial port (using API mode) into XBeeReceive objects.

So in order to reply to the XBee module which sent data, you simply need to write a Netty handler which handles XBeeReceive objects and write some XBeeTransmit16 objects in the pipeline:

public class XBeeEchoHandler extends ChannelInboundMessageHandlerAdapter<XBeeReceive> {
    protected void messageReceived(ChannelHandlerContext ctx, XBeeReceive request)
            throws Exception {
        XBeeTransmit16 response = new XBeeTransmit16(
                        (XBeeAddress16) request.getSource(),
                        new XBeeTransmit.Options(false, false),


The way to use this handler can be illustrated here. You simply wait for XBeeReceive objects and write back XBeeRequest objects:

Bootstrap b = new Bootstrap(); OioEventLoopGroup())
  .remoteAddress(new RxtxDeviceAddress(serialPort)
  .option(RxtxChannelOption.BAUD_RATE, baudRate)
  .handler(new ChannelInitializer<RxtxChannel>() {
    public void initChannel(RxtxChannel ch) throws Exception {
      pipeline.addLast("xbee-frame-delimiter", new XBeeFrameDelimiterDecoder());
      pipeline.addLast("xbee-packet-decoder", new XBeePacketDecoder(1));
      pipeline.addLast("xbee-request-encoder", new XBeeRequestEncoder());
      pipeline.addLast("xbee-echo", new XBeeEchoHandler());
  ChannelFuture f = b.connect().sync();
  // keeps running until you force the program to exit

Back to top

Version: 0.1. Last Published: 2013-01-23.