Ok, I worked with my xbees for a while last night.. I am not sure what was happening with them, but i have it all sorted out now.
I am now using the xbees in api mode 2, and things work soooo much better now.
I am using the following config on the sender xbee, and it is standalone:
DL-1234
MY-5678
CE- 0-end device
NI- SENSOR
AP- 2
DIO4- 3-digital input
IC- 10 (watches pin 4 only for changes and broadcasts only when the state changes)
On the base unit, i have the following settings:
MY - 1234
CE - 1 (coordinator)
NI - COORDINATOR
AP - 2
Now, here is the sketch that I am using on the base unit.
Currently, it catches the API string when it's sent from the remote sensor, and broadcasts it through the serial monitor. It shows the sensor id when it does receive an "alarm" state.
#include <NewSoftSerial.h>
/*
Basic Xbee Remote Sensor Alarm
This sketch reads the state of a string sent by a remote "sensor" xbee series 1.
The "Sensor" xbee is just an xbee series 1 on an adafruit xbee breakoutboard, it supplies 3.3v
to a switch, when the switch is depressed, ie, goes low, the packet changes that is sent.
This sketch checks that packet for a change and reports it to the serial monitor.
*/
int incomingByte=0; // to catch the incoming bytes
int PacketArray[14] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1}; // to store the validated xbee packet
int Alarms; // to store the number of times the alarm has been sent by the remote xbee.
NewSoftSerial xBee = NewSoftSerial(2, 3);
void setup()
{
Serial.begin(9600);
xBee.begin(9600);
Serial.println("Connected to Xbee Remote");
pinMode(10, OUTPUT);
}
void loop()
{
if (xBee.available()>13) { //checks to make sure that we have received at least one frame worth of bytes
incomingByte=xBee.read();
if(incomingByte== 0x7E){
PacketArray[0]=0x7E;
for(int i=1; i<14; i=i ++) {
PacketArray[i] = xBee.read();
}
}else{
int junk = xBee.read();
}
}
if(PacketArray[12]==0){
digitalWrite(10,HIGH);
Serial.print("Alarm detected on sensor ");
Serial.print(PacketArray[4], HEX);
Serial.print(PacketArray[5], HEX);
Serial.print("!");
Serial.println(" ");
}
else{
digitalWrite(10,LOW);
}
}
I can not explain why it was broadcasting api strings when it was not in api mode, but it does. Since changing to api it broadcasts only when it detects a change, and it broadcasts that same api string.
Who knows.. it works now and thats' all that matters to me.