This project has moved and is read-only. For the latest updates, please go here.

This demo shows you how XBee library can be used with FEZ Hydra. Hardware that was used in this example:

  • 1 x FEZ Hydra mainboard
  • 1 x USB Client SP Module
  • 2 x XBee Adapter Module
  • 1 x XBee eblock adapter (legacy)
  • 1 x MakeBread Module
  • 1 x LED7R Module
  • 1 x XBee ZB with integrated antenna (XB24-Z7WIT-004)
  • 1 x XBee-PRO ZB with RPSMA connector (XBP24-Z7SIT-004J)
  • 2 x XBee ZB with U.FL connector (XB24-Z7UIT-004, one is not shown in the picture)
  • 1 x XBee ZB Wall Router (not shown in the picture, used as extra node in the network)
  • 1 x ConnetPort X4 (not show in the picture, used as extra node in the network)

Below is the connection diagram generated by Visual Studio:




And here is a picture of how it all looks in reality:




Here is a list of steps performed by the demo application:

  • Turn on the red LED in the LED7R module
  • Initialize all connected XBee modules
  • Print basic infomation about each connected XBee
  • After XBee configured as Router reports status ‘Associated’ perform node discovery (from this Router)
  • Print info about each discovered node
  • Send a ping message to that node
  • Turn on next LED in the LED7R module
  • If the Router receives a pong message print in to the sceeen


Source code:

using System.Collections;
using System.Text;
using Microsoft.SPOT;
using NETMF.OpenSource.XBee.Api;
using NETMF.OpenSource.XBee.Api.Common;
using XBee = NETMF.OpenSource.XBee.Api.XBee;

namespace Gadgeteer.Tester
    public partial class Program
        private const string Ping = "PING";
        private const string Pong = "PONG";
        private ArrayList _nodes;

        void ProgramStarted()
            lED7R.TurnLightOn(7, true);

            coordinator.Api.DataReceived += OnDataReceived;

            endDevice.Api.DataReceived += OnDataReceived;

            router.Api.StatusChanged += (x, s) => OnStatusChanged(s);
            router.Api.DataReceived += OnDataReceived;

            Debug.Print("Coordinator config: " + coordinator.Api.Config);
            Debug.Print("Router config: " + router.Api.Config);
            Debug.Print("End device config: " + endDevice.Api.Config);

        private void OnStatusChanged(ModemStatus status)
            if (status == ModemStatus.Associated)

        private void DiscoverNodes()
            _nodes = new ArrayList();

            router.Api.DiscoverNodes(node =>
                var nodeInfo = node.NodeInfo;

                if (_nodes.Contains(nodeInfo))


                PrintNode(_nodes.Count, node);

                // depending on XBee settings discovery may return local node info
                if (nodeInfo.SerialNumber != router.Api.Config.SerialNumber)

        private void PrintNode(int nodeNumber, DiscoverResult info)
            Debug.Print("#" + nodeNumber + " - " + info);

        private void OnDataReceived(XBee receiver, byte[] data, XBeeAddress sender)
            var dataStr = new string(Encoding.UTF8.GetChars(data));

            switch (dataStr)
                case Ping:

                case Pong:
                    Debug.Print("Received Pong from " + sender);


Generated output:


Using mainboard GHIElectronics-FEZHydra version 1.0
Coordinator config: ApiMode: EnabledWithEscaped, HardwareVersion: Series 2, Firmware: 21A0, SerialNumber: 0013A20040692938, NodeIdentifier: ' '
Router config: ApiMode: EnabledWithEscaped, HardwareVersion: Series 2, Firmware: 23A7, SerialNumber: 0013A2004086AD32, NodeIdentifier: ' '
End device config: ApiMode: EnabledWithEscaped, HardwareVersion: Series 2 Pro, Firmware: 29A7, SerialNumber: 0013A200406E92A6, NodeIdentifier: ' '
#1 - Router, address=173F, serial=0013A2004086AD32, id=, parent=FFFE
#2 - End device, address=1B0F, serial=0013A2004086AD25, id=, parent=C3C9
#3 - Coordinator, address=0000, serial=0013A20040692938, id=, parent=FFFE
Received Pong from 0013A20040692938
#4 - End device, address=7D81, serial=0013A200406E92A6, id=, parent=C3C9
Received Pong from 0013A200406E92A6
#5 - Router, address=C3C9, serial=0013A20040476061, id=CONNECTPORTX4, parent=FFFE
#6 - Router, address=C306, serial=0013A2004060F30B, id=WALLROUTER, parent=FFFE

Last edited Mar 29, 2012 at 1:41 PM by gralinPL, version 9


gralinPL Jan 30, 2013 at 6:51 PM 
Your are correct, the modules are preconfigured to be a router, coordinator and end device. The mode (or role as you call it) is determined by the firmware of the XBee module, so you can't switch the mode at runtime in C#. This limitation is caused by memory constraints of the hardware, it has to little memory to store all three versions of the firmware. In order to preconfigure the XBee you need to connect it to your PC (e.g. using an adapter like this and use X-CTU software ( I know there are new generation of XBee modules that have more memory and one unified firmware, but this library was written when those were not available yet.

appsolo1 Jan 5, 2013 at 12:22 PM 
I have a couple of questions regarding this Library and example. Firstly in this example are the xbee modules preconfigured to be coordinator, Router and End device? Secondly is it possibly to assign the xbee module roles using this library in c#.