i have a problem with my code, i was working with xbee series 1 s2c with my receiver and transmitter codes with sensors, it was working, but when i apply the same codes in a xbee pro series 2 s2c rpsma, it does not transmit any message from the xbee transmitter to the receiver, what can i change in the code to get the communication?
It impossibly to say because you don't show the code
Tx
#include <SoftwareSerial.h>
#include <XBee.h>
XBee xbee =XBee();
SoftwareSerial XBee(3,2);
float data;
void setup() {
Serial.begin(9600);
XBee.begin(9600);
}
void loop() {
int hum = analogRead(A0);
Serial.print('a');
Serial.print(hum);
Serial.print('b');
delay(100);
}
Rx
#include <SoftwareSerial.h>
SoftwareSerial XBee(3,2);
int i;
char digitos[6];
void setup() {
Serial.begin(9600);
XBee.begin(9600);
}
void nodo_1(){
if(digitos[0]=='a'){
Serial.print("Humedad: ");
for(i=1;i<6;i++){
if(digitos[i]!='b'){
Serial.print(digitos[i]);
}
else{
break;
}
}
Serial.println(" ");
}
}
void nodo_2(){
if(digitos[0]=='x'){
Serial.print("Sonido: ");
for(i=1;i<6;i++){
if(digitos[i]!='y'){
Serial.print(digitos[i]);
}
else{
break;
}
}
Serial.println(" ");
}
}
void loop() {
while(Serial.available()>0){
for(i=0;i<6;i++){
digitos[i]=Serial.read();
}
nodo_1();
nodo_2();
}
delay(100);
}
It only communicates with a normal xbee s2c, but when used with a xbee pro s2c it does not transmit.
Please edit your post to add code tags ("</>" editor button).
It sounds like the problem is with the "xbee pro s2c", and not with the code.
#include <SoftwareSerial.h>
#include <XBee.h>
XBee xbee =XBee();
SoftwareSerial XBee(3,2);
float data;
void setup() {
Serial.begin(9600);
XBee.begin(9600);
}
void loop() {
int hum = analogRead(A0);
Serial.print('a');
Serial.print(hum);
Serial.print('b');
delay(100);
}
#include <SoftwareSerial.h>
SoftwareSerial XBee(3,2);
int i;
char digitos[6];
void setup() {
Serial.begin(9600);
XBee.begin(9600);
}
void nodo_1(){
if(digitos[0]=='a'){
Serial.print("Humedad: ");
for(i=1;i<6;i++){
if(digitos[i]!='b'){
Serial.print(digitos[i]);
}
else{
break;
}
}
Serial.println(" ");
}
}
void nodo_2(){
if(digitos[0]=='x'){
Serial.print("Sonido: ");
for(i=1;i<6;i++){
if(digitos[i]!='y'){
Serial.print(digitos[i]);
}
else{
break;
}
}
Serial.println(" ");
}
}
void loop() {
while(Serial.available()>0){
for(i=0;i<6;i++){
digitos[i]=Serial.read();
}
nodo_1();
nodo_2();
}
delay(100);
}
I will try to do it with another xbee pro, if you can try it I would appreciate it.
In XCTU they appear to communicate and I can do the RSSI and I can see that it sends the packets, so I guess they work.
The code below has a very low probability of receiving valid message.
With Serial.available() you check for the presence of only one character in the buffer, but read all six from there. This means that if, for example, there are two characters in the buffer, they will be read to the beginning of the digitos[] array and the rest will be filled with garbage. Then the loop cycle will repeat and you will read the next 4 characters of the message - but at the same time you will overwrite the first two, because each time you start saving data from the zero array cell...
What would be the best way to solve this problem?
The xbee that receives does not indicate that it is receiving any message, I think that the code in the transmitter is missing something to be able to transmit it and the coordinator to receive it.
You are using S1 and S2 Xbees in the same PAN? It's been a couple of years since I played with these, are you certain that will work? I could be wrong though.
No, I only used series 2, but series 2c worked the code normally, I got all the messages, but when I used the xbee pro series 2c the messages did not arrive to the other xbee, I think it is the code, I ask for guidance.
I don't think they work the same way. One is for point to point communications the other for mesh networks I think.
I don't really remember all the details, give this a look
https://www.digi.com/resources/documentation/Digidocs/90001942-13/concepts/c_xbee_comparing_at_api_modes.htm?TocPath=How%20XBee%20devices%20work%7CSerial%20communication%7C_____2
Good luck
hallowed31, I followed your recommendation, removed node 2, and also configured the xbee modules to communicate with a point to point protocol, AT communication, still the same problem, it does not receive the messages from the other xbee.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.