Sorry about that; I was assuming the problem was in the xbee.h or xbee.cpp library files; anyway heres the core of the code.
Appreciate quick response and the help.
#include <Keypad.h>
#include <Button.h>
#include <XBee.h>
#include <AltSoftSerial.h>
#include <SoftwareSerial.h>
uint8_t LCDTxPin = 13;
SoftwareSerial mySerial = SoftwareSerial(255, LCDTxPin);
const int launch_A = 10;
const int launch_B = 11;
int buttonstate_A = 0;
int buttonstate_B = 0;
uint8_t count = 0;
uint8_t ncount = 0;
// Define AltSoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 9;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
AltSoftSerial nss(ssRX, ssTX);
XBee xbee = XBee();
unsigned long start = millis();
uint8_t hset = 0x01;
// set payload to launcher ID;i.e hand station 1 and Station 1 and launcher 1
// set payload to launcher ID;i.e hand station 8 and Station 15 and launcher 5
uint8_t payload []= {hset,0x01,0x01};
// Set DIO0 (pin 20) to Analog Input
uint8_t d0Cmd[] = { 'D', '0' };
uint8_t d0Value[] = { 0x4 };
uint32_t xbee_SH = 0x0013a200;
uint32_t xbee_SL = 0x40923f1f;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
//MEMBRAIN KEYPAD
char keys[ROWS][COLS] =
{
{1,2,3},
{4,5,6},
{7,8,9},
{'*',0,'#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int attempt[2]={0,0}; // used for comparison for statioID
char P_PIN[6]={1,2,3,4,5,6}; // our secret (!) number
char P_attempt[6]={0,0,0,0,0,0}; // used for password comparison
int z=0;
uint8_t key1;
uint8_t key2;
uint8_t StationID = 0;
uint8_t nStationID = 0;
char gotolauncher;
void setup()
{
pinMode(LCDTxPin, OUTPUT);
digitalWrite(LCDTxPin, HIGH);
pinMode(launch_A, INPUT);
pinMode(launch_B, INPUT);
digitalWrite(launch_A, HIGH);
digitalWrite(launch_B, HIGH);
Serial.begin(9600); //MICRO USB serial
//Serial1.begin(57600); //xbee serialon pins 1,2
xbee.setSerial(Serial1);
// start soft serial for debugging
nss.begin(9600);
// start LCD serial
mySerial.begin(9600); //start LCD serial
mySerial.write(0x7c);
mySerial.write(130);
delay(1000);
}
void sendPacket()
{
// SH + SL of your remote radio
XBeeAddress64 remoteAddress = XBeeAddress64(xbee_SH, xbee_SL);
// Create a remote AT request with the IR command
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, d0Cmd, d0Value, sizeof(d0Value));
// Create a Remote AT response object
RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();
sendRemoteAtCommand();
nss.println("First Command");
delay(100);
}
void sendRemoteAtCommand() {
nss.println("Sending command to the XBee");
// SH + SL of your remote radio
XBeeAddress64 remoteAddress = XBeeAddress64(xbee_SH, xbee_SL);
// Create a remote AT request with the IR command
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, d0Cmd, d0Value, sizeof(d0Value));
// Create a Remote AT response object
RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();
// send the command
xbee.send(remoteAtRequest);
// wait up to 5 seconds for the status response
if (xbee.readPacket(5000)) {
// got a response!
// should be an AT command response
if (xbee.getResponse().getApiId() == REMOTE_AT_COMMAND_RESPONSE) {
xbee.getResponse().getRemoteAtCommandResponse(remoteAtResponse);
if (remoteAtResponse.isOk()) {
nss.print("Command [");
nss.print(remoteAtResponse.getCommand()[0]);
nss.print(remoteAtResponse.getCommand()[1]);
nss.println("] was successful!");
if (remoteAtResponse.getValueLength() > 0) {
nss.print("Command value length is ");
nss.println(remoteAtResponse.getValueLength(), DEC);
nss.print("Command value: ");
for (int i = 0; i < remoteAtResponse.getValueLength(); i++) {
nss.print(remoteAtResponse.getValue()[i], HEX);
nss.print(" ");
}
nss.println("");
}
} else {
nss.print("Command returned error code: ");
nss.println(remoteAtResponse.getStatus(), HEX);
}
} else {
nss.print("Expected Remote AT response but got ");
nss.print(xbee.getResponse().getApiId(), HEX);
}
} else if (xbee.getResponse().isError()) {
nss.print("Error reading packet. Error code: ");
nss.println(xbee.getResponse().getErrorCode());
} else {
nss.print("No response from radio");
return ;
}
}
void getlauncher()
{
//nss.println("I'm Here");
switch(StationID)
{
case 1: //Station #1
buttonstate_A = digitalRead(launch_A); //A launcher button pushed
buttonstate_B = digitalRead(launch_B); //B launcher button pushed
if (buttonstate_A == LOW)
{
nss.println("launch_A pressed");
ncount = count + 1;
d0Value[0] = 0x5 ;
xbee_SH = 0x0013a200;
xbee_SL = 0x40923f25;
sendPacket();
delay(10);
payload[1] = 0x01;
payload[2] = 0x01;
}
if (buttonstate_B == LOW)
{
nss.println("launch_B pressed");
ncount = count + 1;
d0Value[0] = 0x5 ;
xbee_SH = 0x0013a200;
xbee_SL = 0x40923f3d;
sendPacket();
delay(10);
payload[1] = 0x01;
payload[2] = 0x02;
}
break;
case 2: //Station #2
buttonstate_A = digitalRead(launch_A); //A launcher button pushed
buttonstate_B = digitalRead(launch_B); //B launcher button pushed
if (buttonstate_A == LOW)
{
nss.println("launch_A pressed");
ncount = count + 1;
d0Value[0] = 0x5 ;
xbee_SH = 0x0013a200;
xbee_SL = 0x40923f25;
sendPacket();
delay(10);
payload[1] = 0x02;
payload[2] = 0x01;
}
if (buttonstate_B == LOW)
{
nss.println("launch_B pressed");
ncount = count + 1;
d0Value[0] = 0x5 ;
xbee_SH = 0x0013a200;
xbee_SL = 0x40923f3d;
sendPacket();
delay(10);
payload[1] = 0x02;
payload[2] = 0x02;
}
break;
}
}
void readcounts()
{
mySerial.write(254); //cursor to beginning of first line
mySerial.write(128);
mySerial.write("StationID= ");
mySerial.write(254); //cursor to position 12 of first line
mySerial.write(139);
mySerial.print(nStationID);
mySerial.write(254); //cursor to beginning of second line
mySerial.write(192);
mySerial.write("#launches= ");
mySerial.write(254); //cursor to position 12 of second line
mySerial.write(203);
mySerial.print(ncount);
}
void loop()
{
if (nStationID != StationID)
{
readcounts();
StationID = nStationID;
}
if (StationID == 0)
{
}
if (gotolauncher = '#')
{
getlauncher();
}
if (StationID != 0 && StationID != 18 && StationID != 21)
{
}
if (StationID == 21)
{
}
if(StationID == 18)
{
}
if (ncount != count)
{
readcounts();
count = ncount;
}
}