[ALPHA] The XBee Network Protocol (XNP)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

[ALPHA] The XBee Network Protocol (XNP)

by miax on Sun Jan 15, 2012 1:22 am


This will be the first ALPHA release of the Xbee Network Protocol (XNP). I'm sure there are 100 better ways I could have coded different bits in the program.
My hope is that members of the community will try out XNP and make good use of it in their projects, and that those folks and others interested might give me
a few tips and pointers on how I could do things better. :) The Xbee Network Protocol is OpenSource, and is posted at the Github Software Repository for XNP
where you can download the sketch:


This is the official XNP release site, the home of Sojourn Studios. All documentation for XNP can be found at:


XNP Comes equipped with many of the basic features of TCP/IP, and works well in full-mesh networks and unnder poor radio conditions. It is possible
to setup an XNP network with one XNP Core/Control router and a dozens of XNP edge-routers that run sensor shields or feedback units as shown in the
feature overview below:


The Xbee Network Protocol is designed to allow Xbee-enabled Arduino Mega's (and eventually UNOs) to communicate with one another wirelessly (the
versions used with XNP were Xbee Series 1 radios broadcasting at 2.4 GHz). In an XNP network, each Xbee radio is configured in a basic send/receive
configuration with the same PAN IDs. When an Xbee is connected to an Arduino Mega using one of the SerialX ports (XNP defaults to Serial1,
PINs 18 and 19), XNP allows the Arduino's to communicate in real-time with other similarly-configured Arduino Megas. The XNP protocol allows
any number of Xbee-enabled Megas to communicate with one-another and has three different modes of operation for different applications (Full Mesh
Networking, Non-Mesh Networking, and Fast-and-Furious Networking). Each mode has strengths and weakness over the other depending on the application.


