Xbee Zigbee PRO S2C network

Wireless communications in Waspmote, topologies, node types...
libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Thu Sep 20, 2018 8:50 am

Hi,

The example sends a packet in the format of Libelium frames. If you want to send only "hello", try to use the following function

Code: Select all

error = xbeeZB.send( RX_ADDRESS, "hello");   
Regards

M_o7ammed
Posts: 24
Joined: Fri Sep 07, 2018 9:37 pm
Company: Khalifa University

Re: Xbee Zigbee PRO S2C network

Post by M_o7ammed » Wed Oct 10, 2018 5:09 pm

I have three Nodes ( A, B, C). Node B acts as a gateway. (Node A only sends to B, Node B receives data from node A and sends to node C, Node C receives data from Node C. I am stuck in Node B's code since I don't know how to save the value of the data sent from node A. I was able to send from node A to C directly but now I want node B to act as a gateway (receive & send).
Here are the codes for node A and C:

Node A:

Code: Select all

#include <WaspXBeeZB.h>
#include <WaspFrame.h>
#include "WaspSensorRadiation.h"
unsigned long CurrentTime=0;

char RX_ADDRESS[] = "0013A200416CE8B8"; //Node B address
void setup()
{  
  USB.ON();
  xbeeZB.ON(); 
  delay(3000);
  RadiationBoard.ON();
  #define RAD_INT 64 
  enableInterrupts(RAD_INT);
}


void loop()
{ 
  if (intFlag & RAD_INT)
    {
     CurrentTime=millis();
     send(CurrentTime);
        clearIntFlag();
        enableInterrupts(RAD_INT);
    }
} 

 void send (int a){
  char b[20];
  Utils.long2array(a, b); 
  xbeeZB.send(RX_ADDRESS,b);
  xbeeZB.send(RX_ADDRESS,"           ");
  
  }

Node C code

Code: Select all

#include <WaspXBeeZB.h>
#include <WaspFrame.h>
unsigned long received;

void setup()
{  
  USB.ON();
  xbeeZB.ON(); 
  delay(3000);
}
void loop()
{ 
 receive();
} 

void receive(){
  received = xbeeZB.receivePacketTimeout( 10000 );  
  if( received == 0 )  
    USB.println( xbeeZB._payload, xbeeZB._length);
  else
  {
    USB.print(F("Error receiving a packet:"));
    USB.println(received,DEC);     
  } 
  }
I tried to write a code for node B but I got stuck since i didnt know how the save the value to resend it

Code: Select all

#include <WaspXBeeZB.h>
#include <WaspFrame.h>
unsigned long received;

char RX_ADDRESS[] = "0013A2004127CE7E"; //Node C address
void setup()
{  
  USB.ON();
  xbeeZB.ON(); 
  delay(3000);
}
void loop()
{ 
 
 receive();

 
} 

void receive(){
  received = xbeeZB.receivePacketTimeout( 10000 );  
  if( received == 0 )  
    USB.println( xbeeZB._payload, xbeeZB._length);
  else
  {
    USB.print(F("Error receiving a packet:"));
    USB.println(received,DEC);     
  } 
  }
  void send (int a){
  char b[20];
  Utils.long2array(a, b); 
  xbeeZB.send(RX_ADDRESS,b);
  xbeeZB.send(RX_ADDRESS,"           ");
  
  }
How can I save the value sent from Node A and send it to node C from B?

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Thu Oct 11, 2018 11:13 am

Hi,

Received data is saved in xbeeZB._payload variable, so you can try to send that variable as follow

Code: Select all

error = xbeeZB.send( RX_ADDRESS, (char*) xbeeZB._payload );
Regards

M_o7ammed
Posts: 24
Joined: Fri Sep 07, 2018 9:37 pm
Company: Khalifa University

Re: Xbee Zigbee PRO S2C network

Post by M_o7ammed » Sun Oct 14, 2018 11:54 am

I can send the data now successfully. However, there is something with the values. I am sending millis() which is supposed to be negative but i am getting values between -32768 and 32768. It starts from 0 to 32768, then from -32768 to 0 and so on.

M_o7ammed
Posts: 24
Joined: Fri Sep 07, 2018 9:37 pm
Company: Khalifa University

Re: Xbee Zigbee PRO S2C network

Post by M_o7ammed » Sun Oct 14, 2018 11:56 am

ignore the last post....

I can send the data now successfully. However, there is something wrong with the values. I am sending millis() which is supposed to be positive but i am getting values between -32768 and 32768. It starts from 0 to 32768, then from -32768 to 0 and so on *

M_o7ammed
Posts: 24
Joined: Fri Sep 07, 2018 9:37 pm
Company: Khalifa University

Re: Xbee Zigbee PRO S2C network

Post by M_o7ammed » Sun Oct 14, 2018 12:50 pm

Also, i keep getting
H# in node B (the gateway), it keeps restarting the program causing delay

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Mon Oct 15, 2018 10:14 am

Hi,

What is the battery level of the devices? The nodes will restart if the battery level is low or it isn't connected.

How do you use millis() function? Here you can find a example code
http://www.libelium.com/development/was ... -function/

Regards

M_o7ammed
Posts: 24
Joined: Fri Sep 07, 2018 9:37 pm
Company: Khalifa University

Re: Xbee Zigbee PRO S2C network

Post by M_o7ammed » Tue Oct 16, 2018 12:25 am

It is getting power from the pc. (USB)

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Tue Oct 16, 2018 9:07 am

Hi,

The USB can't supply the current needed to power the radio modules, waspmote needs the battery to work properly.

Regards

M_o7ammed
Posts: 24
Joined: Fri Sep 07, 2018 9:37 pm
Company: Khalifa University

Re: Xbee Zigbee PRO S2C network

Post by M_o7ammed » Thu Oct 18, 2018 12:53 am

Hello, i am using this code to send the time ( millis() ) using zigbee.

Code: Select all

#include <WaspXBeeZB.h>
#include "WaspSensorRadiation.h"
unsigned long long CurrentTime=0;
 char RX_ADDRESS[]= "0013A2004127CE7E";
 //char RX_ADDRESS[]= "0013A200415D8BC6";
void setup()
{  
  USB.ON();
  xbeeZB.ON(); 
  delay(3000);
  RadiationBoard.ON();
  #define RAD_INT 64 
  enableInterrupts(RAD_INT);
}
void loop()
{ 
  if (intFlag & RAD_INT)
    {
     CurrentTime=millis();
     send(CurrentTime);
        clearIntFlag();
        enableInterrupts(RAD_INT);
    }
} 
 void send (int a){
  char b[30];
  Utils.long2array(a, b); 
  xbeeZB.send(RX_ADDRESS,"  B "); 
  xbeeZB.send(RX_ADDRESS,b); 
  }
The function send converts the value of millis from long to string which can be sent using zigbee. However, the values i get at the receiver are between -32768 and +32768. Is there a problem with the conversion code? or what else can I do to get the right values for millis() which start from 0 ms and end at 2^32 ms ?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest