Post a new topicPost a reply Page 1 of 2   [ 11 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Basic example of Sender & Receiver 802.15.4
PostPosted: Sun Mar 18, 2012 10:12 pm 

Joined: Tue Feb 21, 2012 9:53 am
Posts: 18
Hi everyone.

I need a basic example of sender and receiver using 802.15.4. I’ve two WaspMote and for this reason I would prefer two codes. One for sender and another one for receiver.

I tried with the following codes but I couldn’t communicate between them. The communication is UNICAST.

Sender code:

Code:
//MAC 0013A2004069185D #99 -> 0013A20040691859 #31

uint8_t PANID[2] ={0x99, 0x99};
uint8_t netAddr[2] ={0x12, 0x34};
uint8_t channel = 0x10;

packetXBee* paq_sent;
int8_t state = 0;
char* data;

char aux[200];
char* macHigh="          ";
char* macLow="           ";

void setup()
{
 
   USB.begin();
 
   // Inits the XBee_802_15_4 library
   xbee802.init(XBEE_802_15_4, FREQ2_4G, NORMAL);

   // Powers XBee
   xbee802.ON();
   
   delay(500);
   xbee802.setPAN(PANID);
   xbee802.setChannel(channel);
   xbee802.setOwnNetAddress(netAddr[0], netAddr[1]);
   xbee802.setNodeIdentifier("Transmisor");

  delay(1000);
}

void loop(){
 
  sprintf("En un lugar de la Mancha");
 
  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
  paq_sent->mode=UNICAST;
  paq_sent->packetID=0x52;
  paq_sent->opt=0;
  xbee802.setOriginParams(paq_sent, "0013A2004069185D", MAC_TYPE);
  xbee802.setDestinationParams(paq_sent, "0013A20040691859", aux, MAC_TYPE, DATA_ABSOLUTE);
  xbee802.sendXBee(paq_sent);

  Utils.blinkLEDs(100);

  if( !xbee802.error_TX ){
    XBee.println("ENVIO CORRECTO");
    Utils.blinkLEDs(100);
  }else{
    XBee.println("ERROR AL ENVIAR");
  }
 
  free(paq_sent);
  paq_sent=NULL;
  delay(5000);
}


Receiver code:

Code:
uint8_t PANID[2] ={0x99, 0x99};
uint8_t netAddr[2] ={0xFF, 0xFF};
uint8_t channel = 0x10;
long previous=0;

void setup()
{
   USB.begin();
 
   // Inits the XBee_802_15_4 library
   xbee802.init(XBEE_802_15_4, FREQ2_4G, NORMAL);
   
   // Powers XBee
   xbee802.ON();
   
   delay(500);
   xbee802.setPAN(PANID);
   xbee802.setChannel(channel);
   xbee802.setOwnNetAddress(netAddr[0], netAddr[1]);
   xbee802.setNodeIdentifier("Receptor");
   delay(1000);
}

void loop()
{
  previous=millis();
  while( (millis()-previous) < 20000 ){
   
    USB.println("Step 1");
   
    if (XBee.available()==1) { //It checks if there is available data waiting to be read.
     
        USB.println("Step 2"); //This part doesn't run
        XBee.println("XBee is available");
       
        xbee802.treatData();       
        if (!xbee802.error_RX) {
         
           while(xbee802.pos>0){
             Utils.blinkLEDs(100);
             USB.println("Ha llegado algo");
           }
           previous=millis();
         }
    }
  }
  delay(1000);
}



I hope you can help me.

Regards,
Jose Alberto.


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Mon Mar 19, 2012 9:39 am 

Joined: Tue Feb 21, 2012 9:53 am
Posts: 18
Sorry, in the original code appears (inside the loop):

sprintf(aux, "En un lugar de la Mancha");

instedad of:

sprintf("En un lugar de la Mancha")

This was a error when I wrote in the post.


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Mon Mar 19, 2012 9:43 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
javargas,

we were just answering you.

Glad to hear that!

Any other issues please let us know.

Regards.


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Mon Mar 19, 2012 10:20 am 

Joined: Tue Feb 21, 2012 9:53 am
Posts: 18
Hi libelium-dev.

It was a error. I corrected my post, because I made a mistake when I wrote the post.

I still have the same problem. I need two basic examples for communicate two WaspMote.

Thanks you.

Regards.


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Mon Mar 19, 2012 11:08 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
javargas,

Ok, then please refer to sending_receiving example provided with IDE (or tale a look here)

Try first in BROADCAST mode and then switch to UNICAST.

Take into account that both Xbee's must have same network parameters in order to achieve communication.

Besides that, take a look into waspmote checklist post, to avoid other causes.

Let us know if you are success.

Best Regards


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Mon Mar 19, 2012 1:17 pm 

Joined: Tue Feb 21, 2012 9:53 am
Posts: 18
libelium-dev,

Now, I'm using the examples provides with IDE:
    Sender: WaspXBee802_2_sending_receiving
    Receiver: WaspXBee802_2_sending_receivingB

And I tried 3 methods:

  • First: Without changing the code
  • Second: Changin the line (into the sender), because the documentation said that for broadcast.:
Code:
xbee802.setDestinationParams(paq_sent, "000000000000FFFF", data, MAC_TYPE, DATA_ABSOLUTE);

  • Third: Changin the line (into the sender), receiver's MAC:
Code:
xbee802.setDestinationParams(paq_sent, "0013A20040691859", data, MAC_TYPE, DATA_ABSOLUTE);


For all methods the output is the same (Sender's output):

Code:
~ RMYÿ~   RMYÿÿ ~   R     ÿÿ R # VxTest message!¥~   RMY4¹ok
~ RMYÿ~   RMYÿÿ ~   R     ÿÿ R # VxTest message!¥~   RMY4¹ok
~ RMYÿ~   RMYÿÿ ~   R     ÿÿ R # VxTest message!¥~   RMY4¹ok
~ RMYÿ~   RMYÿÿ ~   R     ÿÿ R # VxTest message!¥~   RMY4¹ok


Receiver's output is white.

What's the problem?

Thanks for everything!

Regards.


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Mon Mar 19, 2012 2:18 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
javargas,

About first method:
Without changing the code: Be sure you set same PANID, channel, encryption on both modules using Xctu tool or by AT commands. You can also use API functions.

Others should be ok.

Are you able to read parameters on both Xbee using X-ctu?

Did you try to switch xbees?

In order to test communication you can upload also example called "wasp_start_program_full_802 and place second Xbee into the gateway to see output.

Moreover, take a look into this post, It can be useful for you.

One tip: Please use edit/copy for forum when posting large codes (as said here) to make easier for us. Thank you.

Please try this things and let us know.

Regards


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Tue Mar 27, 2012 10:26 am 

Joined: Tue Feb 21, 2012 9:53 am
Posts: 18
Hi libelium-dev,

Quote:
In order to test communication you can upload also example called "wasp_start_program_full_802 and place second Xbee into the gateway to see output.


I tried this pogram and used a Waspmote and Gateway. Everything works fine. I can see the different XBee Mac, of course changing the modules to check.

Quote:
Moreover, take a look into this post, It can be useful for you.

I read the post and my Waspmote have the same PAID, channel and different netAddr. Same firmware. I used X-CTU to check.

Code:
uint8_t PANID[2] ={0x99, 0x99};
uint8_t netAddr[2] ={0x88, 0x88};
uint8_t channel = 0x18;

Code:
uint8_t PANID[2] ={0x99, 0x99};
uint8_t netAddr[2] ={0x12, 0x34};
uint8_t channel = 0x18;


Once tried everything, I came to the conclusion that the transmission is working properly but in the receiver I can't pass the step of if (XBee.available())

I attached the code again. The transmission shows ok if the receiver is turned on and error if the receiver is turned off, so that the transmitter works well.

What is the problem?.

Thanks for everything!

Regards.

Transmiter

Quote:
//MAC 0013A2004069185D #99 -> 0013A20040691859 #31

uint8_t PANID[2] ={0x99, 0x99};   // Mismo
uint8_t netAddr[2] ={0x12, 0x34}; // Diferente
uint8_t channel = 0x18;           // Mismo

packetXBee* paq_sent;
int8_t state = 0;
char* data;

char aux[200];
char* macHigh=" ";
char* macLow=" ";

void setup()
{
  
   USB.begin();
 
   // Inits the XBee_802_15_4 library
   xbee802.init(XBEE_802_15_4, FREQ2_4G, NORMAL);

   // Powers XBee
   xbee802.ON();
   
   delay(500);
   xbee802.setPAN(PANID);
   xbee802.setChannel(channel);
   xbee802.setOwnNetAddress(netAddr[0], netAddr[1]);
   xbee802.setNodeIdentifier("Transmisor");
   xbee802.writeValues();
      
   // Get the XBee MAC address
   int counter = 0;
   while(xbee802.getOwnMac()==1&&counter<4){
     xbee802.getOwnMac();
     counter++;
  }
  
  Utils.hex2str(xbee802.sourceMacHigh,macHigh,4);
  Utils.hex2str(xbee802.sourceMacLow,macLow,4);
      
  delay(1000);
}

void loop(){
  
  sprintf(aux,"-mac:%s%s Envio Realizado",macHigh,macLow);
  USB.println(aux);
  
  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
  paq_sent->mode=UNICAST;
  paq_sent->packetID=0x52;
  paq_sent->opt=0;
  xbee802.setOriginParams(paq_sent, "0013A2004069185D", MAC_TYPE);
  xbee802.setDestinationParams(paq_sent, "0013A20040691859", aux, MAC_TYPE, DATA_ABSOLUTE);
  xbee802.sendXBee(paq_sent);

  if( !xbee802.error_TX ){
    XBee.println("ENVIO CORRECTO");
    Utils.blinkLEDs(100);
  }else{
    XBee.println("ERROR AL ENVIAR");
  }
  
  Utils.blinkLEDs(100);
  
  free(paq_sent);
  paq_sent=NULL;
  delay(5000);
}




Receiver

Quote:
//MAC 0013A2004069185D #99 -> 0013A20040691859 #31

uint8_t PANID[2] ={0x99, 0x99};   // Mismo
uint8_t netAddr[2] ={0x88, 0x88}; // Diferente
uint8_t channel = 0x18;           // Mismo
long previous=0;

void setup()
{
   USB.begin();
 
   // Inits the XBee_802_15_4 library
   xbee802.init(XBEE_802_15_4, FREQ2_4G, NORMAL);
   
   // Powers XBee
   xbee802.ON();
   
   delay(500);
   xbee802.setPAN(PANID);
   xbee802.setChannel(channel);
   xbee802.setOwnNetAddress(netAddr[0], netAddr[1]);
   xbee802.setNodeIdentifier("Receptor");
   xbee802.writeValues();
   delay(1000);
}

void loop()
{
  previous=millis();
  while( (millis()-previous) < 20000 ){
    
    USB.println("Check 1"); //To check the running state
    
    if (XBee.available()) { //It checks if there is available data waiting to be read.
      
        USB.println("Check 2");
        XBee.println("XBee is available");
        
        xbee802.treatData();        
        if (!xbee802.error_RX) {
          
           USB.println("Check 3");
           while(xbee802.pos>0){
             Utils.blinkLEDs(100);
             USB.println("Ha llegado algo");
           }
           previous=millis();
         }
    }
  }
  delay(1000);
}



Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Tue Mar 27, 2012 1:54 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7516
Hi javargas,

first of all, did you try with the sending receiving example provided with the IDE and in the development section of the Libelium website, so we can see if there is any problem with the XBees?

One question about your receiver code, you are printing continuously a message ("CHECK1") in the while loop. This continuity of the printing in the UART may interfere with the XBee reception operation. Did you try your code removing it?

Regards.


Top
 Profile  
 
 Post subject: Re: Basic example of Sender & Receiver 802.15.4
PostPosted: Thu Apr 12, 2012 5:14 pm 

Joined: Tue Feb 21, 2012 9:53 am
Posts: 18
Hi ,libelium-dev

Everything has been solved, it was only necessary to rest on Easter holidays... I'm kidding :)

Problem is one of my modules XBee because if I remove this module and put another, all my programs work perfectly. But it is strange, this “wrong” module has the same version and all the correct parameters even some code if another sensor detects listening or not, as said before.

Would this XBee module has a problem? Should I send it to repair?

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 11 posts ]
Go to page 1, 2  Next


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use