Go Down

Topic: Arduino Xbee mesh network (Read 984 times) previous topic - next topic

vibe

Hi.

I am trying to build a mesh network and therefore all of my Xbee devices are in API mode (I believe that is the way it is done if I want to build a mesh network, correct me if I am wrong). For now I am just testing communication and I am using just 2 devices: a coordinator and a router (the network will have more routers and end devices later). Both Xbee's (and every Xbee I add to the network later) will be attached to an Arduino unit. The Arduino will generate some values and send them to the coordinator, so no sensors will be used because I am just trying to implement a communication protocol in the network. The Xbee.h library is used in all Arduino sketches. At this moment, I am trying to establish communication between the coordinator and the router, but without success. I am new to Xbee and Arduino and I am trying to establish a communication between them for the last few days without any success. I am not sure if my X-CTU configuration is wrong or if my code is not OK. In my current scenario (it is used only to check if communication works), the coordinator sends some data to the router and the router will print it on the serial monitor. Both of my devices are attached to my laptop via USB cabels (I am not sure if this can cause a problem). My code and configuration is the following:

Tansmitter - coordinator code

Code: [Select]
#include <XBee.h>
XBee xbee = XBee();
void setup() {
  Serial.begin(9600);
  xbee.setSerial(Serial);
}
void loop() {
  Serial.println("\n Transmitting");
  uint8_t data[] = {'H','e','l','l','o'};
  XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x409BB998);
//  addr64.setMsb(0x0013A200);//XXXXX -> Msb address of router/end node
//  addr64.setLsb(0x409BB998);//XXXXX -> Lsb address of router/end node
  ZBTxRequest zbTx = ZBTxRequest(addr64, data, sizeof(data));
  xbee.send(zbTx);
  delay(1000);
}


Receiver - router code
Code: [Select]
#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
void setup() {
  Serial.begin(9600);
  xbee.begin(Serial);
}
void loop() {
  Serial.println("receiving");
String sample;
  xbee.readPacket();
    if (xbee.getResponse().isAvailable()) {
      Serial.println(xbee.getResponse().getApiId());
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        xbee.getResponse().getZBRxResponse(rx);
        for (int i = 0; i < rx.getDataLength(); i++) {
          sample += (char)rx.getData(i);
        }
        Serial.println(sample);
      }
      else
      {
        Serial.println("something else");
      }
    }else if (xbee.getResponse().isError()) {
      Serial.println("Error reading packet.  Error code: "); 
      Serial.println(xbee.getResponse().getErrorCode());
  }
  delay(2000);
}



Coordinator configuration:

Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>

<data>
  <profile>
    <description_file>XB24-ZB_21A7.xml</description_file>
    <settings>
      <setting command="ID">1234</setting>
      <setting command="SC">FFFF</setting>
      <setting command="SD">3</setting>
      <setting command="ZS">0</setting>
      <setting command="NJ">FF</setting>
      <setting command="DH">0</setting>
      <setting command="DL">FFFF</setting>
      <setting command="NI">Coordinator</setting>
      <setting command="NH">1E</setting>
      <setting command="BH">0</setting>
      <setting command="AR">FF</setting>
      <setting command="DD">30000</setting>
      <setting command="NT">3C</setting>
      <setting command="NO">3</setting>
      <setting command="CR">3</setting>
      <setting command="PL">4</setting>
      <setting command="PM">1</setting>
      <setting command="EE">0</setting>
      <setting command="EO">0</setting>
      <setting command="KY"></setting>
      <setting command="NK"></setting>
      <setting command="BD">3</setting>
      <setting command="NB">0</setting>
      <setting command="SB">0</setting>
      <setting command="D7">1</setting>
      <setting command="D6">0</setting>
      <setting command="AP">2</setting>
      <setting command="AO">0</setting>
      <setting command="SP">20</setting>
      <setting command="SN">1</setting>
      <setting command="D0">1</setting>
      <setting command="D1">0</setting>
      <setting command="D2">0</setting>
      <setting command="D3">0</setting>
      <setting command="D4">0</setting>
      <setting command="D5">1</setting>
      <setting command="P0">1</setting>
      <setting command="P1">0</setting>
      <setting command="P2">0</setting>
      <setting command="PR">1FFF</setting>
      <setting command="LT">0</setting>
      <setting command="RP">28</setting>
      <setting command="DO">1</setting>
      <setting command="IR">0</setting>
      <setting command="IC">0</setting>
      <setting command="V+">0</setting>
    </settings>
  </profile>
</data>


Router configuration
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>

