Xbee Discover radio node in the same Network
Hello! So far I'm loving the Xbee but I need help to write my own program. With the XCTU software I was able to communicate between 2 XBee Pro that are in the same Network (same channel). One is the "Coordinator" receiving data and the other is the "Router" sending "hello world" from a Stamp2. All works perfectly with the XCTU software. I created a project on Visual Studio 2022 (C# windows form). I was able to open the port successfully means the Xbee "Coordinator" is ready but how I add the other Xbee (router) that is not connected to the computer. You do this manually on the XCTU software by pressing "Discover radio node in the same Network". How do I add all the Xbee remote modules on Visual Studio C# code to be all communicating? I appreciate any help!
Comments
Look up the Node Discovery command. It's an AT message that will cause XBees in the same Channel and PAN to respond (MAC, MY address, and Node ID). At Elite Laser Tag we use it to identify our taggers (guns) in a system. Fair warning: if there are other XBees in the same Channel and PAN but not part of your system, you could be fooled. We get around this by having the tagger program the NI field of the XBee with a string that identifies us and product type. For example, "ELTE-01" is a tagger, "ELTE-02" is a game box. It's not likely that another vendor is going to use those strings in their NI field.
Hi JonnyMac! Where is this Node Discovery command? Is something on the XTCU software or something I have to setup via code on my .Net project? Do you have any screenshot or examples I can look up ?
Thanks
I edited my post to show you how you can create a command using the frames generator in XCTU. You need to send this sequence to the XBee, then get ready to receive.
There is also a serial terminal in XCTU. I fired up a tagger and sent the ND command and monitored the response. There are actually two responses: the first (yellow highlight) is the tagger. The second (underline) is the message from the XBee telling you the ND scan period is complete.
XCTU is a very useful tool. I suggest you spend a lot of time with it to learn the ins-and-outs of XBee.
Let's see if I understand. Are you saying if I send this command (7E 00 04 08 01 4E 44 64) from the BS2 that is connected to the XBEE remote module before I send the String EX: "hello world" the Master XBee connected to the computer will get the message? without having to discover the remotes modules? Or I'm confused?
Remember I have 1 Xbee (Coordinator) USB to PC and 1 Xbee as remote connected to a BS2. The BS2 sends OUT "Hello World" and the Coordinators needs to receive that message.
With one remote and one at the PC you should simply consider transparent mode -- Node Discovery is for locating devices within your network and there's not enough RAM in the BS2 to deal with that.
While I would never use the XBee with a BS2, others have. This document is old and XCTU has been updated a lot, but it should be helpful.
-- https://forums.parallax.com/uploads/attachments/47421/101790.pdf
@JonnyMac
Hi JonnyMac! you are a genius! everything works except I can't read the whole data. It just read some characters. I feel I'm really close to finish with this project. I just need to know why when I'm reading the serial port on C# only reading a few character. Maybe because I'm not sending the "ND scan period is complete" ? 7E 00 05 88 01 4E 44 00 E4 or something wrong on my code?
}
No, I just have a lot of experience with XBee at my employer. We have fields with more than 100 "taggers" in operation that are sending messages back to our scoring system.
I don't code in C# and having only started working with serial for the PC using Xojo. Here's some things you'll understand once you've taken the time to study XBee docs (hint, hint).
1) API Messages begin with $7E
2) The byte that follows will always be $00 (MSB of payload length)
3) The 3rd byte will be LSB of the payload length
4) The payload is the 4th through penultimate bytes
5) The last byte is the XBee checksum
I highlighted the payload here. Note that the byte that precedes the payload indicates its length.
This is how I receive an XBee message in the Propeller (if you can understand C#, Spin should be very simple).
You probably have to do things differently on the PC with serial events. Perhaps you need to keep a state variable vis-à-vis a message. Maybe it's 0 when no message is in process. When a $7E is received, the state would be set to 1 (receiving), the $7E would be buffered, and the buffer count (len in my code) set to 1. Note that after capturing the LSB of the payload length I use a loop to collect the rest of the message. While rare, the Propeller serial buffer could be holding multiple messages when this method is called. This design lets me extract one method at a time. I can check the serial buffer available() method to see if there's anything else to do.
With the message fully buffered, you can verify the checksum. This is how I do it in Spin.
Note that the checksum is of the payload bytes only. This is how I use it in Spin
The first line calculates the index of the last byte in the buffer. The checksum is calculated on the payload which starts at index 3 and is index 2 bytes long. The last byte in the buffer is the transmitted checksum.
@JonnyMac Problem solved! I was not getting all the data because the BS2 was sending Command "CLS" before sending the string I need, that will cause the screen to be clear. removing that fixed the problem:
' {$STAMP BS2}
' {$PBASIC 2.5}
SELECT $STAMP
#CASE BS2
T9600 CON 84
ENDSELECT
Baud CON T9600
Tx PIN 0
Rx PIN 1 'NO CONNECTED
'******************* Varaible Declarations***************
Counter VAR Byte
'********************************************************
'**************Main Loop*********************************
PAUSE 500
SEROUT Tx, Baud, [ $7E, $00, $04, $08, $01, $4E, $44, $64] 'DISCOVERY NODE AT COMMAND
PAUSE 200
SEROUT Tx, Baud, ["1A1"] ' This is the data I need
PAUSE 500 ' Pause
END
Why do you think you need the ND command? Your code makes not sense. When the ND is sent by an XBee, any other XBees in the network will respond to it, but you're not doing anything with the response -- you're just filling the XBee RX buffer.
I, and others, have a lot of experience with XBee. What is your goal with the project?
Hey JonnyMac. Im not connecting XBEE DOUT to any pin on the BS2. The BS2 is only sending data, no receiving. Everything is working fine. Now Im going to connect “buttons” on the BS2 to be press and send string. Do you see anything wrong with this approach?
There is no need to use Node Discovery. If you setup your XBees for transparent mode it will act like a wired connection without the wires.
https://www.digi.com/resources/documentation/Digidocs/90001942-13/concepts/c_transparent_mode_detailed.htm?tocpath=XBee transparent mode|XBee transparent mode in detail|_____0
@JonnyMac
Thank you! very useful information. All Xbee's are happy and communicating! Moving on to finish the project now!