You'll need two Arduino Mega-2560s (http://www.adafruit.com/products/191 to run the Alpha-code, Two Adafruit Xbee radio adapter kits
(http://www.adafruit.com/products/126), and Xbee Series 1 Radios ([url]href='http://www.adafruit.com/products/128[/url] to get started.
I provide a detailed instruction guide on how to setup an XNP router, and documentation that will help you to understand how it works. The sketch
started with example code from Lady Adas tutorials on Xbee (http://www.ladyada.net/make/xbee/) and the Tweet-A-Week kit
(http://www.adafruit.com/products/144). The maximum number of XNP-enabled Xbee Arduino Megas that can successfully talk in the same
room has not been confirmed, but so far I have had 5 working together on my desk with a 100% data transmission success rate. To get an idea of
just how challenging packet communication is for XNP, the diagram below illustrates the life of a typical packet on a big XNP network:


XNP packets have to be as small as possible due to the transport medium (57,600 baud), which is a narrow bandwidth channel that can become easily
congested with 5+ XBee radios all sharing that same bandwidth channel. XNP is clearly not meant for streaming music, video or image content (as
that's what TCP/IP is for), but does have some unique properties that make it different than TCP/IP and potentially more data-friendly for
sensor/collection projects. XNP packets are restricted to 32-byte payloads by default to give each XNP packet a better-chance of being successfully
received in one-piece. TCP/IP packets have the a dedicated medium and more stream-lined communication mechanism that affords it the luxury fixed-
length headers and 512-byte payloads, where XNP is more successful with delimiter-based headers and smaller payload sizes. More experimenting will
occur in the months ahead to improve this condition.

What I would REALLY appreciate is feedback and constructive criticism on how I could make it better. :) This thread will be my official "Blog" for XNP
where I answer questions and offer help, post updates, etc. I chose this path because 100% of the products in XNP I get from Adafruit, some are made by
Adafruit and we use Adafruit tutorials on the XBee. Plus I post all my projects here, and I look forward to your feedback!



XNP GitHub: https://github.com/SojournStudios/Xbee_Network_Protocol
XNP Documentation and Tutorials: http://sojournstudio.org/xnp

Posts: 152
Joined: Tue Apr 05, 2011 11:41 am

Re: [ALPHA] The XBee Network Protocol (XNP)

by miax on Sun Jan 15, 2012 1:52 am

I'm posting some of the URLs in the documentation site directly to make them easier to find, starting with an Overview of XNP:


A deeper understanding of how XNP works:


Software Downloads related to XNP are at:


Required and Recommended Tools and Hardware needed:


Communicating with an XBee radio:


Full Installation instructions:


XNP Configuration instructions:


Lastly a quick-build guide for an XNP Router:


Bedtime for Bonzo! Will post more tomorrow,



Posts: 152
Joined: Tue Apr 05, 2011 11:41 am

Re: [ALPHA] The XBee Network Protocol (XNP)

by adafruit_support_bill on Sun Jan 15, 2012 8:03 am

My, you have been busy! :D
Looks like a well-thought-out protocol. It would seem that the redundant forwarding on re-transmits would limit scalability in non-ideal conditions. That could be reduced or eliminated, but you would have to trade-off that against a slightly increased packet-size and (likely considerable) increase in stack complexity.

Posts: 65407
Joined: Sat Feb 07, 2009 10:11 am

Re: [ALPHA] The XBee Network Protocol (XNP)

by miax on Sun Jan 15, 2012 8:32 am

Adafruit Support:

Yeah that was the real cause of the 4 week delay, I was trying to get the documentation 100% done. Unfortunately work has been Crazy busy lately and that has limited my time to writing/documenting in the evening or I would have had all the web site done + many example program configs. :o I'll add that over the coming weeks, hopefully enough is done to make it Usable - especially when I solve my UNO NewSoftSerial problem.

As for redundant forwarding; that only happens in Full Mesh networking, the Non-Ideal and Fast and Furious modes don't forward packets at all. For Full Mesh, I built in a protection mechanism that will limit the number of times that any XNP router will forward a packet. So we do loose bandwidth over the fact that XNP re-transmits packets to forward them - but the benefit is that I don't have to "route" packets. Your right though, it would be better to go to a routed algorithm for packet forwarding - noting this in my new feedback log of things to do! :)

Thanks for the feedback. :D I'm working on UNO compatibility next, its all coded except for a receive problem with NewSoftSerial that I'll post later today for help/comment.

More to come!

Kristopher Kortright
Father, Husband, Horseman, Maker, Writer, Internet Technologist and Inventor of Strange of Useful Things
Supporter of the Open Source Hardware movement

Posts: 152
Joined: Tue Apr 05, 2011 11:41 am

Re: [ALPHA] The XBee Network Protocol (XNP)

by miax on Sun Jan 15, 2012 3:06 pm

XNP Revisions pushed, XNP 0.8.7S (ALPHA-S) code is now on GitHub for download: https://github.com/SojournStudios/XBee_Network_Protocol

Documentation updates have already begun today on the XNP site: http://sojournstudio.org/xnp/

This version works well, and only requires that you set the IDENTITY integer at the top of the sketch (each XNP router has a unique IDENTITY number). Make sure that at least One XNP router is IDENTITY = 1, as that becomes the Control Router/Gateway for the rest. I need to specify that better in the documentation today, but one router on an XNP network (the gateway) must be IDENTITY = 1; the rest of the XNP routers can be any integer you like up to 999.

Then compile, open console and watch the packets fly!

} RUN STATS from test:
-} Outbound: 1860, Inbound: 3038, Forwards: 39, AvgRTT: 96ms
-} Total Packets: 4937, Bad Packets: 0, Packet Loss: 0.0 %
-} Ping Ratio: 413/413, Network Avail: 100.0 %
-} Data Transmission Ratio: 445/444, Success: 99.77 %
-} Output Buffers: 6, Open: 4, Used: 2, Buffer Utilization: 33.33

All systems go at this point, I'm going to work on the UNO release and more updates to the XNP Configuration pages (its missing half the pages, couldn't get those done in time for AAE :)

Stay Tuned,


Posts: 152
Joined: Tue Apr 05, 2011 11:41 am

Re: [ALPHA] The XBee Network Protocol (XNP)

by PanGoat on Mon Jan 16, 2012 12:33 am

This is interesting. I've been implementing an OSC library for XBee communication. Lots to consider. I'll check out what you've got going here.
Posts: 2
Joined: Sun Jan 01, 2012 5:02 am

Re: [ALPHA] The XBee Network Protocol (XNP)

by miax on Thu Jan 26, 2012 12:26 am

I've updated the XNP site with news about XNP, current status and a new shield (seen on Adafruit Industries Show and Tell SHOW-AND-TELL 1/21/12 - http://www.youtube.com/watch?v=UDlLVZJ7_Kc)

Hello Open Source Hardware/Software Community! There are three big updates on XNP:

XNP-ForwardMegaShield-02-800.png (727.05 KiB) Viewed 4568 times

ALPHA Update:

A new version of XNP is being spun-up, with a number of bug fixes as well as support for the XNP Forwward Mega Shield and Adafruit 2.8' TFT Touch Screen LCD. There are still a few more bugs I want to crush before updating GitHub with the new "0.87U" release. I plan to post the new version sometime this weekend once it is fully debugged.

