Hi,
I need to make a wireless network with XBee's and Arduino, I'll be using a Mesh topology network. I'm using XBee Series 1 with the new Mesh Firmware.
The problem is that I need to set an address for each XBee without having to configure each one, I mean I just want every Arduino to set a unique address to its XBee automatically everytime they are powered on.
For that I was planning to use AT commands to get the low part of the serial number of each XBee and set it as node ID. It works fine sometimes but not always. If I plug the arduino it works most of the time but many times if I reset it or just unplug and plug again it won't do it right.
I'm tired of looking at the code and trying to find the problem but I have been imposible for me to find the problem.
I appreciate it if anyone could point me in the right direcction. My guess is that the problem is in the arrays declaration or size or something like that but what I can't understand is how the same arduino with the same code works sometimes and sometimes doesn't.
Thank you!
The code:
#include <stdio.h>
#include <string.h>
char datoRX[11]= "01234567x" ;
char datoTX[15]={"0123456789012x"};
int i;
void setup(){
Serial.begin(115200);
delay(10000);
setNI();
}
void loop(){
}
void setNI(){
int i=0;
Serial.flush();
Serial.print("+++");
//Wating to get the "OK\r" response from the XBee
char thisByte = 0;
while (thisByte != '\r') {
if (Serial.available() > 0) {
thisByte = Serial.read();
}
}
thisByte='0';
i=0;
//Getting the low part of the Serial Number
Serial.flush();
Serial.print("ATSL\r");
while (thisByte != '\r') {
if (Serial.available() > 0) {
thisByte=Serial.read();
datoRX*=thisByte;*
-
i++;*
-
delay(20);*
-
}*
-
}*
-
datoRX[11]='\0';*
-
strcat(datoTX,"ATNI");*
-
strcat(datoTX,datoRX);*
-
for (i=0;i<=14;i++){ *
_ Serial.print(datoTX*); //Configuring the SN as NI._
_ delay(20);_
_ }_
_ digitalWrite(13,HIGH);*_
}