Sending 49 full frames from Arduino to XBee in API

Hi, I am using the XBee 3 Series and Arduino Mega 2560. I am trying to send 49 frames (48 frames of 273 bytes, and a 166 byte frame). I find that I could not use the arduino-xbee library as well.

Configuration:

Parameter Coordinator End-device
ID 2015 2015
JV - Enabled [1]
CE Enabled [1] -
NI COORD END-DEVICE
AP API Mode Without Escapes [1] API Mode Without Escapes [1]
SM - Pin Hibernate [1]
SP - 1F4

(-) keep default value

This is how the frame structure should look like:

Start Length (MSB, LSB) Frame Type ID 64-bit
add.
16-bit add. Radius Options RF Data CRC
Header Data
0x7E 0x01 0x10 0x10 0x01 0x00 … 0x00 … 0x00 0x00 0x01 of 0x49

I need the RF data to be {0x01, 0x49, 0x01, …, 0x01} (255 bytes total). The checksum for each frame is calculated by summing up the bytes from Frame Type to the end of RF data, then keeping the lowest 2 bytes and subtracting them from 0xFF. I also need to receive each acknowledgement from each successful/unsuccessful transmission and retransmit packets that are lost.

I have done this for sending 1 frame (works fine), here is the code.

#include <Printers.h>
#include <SoftwareSerial.h>
SoftwareSerial XBee(12, 13);                        //xbee TX to mega RX (12), xbee RX to mega TX (13)

byte packet1[] = {0x7E, 0x01, 0x0D, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x49, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xA7};

int wakePin = 2;                                    //xbee pin 10 (sleep) to arduino dig pin 2

void setup() 
{
  Serial.begin(9600);
  XBee.begin(9600);
  pinMode(wakePin, OUTPUT);                       
  delay(500);
  Serial.println("Setup Complete");                 //debug
  XBee.write(packet1, sizeof(packet1));             //send 1st packet
}

void loop() 
{
  digitalWrite(wakePin, LOW);                       //wake module
  
  if (XBee.available() >= 11)                       //ensure all frames present (11 bytes total)
  {                                                 //read transmit status frame
    for (int i = 0 ; i < 8 ; i++)                   //skip to read delivery status (9th byte)
    {
      byte discardByte = XBee.read();
    }
    
    int deliveryStat = XBee.read();                 //0x21 = nwk ack failure, 0x00 = success
    int remaining1 = XBee.read();                   //read remaining 2 bytes to prevent errors
    int remaining2 = XBee.read();
    
    if (deliveryStat == 0x00)                       //if success, send next frame
    {
      Serial.println("Transmit Success");
      Serial.println("Sending next frame...");
      XBee.write(packet1, sizeof(packet1));
      delay(500);
    }
    else if (deliveryStat == 0x21)                  //if failure occurs, re-transmit
    {
      Serial.println("Transmit Failure");
      Serial.println("Retransmitting...");        
      XBee.write(packet1, sizeof(packet1));       
      delay(500);
    }
  }
}

However, I am trying to wrap my head around on how to do this with more frames and receiving each acknowledgement. I tried to do something similar to the one above, but it caused memory issues as there I manually made the frame arrays all the way to frame 49. I’m thinking of incrementing each byte in an array I am going to create to store the basic frame structure. Or any other ways I can do this. Have attached a sketch for the 49 frames. Any help is greatly appreciated.

sketch_dec09a_XBeeMega2560__49_frames_.ino (84.4 KB)

If the Xbee portion of the code is working then you no longer have an Xbee problem.

If the data in packets 1-49 was provided to you as a student exercise then you have a programming algorithm problem. A quick look at the data shows a series of patterns incrementing in small and big steps.

My guess is that you are expected to conserve memory by only using a single packet that starts with the data in packet1 and then you modify it using an algorithm you create to build versions 2-49.

This is your project so you are expected to do the work.

Hi, thanks for the reply. This is not a student project. I do not have an XBee problem, I mostly do not see examples of people sending that much data so I am not sure in which direction should I work it in. Also, there are limited examples of XBee3 interfacing with Arduino and the libraries have not been updated.

xinnn:
Hi, thanks for the reply. This is not a student project. I do not have an XBee problem, I mostly do not see examples of people sending that much data so I am not sure in which direction should I work it in. Also, there are limited examples of XBee3 interfacing with Arduino and the libraries have not been updated.

Where did the carefully crafted packets1-49 come from? Is this sensor data?

If you are looking for a general solution that builds packets using arbitrary data then a good starting point would be the Xbee2 library and a copy of the datasheets for the xbee2 and xbee3 devices to see what the differences are.

If you are looking for a specific solution for your 49 packet example then why not store the data on an SD card and read it in packet by packet?