Here's info on the transmission sent through XCTU:
The frame is sent by clicking on Send Selected Frame.
Here is the frame. Note that it is frame type 0x01 - Tx(Transmit) Request: 16-bit address. Also note that in the RF data entry, the hex number sent is 0x03 0xFF. This is equivalent to 1023 or HIGH. This is simulating a pin that is high until a circuit is created to push a button and the value of digital pin on the xbee will be used for this purpose.
Here's the arduino code for the remote end device:
/*****************************************************************
XBEE_receive_ex.ino
Set up a software serial port to pass data between an XBee Shield
and the serial monitor.
Hardware Hookup:
The XBee Shield makes all of the connections you'll need
between Arduino and XBee. If you have the shield make
sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
the XBee's DOUT and DIN pins to Arduino pins 2 and 3.
End Device + arduino
DL = 1234
MY = 5678
API = 2
CE = 0
Receives this example rx signal from the transmission signal sent by coordinator
Coordinator + explorer shield
DL = 5678
MY = 1234
API = 2
CE = 1
*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
int incomingByte = 0;
int PacketArray[11] = {1,1,1,1,1,1,1,1,1,1,1}; // to store the validated xbee packet
int data = 0;
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
}
void loop()
{
Serial.println(XBee.available()); //prints # bytes in transmitted message
if (XBee.available()>10) //needs 11 bytes to proceed
{
incomingByte = XBee.read(); //read the first byte
Serial.println(incomingByte); //print the first byte to the serial monitor
if (incomingByte == 0x7E){
PacketArray[0]=0x7E; //this is the start of the frame
for(int i=1; i<11; i++) { // for the next 10 bytes, do the following
PacketArray[i] = XBee.read(); //set each byte to a spot in the vector
Serial.print(i); //print the array location
Serial.print(" "); //print a space
Serial.print(PacketArray[i]); // print the value of the byte
Serial.print(" "); //print a space
delay(100); // try different values
}
Serial.println(" "); //add a line break
if (PacketArray[4] == 0x12 & PacketArray[5] == 0x34 & PacketArray[9] ==255 ){ // there are two byte of data, this is the second one
Serial.println("ON"); // if the second byte is 0xFF or 255, print this.
data = PacketArray[9] + PacketArray[8]*256;
Serial.println(data);
}
}
}
delay(5000);//delay of 5 seconds between each iteration of void loop
}
******************************************************************
The remote xbee receives a frame of frame type 0x81. In Hex, the received packet is:
0x7e 0x00 0x07 0x81 0x12 0x34 0x37 0x00 0x03 0xff 0xff
I used XCTU's frame generator to plug these numbers in to see if I could replicate the frame and here's what that looks like. Notice that the frame type is 0x81 because it's a RX(Receive)Packet: 16-bit address. Note that the checksum values match. Also, interestingly, the RSSI value is given which is the strength of the signal (40 max in Hex, I think). This packet is 7 bytes, it's a rx packet, it was sent by the xbee with a MY address of 1234, the signal strength is 37, there are no options, there are two bytes of data that equal 1023 decimal, and the checksum value is 255.
Here's what I see on the serial monitor.
The zeros show me XBee.available() = 0, so nothing is being transmitted.
When I send the selected packet on the coordinator's xbee (blue in the console), I get a transmission status response (red in the console) and it show that the remote xbee received it (Status 00(Success)).
The code reads the first byte as the start delimiter of the frame. Then reads in the rest of the packet and stores all 11 bytes in an array and prints each value in the array (along with the array index) to the serial monitor. Then the code checks the address to make sure the packet was sent by the coordinator. It also checks to see that the last data byte is equal to 0xFF (or 255 decimal). If so, then it prints "ON" and it adds the two data bytes and prints the result to the serial monitor. Notice that they are equal to 1023 (HIGH). Then it goes back to monitoring for another packet and you know this because it's printing zeros which means that there are no packets available to be read.
Next:
1. Add to program and send a return packet with data measured from the arduino pins and printed to the xbee serial port.




No comments:
Post a Comment