<data>
  <profile>
    <description_file>XB24-ZB_23A7.xml</description_file>
    <settings>
      <setting command="ID">1234</setting>
      <setting command="SC">FFFF</setting>
      <setting command="SD">3</setting>
      <setting command="ZS">0</setting>
      <setting command="NJ">FF</setting>
      <setting command="NW">0</setting>
      <setting command="JV">0</setting>
      <setting command="JN">0</setting>
      <setting command="DH">0</setting>
      <setting command="DL">0</setting>
      <setting command="NI">Router1</setting>
      <setting command="NH">1E</setting>
      <setting command="BH">0</setting>
      <setting command="AR">FF</setting>
      <setting command="DD">30000</setting>
      <setting command="NT">3C</setting>
      <setting command="NO">3</setting>
      <setting command="CR">3</setting>
      <setting command="PL">4</setting>
      <setting command="PM">1</setting>
      <setting command="EE">0</setting>
      <setting command="EO">0</setting>
      <setting command="KY"></setting>
      <setting command="BD">3</setting>
      <setting command="NB">0</setting>
      <setting command="SB">0</setting>
      <setting command="D7">1</setting>
      <setting command="D6">0</setting>
      <setting command="AP">2</setting>
      <setting command="AO">0</setting>
      <setting command="SM">0</setting>
      <setting command="SN">1</setting>
      <setting command="SO">0</setting>
      <setting command="SP">20</setting>
      <setting command="ST">1388</setting>
      <setting command="PO">0</setting>
      <setting command="D0">1</setting>
      <setting command="D1">0</setting>
      <setting command="D2">0</setting>
      <setting command="D3">0</setting>
      <setting command="D4">0</setting>
      <setting command="D5">1</setting>
      <setting command="P0">1</setting>
      <setting command="P1">0</setting>
      <setting command="P2">0</setting>
      <setting command="PR">1FFF</setting>
      <setting command="LT">0</setting>
      <setting command="RP">28</setting>
      <setting command="DO">1</setting>
      <setting command="IR">0</setting>
      <setting command="IC">0</setting>
      <setting command="V+">0</setting>
    </settings>
  </profile>
</data>


I am not sure if this is important or not, but when I attach my xbee+arduino router to my laptop, it does not print anything alhought there is a Serial.println command at the beginning of every loop iteration in the uploaded sketch. I have to upload my sketch every time if I want it to work. I don't have that problem with my coordinator.

Any suggestion or help will be appreciated.

Thanks in forward.

PaulS

Quote
correct me if I am wrong
You are. A mesh network can be set up with the XBees in AT mode or API mode. Given the code you have, AT mode is more appropriate.

DH and DL are the destination addresses. NO XBee should be using 0 or FFFF for either value.

Which XBee is the "Tansmitter" sending to?
The art of getting good answers lies in asking good questions.

MarkDerbyshire

#2
Jun 13, 2017, 03:58 pm Last Edit: Jun 13, 2017, 03:59 pm by MarkDerbyshire
Set the recieving Xbee to Coordinator.  Set the DH and DL values of the sending xbees to the recieving xbee SH and SL values.  I set the coordinator to API mode (2) and left the Transmitters (End Devices) in transparent mode.  The Xbees in my setup are S1

This is how my hive setup works with multiple Tx Xbees sending to one Rx Xbee connected to a Mega2560

vibe

#3
Jun 13, 2017, 04:01 pm Last Edit: Jun 13, 2017, 10:51 pm by vibe
In this case the "transmitter" is the coordinator and it is sending data to a router Xbee which has the already mentioned receiver arduino sketch. It's address is set in the request on transmitter side.

Code: [Select]

XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x409BB998);
//  addr64.setMsb(0x0013A200);//XXXXX -> Msb address of router/end node
//  addr64.setLsb(0x409BB998);//XXXXX -> Lsb address of router/end node



If I want to make a mesh, what values have to be set for DH and DL for each Xbee (coordinator, router
and end device). I assume that if I use AT mode for the router, then it's DH and DL have to be set to the coordinator address. Is it the same if the router is in API mode? I have googled and seen multiple different configuration scenarios for API mode and to be honest it really confuses me. In some cases the DH and DL were set as in my post and in others they were DH = 0 and DL = 1 for the coordinator, but none of that worked.

Quote
You are. A mesh network can be set up with the XBees in AT mode or API mode. Given the code you have, AT mode is more appropriate.
Should all Xbees be in AT mode including the coordinator? If so, then should the communication be established by using Xbee.h library?

By the way I am using series 2 Xbee's.

Quote
Set the recieving Xbee to Coordinator.
Why should I set the coordinator as the receiver? I guess I am wrong, but judging by your response it sounds to me as if the coordinator is only able to receive data. I want to establish bidirectional communication in my mesh. The coordinator will be periodically polling the generated values of each router and end device (broadcast). It should also be able to request (poll) the generated value/data of just one Xbee. That is why I tried to implement a scenario where the coordinator sends something to the router.

tteo

Hi! I am also facing the same issue. I tried both the code posted by vibe and the example given in the library.
Not sure what the problem is but I am configuring the XBEEs on XCTU; followed the settings given by the datasheet of Digi:
https://www.digi.com/resources/documentation/Digidocs/90001942-13/#concepts/c_libraries.htm%3FTocPath%3DXBee%2520API%2520mode%7CXBee%2520frame%2520exchange%7C_____7. The connections are fine on XCTU but when I try to move the modules to the Arduino it didn't work.

Can anyone tell me which settings to use or how did you all solve the problem? (I am using RX as coordinator and TX as router)

Go Up