The fun part was adding support for the Adafruit TFT Touch Screen, as it was my first real test of the Forward Mega Shield sitting along-side of another Arduino-compatible shield without any hardware conflicts. It worked the first time, and that made me very excited - the TFT adafruit shield is Awesome! I also now have the 2 Gigabyte SD card I can use, and so far the Lady Ada tutorial and software library are easy to use - within two hours I had an XNP splash screen loaded and ready to go!


Erin RobotGrrl generously donated her time to hack-out a version of XNP that works on the UNO! She also showed me where I was getting stuck on the UNO compile, and for that I am eternally grateful!! Im still working on a version of the larger code that will work on the UNO well, and its all thanks to Erin! I really don't think it would have been possible to find it on my own, as I was using a completely wrong library!

RiderNetXNP-UNO_800.jpg (332.4 KiB) Viewed 4568 times

One thing that she showed me is that my PHAT code is over-commented and has a ton of stuff that it doesn't NEED to function as a packet engine. This is definitely true, as I have tons and tons of profiling code and comments in there to help me debug it. I promise the first beta release will be much reduced. :)

XNP Forward Mega Shield:

I finished development of a new shield for the Arduino Mega 2560 that I'm calling the Forward Mega Shield (in reference to it's position, forward on the Mega's extended PIN outs. The shield, built on the Adafruit Mini-Proto board, contains all of the hardware for an XNP router; Adafruit XBee Adapter ports, 3 sensor ports, a power switch tail port, two buttons, a 16-position rotary POT for setting the router's ID, and a Piezo buzzer. There are also 3 packet indicator LEDs (in, out and bad packets) and an RGB status LED.

XNP-ForwardMegaShield-03-800.png (701.38 KiB) Viewed 4568 times

The FMS was alot of fun to make, and reminded me of how much fun the hardware hacking part is! (versus the 6 weeks-long grind of developing the first XNP ALPHA software release). I very much want to turn this into a PCB, and will be investigating Fritzing as one potential way of doing that. It may be too early, but think I want to make these into my first kits - but I have much to learn and study about it first!

I'm finishing the last FMS (of three prototypes) tonight, and will have some final fun news to share on Friday!

Thanks for all the help and encouragement! :)


The XNP Update can be found here here: http://sojournstudio.org/xnp/?p=616

Comments welcome!!


Posts: 152
Joined: Tue Apr 05, 2011 11:41 am

Re: [ALPHA] The XBee Network Protocol (XNP)

by miax on Mon Feb 06, 2012 10:52 am

My progress on XNP has been slowed due to a heavy work schedule last week in which I was working through several nights. However on the weekend I was able to make good progress on my article about RiderNet-XNP (more on that later) and on building the 15 Forward Mega Shields I will need (10 for the farm, 2 as a gift, 3 for devel). This is the last hardware component of RiderNet and XNP (though in March I'll likely make an UNO-shield).

XNP Mega Forward Shields (batch 50% done)
XNP-FMS_HalfBuild_800.png (859.87 KiB) Viewed 4351 times

I was able to get all of the hardware mounted on the mini-proto shileds this weekend, along with the header blocks underneath to connect to the Arduino Mega 2560s. I ended-up swapping-out the Pieze buzzers on most of them for the new diffused, 5mm slow-fading LEDs from Adafruit - so each forward shield will have nice color and rythum, which will leave the diffused tri-color LED for status indications. I should be done with these by Thursday or Friday, some testing, some Fedex, and Show-N-Tell this weekend. :)

Once the FMS shields are done and my article complete, I'll turn focus back to working on the ALPHA code again. I hope I have not dissapointed too-many folks with how limited XNP is right now, and I struggled with the notion of even releasing it at this stage, but it had to escape the lab! Once I get time to really focus and clean-it up, it will perform for the Mega and UNO with better performance and a smaller memory profile. I also plan to research the XBee radios alot more, and see what I can use in the existing protocols to make XNP more efficient and capable.

For the next week however, it's all about finishing these shields and finishing an article about RiderNet-XNP for some very generous folks!

I'll post another update at the end of the weekend.. All comments and feedback are welcome!


Kristopher Kortright
Father, Husband, Horseman, Maker, Writer, Internet Technologist and Inventor of Strange of Useful Things
Supporter of the Open Source Hardware movement

Posts: 152
Joined: Tue Apr 05, 2011 11:41 am

Please be positive and constructive with your questions and comments.