Xbee Zigbee PRO S2C network

Wireless communications in Waspmote, topologies, node types...
M_o7ammed
Posts: 24
Joined: Fri Sep 07, 2018 9:37 pm
Company: Khalifa University

Xbee Zigbee PRO S2C network

Post by M_o7ammed » Thu Sep 13, 2018 12:37 pm

Hello, I've been trying to establish a network of waspmotes using zigbee PRO S2C.
I tried to do it using two waspmotes. I configured both modules in XCTU by a gateway to be end devices using two laptops and both of them were able to transmit and receive. Then I connected the modules on the waspmote microcontrollers and uploaded the built in examples ZB_03_send_packets on one of the waspmotes and ZB_03_receive_packets on the other, and I put the correct address of the receiver (RX_ADDRESS[] = "0013A2004127CE7E") in the sending code. However, when I try to send something through the serial monitor, i keep getting "operating 64-b PAN ID: 0000000000000000"
How can I fix this and make both waspmotes as transmitter and receiver?

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

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Fri Sep 14, 2018 8:58 am

Hi,

Did you configure a node as coordinator and the another as router? A zigbee network must have a coordinator, the the router must be connected to the coordinator network. So you have to upload the following example code to the router device to be connected to the coordinador node, and then you can use the example codes to send and receive data
http://www.libelium.com/development/was ... n-network/

Also you can find more information in the ZigBee Networking Guide
http://www.libelium.com/downloads/docum ... _guide.pdf

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 Sep 16, 2018 1:13 pm

I set one of the zigbees as a coordinator and the other as a router. I set the PAN ID to be 0xFFFFFFFFFFFFFFFF for both. They were able to send and receive text using XCTU. After that I connected the router to a waspmote and the coordinator was still on the XCTU. I uploaded the code "ZB 02a: Join known network" to the waspmote and configured the PAN ID but I got this on the serial monitor.
H#
ZB_02a example
1. Error while disabling Coordinator mode
2. Error while setting PANID
3. Error while setting 'Scanning channels'

operatingPAN: 0000
extendedPAN: 0000000000000000
channel: 00

And on the XCTU console log I get gibberish output

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

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Mon Sep 17, 2018 10:22 am

Hi,

Is the baudrate of the module configured to 115200 bauds?

Please upload the following code to the node in order to check if the Zigbee module is detected. Copy here the output through the serial monitor

Code: Select all

/*
    ------ Waspmote factory default code ------

    Explanation: Send basic parameters through the corresponding
    radio module.

    Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
    http://www.libelium.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Version:         3.8
    Design:          David Gascón
    Implementation:  Yuri Carmona, Javier Siscart
*/

// Include libraries
#include <WaspXBee802.h>
#include <WaspXBeeZB.h>
#include <WaspFrame.h>


// Define the Waspmote default ID
char node_id[] = "node_id";

// Define the authentication key
char key_access[] = "LIBELIUM";

// Declare global variables
char macHigh[11];
char macLow[11];
char filename[] = "TEST_SD.TXT";
uint8_t lora_error;
uint8_t lora_status;
uint8_t xbee_error;
uint8_t response;

// Broadcast address
char destination[] = "000000000000FFFF";

// Declare the XBEE_type
// 0 - NO radio detected
// 1 - 802.15.4
// 2 - 900 MHz - 868 MHz
// 3 - DigiMesh
// 4 - XBee ZB
// 5 - 900 MHz Intl
// 6 - LoRa (deprecated)
// 7 - LoRaWAN
// 8 - Sigfox
// 9 - WiFi PRO
// 10 - 4G
int radio_type = 0;

// Declare the xbee type in the case there is an XBee module
uint8_t firmware[4];

uint8_t errorFlag = 0;

void setup()
{
  USB.ON();
  USB.println(F("Starting Waspmote factory default program"));

  ///////////////////////////////////////////////////////////////////
  // Battery checking
  ///////////////////////////////////////////////////////////////////

  uint8_t battery = PWR.getBatteryLevel();

  if (battery == 0)
  {
    USB.println(F("************************************************"));
    USB.print(F("ERROR: Battery issue. Battery level (%): "));
    USB.println(battery, DEC);
    USB.println(F("************************************************"));
    errorFlag |= 1<<0x01;
  }


  ///////////////////////////////////////////////////////////////////
  // 1. Serial ID
  ///////////////////////////////////////////////////////////////////

  // Show '_serial_id' stored by the API when powering up
  USB.print(F("Global variable '_serial_id':"));
  USB.printHex(_serial_id[0]);
  USB.printHex(_serial_id[1]);
  USB.printHex(_serial_id[2]);
  USB.printHex(_serial_id[3]);
  USB.printHex(_serial_id[4]);
  USB.printHex(_serial_id[5]);
  USB.printHex(_serial_id[6]);
  USB.printHex(_serial_id[7]);
  USB.println();

  // Reading the serial number
  Utils.readSerialID();
  USB.print(F("Waspmote serial ID: "));
  USB.printHex(_serial_id[0]);
  USB.printHex(_serial_id[1]);
  USB.printHex(_serial_id[2]);
  USB.printHex(_serial_id[3]);
  USB.printHex(_serial_id[4]);
  USB.printHex(_serial_id[5]);
  USB.printHex(_serial_id[6]);
  USB.printHex(_serial_id[7]);
  USB.println();


  ///////////////////////////////////////////////////////////////////
  // 2. Boards ON
  ///////////////////////////////////////////////////////////////////
  PWR.setSensorPower(SENS_3V3, SENS_ON);


  /////////////////////////////////////////////////////////////
  // 3. Test SD
  /////////////////////////////////////////////////////////////
  SD.ON();
  if (SD.isSD())
  {
    SD.del(filename);
    SD.create(filename);
    if (SD.writeSD(filename, "Test SD", 0))
    {
      USB.println(F("SD OK"));
    }
    else
    {
      USB.println(F("Error SD"));
      errorFlag |= 1<<0x02;
    }
  }
  else
  {
    USB.println(F("No SD card detected"));
    errorFlag |= 1<<0x03;
  }
  SD.del(filename);
  USB.println();


  /////////////////////////////////////////////////////////////
  // 4. Store key access in EEPROM
  /////////////////////////////////////////////////////////////
  Utils.setAuthKey(key_access);


  /////////////////////////////////////////////////////////////
  // 5. Init RTC and ACC
  /////////////////////////////////////////////////////////////
  RTC.ON();
  ACC.ON();


  /////////////////////////////////////////////////////////////
  // 6. Set Waspmote setting for XBee module for first time.
  // (baudrate at 115200 and API mode enabled)
  /////////////////////////////////////////////////////////////
  // Note: Only valid for SOCKET 0
  xbee802.ON();

  Utils.setMuxSocket0();
  delay(500);
  beginSerial(9600, 0);
  printString("+++", 0);
  delay(2000);
  printString("ATBD7,AP2,WR,CN\r\n", 0);
  delay(500);

  xbeeZB.OFF();
  delay(500);
  xbeeZB.ON();

  // In case of Zigbee modules:
  // XBee command for 115200bps --> ATBD7
  uint8_t ATBD7[] = { 0x7E, 0x00, 0x05, 0x08, 0x01, 0x42, 0x44, 0x07, 0x69 };
  // XBee command for API mode --> ATAP2
  uint8_t ATAP2[] = { 0x7E, 0x00, 0x05, 0x08, 0x01, 0x41, 0x50, 0x02, 0x63 };
  // XBee command for saving config --> ATWR
  uint8_t ATWR[] = { 0x7E, 0x00, 0x04, 0x08, 0x01, 0x57, 0x52, 0x4D };

  for (uint8_t i = 0; i < 9; i++)
  {
    printByte(ATBD7[i], SOCKET0);
  }
  delay(150);
  closeSerial(SOCKET0);
  delay(200);
  beginSerial(115200, SOCKET0);
  for (uint8_t i = 0; i < 9; i++)
  {
    printByte(ATAP2[i], SOCKET0);
  }
  delay(150);
  for (uint8_t i = 0; i < 8; i++)
  {
    printByte(ATWR[i], SOCKET0);
  }
  delay(150);
  closeSerial(SOCKET0);


  /////////////////////////////////////////////////////////////
  // 7. LEDs management
  /////////////////////////////////////////////////////////////
  Utils.setLED(LED0, LED_OFF);
  Utils.setLED(LED1, LED_OFF);
  for (int i = 0 ; i < 4 ; i++)
  {
    Utils.blinkLEDs(100);
  }


  /////////////////////////////////////////////////////////////
  // 8. Identify the radio connected to Waspmote
  //
  //  Possibilities:
  //   - XBee 802.15.4
  //   - XBee 868LP
  //   - XBee 900HP
  //   - XBee DigiMesh
  //   - XBee ZigBee
  //   - LoRa (SX1272) (deprecated)
  //   - LoRaWAN (RN2483 or RN2903)
  //   - Sigfox (TD1207 or TD1508)
  //   - WiFi PRO
  //   - 4G (in SOCKET1)
  /////////////////////////////////////////////////////////////
  uint8_t answer;
  radio_type = 0;



  /////////////////////////////////////////////////////////////
  // 8.1. check for XBee module
  /////////////////////////////////////////////////////////////

  // define object for UART0
  WaspUART uart = WaspUART();

  // init object in SOCKET0
  uart.setUART(SOCKET0);

  // select multiplexer
  Utils.setMuxSocket0();

  // begin serial communication
  uart.beginUART();

  // power on the socket
  PWR.powerSocket(SOCKET0, HIGH);
  delay(500);
  serialFlush(SOCKET0);

  // check for XBees in SOCKET0
  uint8_t cmd_xbee[] = {0x7E, 0x00 , 0x04 , 0x08 , 0x01 , 0x56 , 0x52 , 0x4E};

  // send command & receive answer
  uart.sendCommand(cmd_xbee, sizeof(cmd_xbee));
  uart.readBuffer(100);

  // check response: 7E00078801565200xxxx??
  if (uart._length > 0)
  {
    if ((uart._buffer[0] == 0x7E)
        &&  (uart._buffer[1] == 0x00)
        &&  (uart._buffer[3] == 0x88)
        &&  (uart._buffer[4] == 0x01)
        &&  (uart._buffer[5] == 0x56)
        &&  (uart._buffer[6] == 0x52)
        &&  (uart._buffer[7] == 0x00))
    {

      USB.println(F("XBee module is plugged on socket 0:"));

      /*
        USB.print(F("XBee module in SOCKET0. Firmware: "));
        USB.printHex(uart._buffer[8]);
        USB.printHex(uart._buffer[9]);
        USB.println();
      */

      firmware[0] = uart._buffer[8];
      firmware[1] = uart._buffer[9];
      firmware[2] = uart._buffer[10];
      firmware[3] = uart._buffer[11];

      /////////////////////////////////
      // Get the XBee firmware version
      /////////////////////////////////

      // Set the XBee firmware type depending ont he previous response
      if ((firmware[0] < 0x20) && (firmware[1] > 0x80))
      {
        radio_type = 1; // 802.15.4
        USB.println(F("--> XBee type: 802.15.4"));
      }
      else if ((firmware[0] < 0x20) && (firmware[1] > 0x00))
      {
        radio_type = 2; // 868MHz - 900MHz

        xbee802.OFF();
        xbee802.ON();

        // send Hardware Serial command
        if (!xbee802.sendCommandAT("HS#"))
        {
          // USB.printHexln(xbee802.commandAT, 3);
        }

        // check for XBee 900HP
        if (xbee802.commandAT[0] == 3)
        {
          USB.println(F("--> XBee type: 900HP"));

          // check for available frequencies:
          // US: 00FFFFFFFFFFFFFFFF
          // BR: 00FFFFFFFE00000FFF
          // AU: 00FFFFFFFE00000000
          if (!xbee802.sendCommandAT("AF#"))
          {
            //USB.printHexln(xbee802.commandAT, 16);
            if ((xbee802.commandAT[1] == 0xFF)
                && (xbee802.commandAT[2] == 0xFF)
                && (xbee802.commandAT[3] == 0xFF)
                && (xbee802.commandAT[4] == 0xFF)
                && (xbee802.commandAT[5] == 0xFF)
                && (xbee802.commandAT[6] == 0xFF)
                && (xbee802.commandAT[7] == 0xFF)
                && (xbee802.commandAT[8] == 0xFF))
            {
              USB.println(F("--> Hardware serie: USA"));
            }
            else if ((xbee802.commandAT[1] == 0xFF)
                     && (xbee802.commandAT[2] == 0xFF)
                     && (xbee802.commandAT[3] == 0xFF)
                     && (xbee802.commandAT[4] == 0xFE)
                     && (xbee802.commandAT[5] == 0x00)
                     && (xbee802.commandAT[6] == 0x00)
                     && (xbee802.commandAT[7] == 0x0F)
                     && (xbee802.commandAT[8] == 0xFF))
            {
              USB.println(F("--> Hardware serie: BRAZIL"));
            }
            else if ((xbee802.commandAT[1] == 0xFF)
                     && (xbee802.commandAT[2] == 0xFF)
                     && (xbee802.commandAT[3] == 0xFF)
                     && (xbee802.commandAT[4] == 0xFE)
                     && (xbee802.commandAT[5] == 0x00)
                     && (xbee802.commandAT[6] == 0x00)
                     && (xbee802.commandAT[7] == 0x00)
                     && (xbee802.commandAT[8] == 0x00))
            {
              USB.println(F("--> Hardware serie: AUSTRALIA"));
            }
          }
          else
          {
            USB.println(F("--> Hardware serie: ERROR"));
            errorFlag |= 1<<0x04;
          }
        }
        // check for XBee 868LP
        else if (xbee802.commandAT[0] == 8)
        {
          USB.println(F("--> XBee type: 868LP"));
        }

      }
      else if (firmware[0] >= 0x80)
      {
        radio_type = 3; // DigiMesh
        USB.println(F("--> XBee type: DigiMesh"));
      }
      else if (((firmware[0] >= 0x20) && (firmware[1] < 0xB0)) ||
               ((firmware[0] == 0x70) && (firmware[1] == 0x5B)) )
      {
        radio_type = 4; //ZB
        USB.println(F("--> XBee type: ZigBee"));
      }
      else if (firmware[0] == 0x00 && firmware[1] >= 0x02)
      {
        radio_type = 5; // 900 MHz Intl
        USB.println(F("--> XBee type: 900 International"));
      }
      else
      {
        radio_type = 0;
      }

      /////////////////////////////////////////////////////////////
      // Get the XBee MAC address
      /////////////////////////////////////////////////////////////
      if (radio_type != 0)
      {
        xbee802.OFF();
        delay(1000);
        xbee802.ON();
        delay(1000);
        xbee802.flush();

        // Get the XBee MAC address
        int counter = 0;
        while ((xbee802.getOwnMac() != 0) && (counter < 12))
        {
          xbee802.getOwnMac();
          counter++;
        }


        // convert mac address from array to string
        Utils.hex2str(xbee802.sourceMacHigh, macHigh, 4);
        Utils.hex2str(xbee802.sourceMacLow,  macLow,  4);

        // Get the XBee MAC address
        while ((xbee802.getOwnMac() != 0) && (counter < 12))
        {
          xbee802.getOwnMac();
          counter++;
        }

        // convert mac address from array to string
        Utils.hex2str(xbee802.sourceMacHigh, macHigh, 4);
        Utils.hex2str(xbee802.sourceMacLow,  macLow,  4);

        USB.print(F("--> MAC address: "));
        USB.print(macHigh);
        USB.println(macLow);

      }

      if (radio_type < 5)
      {
        USB.print(F("--> Firmware version: "));
        USB.print(firmware[0], HEX);
        USB.println(firmware[1], HEX);
      }

      if (radio_type == 5)
      {
        USB.print(F("--> Firmware version: "));
        USB.printHex(firmware[0]);
        USB.printHex(firmware[1]);
        USB.printHex(firmware[2]);
        USB.printHex(firmware[3]);
        USB.println();
      }
    }
  }


  /////////////////////////////////////////////////////////////
  // 8.2. check for LORAWAN module
  /////////////////////////////////////////////////////////////
  if (radio_type == 0)
  {
    // init object in SOCKET0
    xbee802.OFF();
    uart.setUART(SOCKET0);
    uart.setBaudrate(57600);

    // switch module OFF
    uart.closeUART();
    Utils.setMuxUSB();
    PWR.powerSocket(SOCKET0, LOW);

    delay(500);

    // select multiplexer
    Utils.setMuxSocket0();

    // begin serial communication
    uart.beginUART();

    // power on the socket
    PWR.powerSocket(SOCKET0, HIGH);
    delay(500);
    serialFlush(SOCKET0);

    // check for XBees in SOCKET0
    static char cmd_lorawan[] = "sys get ver\r\n";

    // send command & receive answer
    answer = uart.sendCommand((char*)cmd_lorawan, "\r\n",1000);

    char vers[9], vers_in[21];
    memset(vers,0x00,sizeof(vers));
    memset(vers_in,0x00,sizeof(vers_in));
    memcpy (vers,uart._buffer,8);
    memcpy (vers_in,uart._buffer,20);

    // send command & receive answer
    uint8_t dev_eui_answer = uart.sendCommand((char*)"mac get deveui\r\n", "\r\n", 1000);

    // check response:
    if (strcmp(vers,"RN2483 0")==0 || strcmp(vers,"RN2483 1")==0)
    {
      USB.println(F("LoRaWAN module is plugged on socket 0:"));
      USB.println(F("--> Hardware serie: LoRaWAN EU"));
      if (dev_eui_answer == 1)
      {
        USB.print(F("--> Device EUI: "));
        USB.print(uart._buffer, uart._length);
      }
      radio_type = 7;
    }
    else if (strcmp(vers,"RN2903 0")==0 || strcmp(vers,"RN2903 1")==0)
    {
      if (strcmp(vers_in,"RN2903 1.0.5C_rc1-In")==0)
      {
        USB.println(F("LoRaWAN module is plugged on socket 0:"));
        USB.println(F("--> Hardware serie: LoRaWAN IN"));
        if (dev_eui_answer == 1)
        {
          USB.print(F("--> Device EUI: "));
          USB.print(uart._buffer, uart._length);
        }
      }
      else
      {
        USB.println(F("LoRaWAN module is plugged on socket 0:"));
        USB.println(F("--> Hardware serie: LoRaWAN US"));
        if (dev_eui_answer == 1)
        {
          USB.print(F("--> Device EUI: "));
          USB.print(uart._buffer, uart._length);
        }
      }
      radio_type = 7;
    }
    else if (strcmp(vers,"RN2903 S")==0)
    {
      USB.println(F("LoRaWAN module is plugged on socket 0:"));
      USB.println(F("--> Hardware serie: LoRaWAN AU"));
      if (dev_eui_answer == 1)
      {
        USB.print(F("--> Device EUI: "));
        USB.print(uart._buffer, uart._length);
      }
      radio_type = 7;
    }
  }



  /////////////////////////////////////////////////////////////
  // 8.4. check for SIGFOX module
  /////////////////////////////////////////////////////////////
  if (radio_type == 0)
  {
    // init object in SOCKET0
    uart.setUART(SOCKET0);
    uart.setBaudrate(9600);

    // switch module OFF
    uart.closeUART();
    Utils.setMuxUSB();
    PWR.powerSocket(SOCKET0, LOW);

    delay(500);

    // select multiplexer
    Utils.setMuxSocket0();

    // begin serial communication
    uart.beginUART();

    // power on the socket
    PWR.powerSocket(SOCKET0, HIGH);
    delay(6000);
    serialFlush(SOCKET0);

    // check for XBees in SOCKET0
    static char cmd_sigfox[] = "AT&V\r";

    // send command & receive answer
    answer = uart.sendCommand((char*)cmd_sigfox, "TD1207", "TD1508", 1000);
    char* pch;
    char sigfox_id[8];
    
    // get IMEI
    if (answer != 0)
    {
      // send command & receive answer
      delay(1000);
      response = uart.sendCommand((char*)"ATI7\r", "\r\n", 1000);

      uart. waitFor("\r\n", 1000);
      if (response == 1)
      {
        pch = strtok( (char*)uart._buffer, "\r\n");
      }
    }

    memcpy(sigfox_id,pch,sizeof(sigfox_id));
    
    // check response:
    if (answer == 1)
    {
      USB.println(F("SIGFOX module is plugged on socket 0:"));
      USB.println(F("--> Hardware serie: Sigfox EU"));
      USB.print(F("--> Serial Number: "));
      USB.println(sigfox_id);
      radio_type = 8;
    }
    else if (answer == 2)
    {
      response = uart.sendCommand((char*)"ATS307?\r","1", "63", 1000);
      USB.println(F("SIGFOX module is plugged on socket 0:"));
      if (response == 1)
      {
        USB.println(F("--> Hardware serie: Sigfox US"));
      }
      else if (response == 2)
      {
        USB.println(F("--> Hardware serie: Sigfox AU"));
      }
      
      USB.print(F("--> Serial Number: "));
      USB.println(sigfox_id);
      radio_type = 8;
    }
  }




  /////////////////////////////////////////////////////////////
  // 8.5. check for WIFI module
  /////////////////////////////////////////////////////////////
  if (radio_type == 0)
  {
    // init object in SOCKET0
    uart.setUART(SOCKET0);
    uart.setBaudrate(115200);

    // switch module OFF
    uart.closeUART();
    Utils.setMuxUSB();
    PWR.powerSocket(SOCKET0, LOW);

    delay(500);

    // select multiplexer
    Utils.setMuxSocket0();

    // begin serial communication
    uart.beginUART();

    // power on the socket
    PWR.powerSocket(SOCKET0, HIGH);
    delay(3000);
    serialFlush(SOCKET0);

    // check for XBees in SOCKET0
    static char cmd_wifi[] = "AT+i\r";

    // send command & receive answer
    answer = uart.sendCommand((char*)cmd_wifi, "I/OK", 1000);

    // check response:
    if (answer == 1)
    {
      USB.println(F("WIFI PRO module is plugged on socket 0"));
      radio_type = 9;
    }
  }



  /////////////////////////////////////////////////////////////
  // 8.6. check for 4G module
  /////////////////////////////////////////////////////////////
  if (radio_type == 0)
  {
    // init object in SOCKET1
    uart.setUART(SOCKET1);
    uart.setBaudrate(115200);

    // switch module OFF
    uart.closeUART();
    pinMode(GPRS_PW, OUTPUT);
    digitalWrite(GPRS_PW, LOW);
    delay(500);

    // select multiplexer
    Utils.setMuxSocket1();

    // begin serial communication
    uart.beginUART();

    // Power on the module
    digitalWrite(GPRS_PW, LOW);
    delay(500);
    digitalWrite(GPRS_PW, HIGH);
    delay(11000);
    serialFlush(SOCKET1);

    // send command & receive answer
    answer = uart.sendCommand((char*)"AT#CGMM\r", "LE910-EU",  "LE910-NAG", "LE910-AU", 1000);
    char imei[50];
    memset(imei, 0x00, sizeof(imei));

    // send CPIN command
    uint8_t pin_ready;
    pin_ready = uart.sendCommand((char*)"AT+CPIN?\r", "+CPIN: READY", "ERROR", 1000);
    if((answer != 0) && (pin_ready != 1)){
      errorFlag |= 1<<0x05;
    }

    // get IMEI
    if (answer != 0)
    {
      // send command & receive answer
      response = uart.sendCommand((char*)"AT#CGSN\r", "OK", 1000);

      if (response == 1)
      {        
        strcpy(imei, strtok( (char*)uart._buffer, "AT#CGSN: \r\n"));
      }
    }

    // check response:
    if (answer == 1)
    {
      USB.println(F("4G module is plugged on socket 1:"));
      
      answer = uart.sendCommand((char*)"AT#CGMM\r", "LE910-EUG",  "LE910-EU V2", 1000);
      if (answer == 1)
        USB.println(F("--> Hardware serie: LE910-EUG (4G EUROPE/BRAZIL)"));
      else if (answer == 2)
        USB.println(F("--> Hardware serie: LE910-EU V2 (4G EUROPE/BRAZIL)"));

      if (pin_ready == 1)
        USB.println(F("--> SIM card: OK"));
      else
        USB.println(F("--> SIM card: ERROR"));
        
      USB.print(F("--> IMEI: "));
      USB.println(imei);
      radio_type = 10;
    }
    else if (answer == 2)
    {
      USB.println(F("4G module is plugged on socket 1:"));
      USB.println(F("--> Hardware serie: LE910-NAG (4G USA)"));
      if (pin_ready == 1) USB.println(F("--> SIM card: OK"));
      else USB.println(F("--> SIM card: ERROR"));
      USB.print(F("--> IMEI: "));
      USB.println(imei);
      radio_type = 10;
    }
    else if (answer == 3)
    {
      USB.println(F("4G module is plugged on socket 1:"));
      USB.println(F("--> Hardware serie: LE910-AU (4G AUSTRALIA)"));
      if (pin_ready == 1) USB.println(F("--> SIM card: OK"));
      else USB.println(F("--> SIM card: ERROR"));
      USB.print(F("--> IMEI: "));
      USB.println(imei);
      radio_type = 10;
    }
  }



  /////////////////////////////////////////////////////////////
  // 9. Check for modules into socket 1
  /////////////////////////////////////////////////////////////

  if (radio_type == 0)
  {
    USB.println(F("No radio module detected into socket 0\n"));
    
    /////////////////////////////////////////////////////////////
    // 9.1 Set Waspmote setting for XBee module for first time.
    // (baudrate at 115200 and API mode enabled)
    /////////////////////////////////////////////////////////////
    closeSerial(SOCKET1);
    delay(500);
    xbee802.ON(SOCKET1);

    Utils.setMuxSocket1();
    delay(500);
    beginSerial(9600, 1);
    printString("+++", 1);
    delay(2000);
    printString("ATBD7,AP2,WR,CN\r\n", 1);
    delay(500);

    xbee802.OFF();
    delay(500);
    xbeeZB.ON(SOCKET1);

    // In case of Zigbee modules:
    // XBee command for 115200bps --> ATBD7
    uint8_t ATBD7[] = { 0x7E, 0x00, 0x05, 0x08, 0x01, 0x42, 0x44, 0x07, 0x69 };
    // XBee command for API mode --> ATAP2
    uint8_t ATAP2[] = { 0x7E, 0x00, 0x05, 0x08, 0x01, 0x41, 0x50, 0x02, 0x63 };
    // XBee command for saving config --> ATWR
    uint8_t ATWR[] = { 0x7E, 0x00, 0x04, 0x08, 0x01, 0x57, 0x52, 0x4D };

    for (uint8_t i = 0; i < 9; i++)
    {
      printByte(ATBD7[i], SOCKET1);
    }
    delay(150);
    closeSerial(SOCKET1);
    delay(200);
    beginSerial(115200, SOCKET1);
    for (uint8_t i = 0; i < 9; i++)
    {
      printByte(ATAP2[i], SOCKET1);
    }
    delay(150);
    for (uint8_t i = 0; i < 8; i++)
    {
      printByte(ATWR[i], SOCKET1);
    }
    delay(150);
    closeSerial(SOCKET1);


    /////////////////////////////////////////////////////////////
    // 9.2 check for XBee module
    /////////////////////////////////////////////////////////////

    // init object in SOCKET0
    uart.setUART(SOCKET1);

    // select multiplexer
    Utils.setMuxSocket1();

    // begin serial communication
    uart.beginUART();

    // power on the socket
    PWR.powerSocket(SOCKET1, HIGH);
    delay(500);
    serialFlush(SOCKET1);

    // check for XBees in SOCKET1
    uint8_t cmd_xbee[] = {0x7E, 0x00 , 0x04 , 0x08 , 0x01 , 0x56 , 0x52 , 0x4E};

    // send command & receive answer
    uart.sendCommand(cmd_xbee, sizeof(cmd_xbee));
    uart.readBuffer(100);

    // check response: 7E00078801565200xxxx??
    if (uart._length > 0)
    {
      if ((uart._buffer[0] == 0x7E)
          &&  (uart._buffer[1] == 0x00)
          &&  (uart._buffer[3] == 0x88)
          &&  (uart._buffer[4] == 0x01)
          &&  (uart._buffer[5] == 0x56)
          &&  (uart._buffer[6] == 0x52)
          &&  (uart._buffer[7] == 0x00))
      {

        USB.println(F("XBee module is plugged on socket 1:"));

        /*
          USB.print(F("XBee module in SOCKET0. Firmware: "));
          USB.printHex(uart._buffer[8]);
          USB.printHex(uart._buffer[9]);
          USB.println();
        */

        firmware[0] = uart._buffer[8];
        firmware[1] = uart._buffer[9];
        firmware[2] = uart._buffer[10];
        firmware[3] = uart._buffer[11];

        /////////////////////////////////
        // Get the XBee firmware version
        /////////////////////////////////

        // Set the XBee firmware type depending ont he previous response
        if ((firmware[0] < 0x20) && (firmware[1] > 0x80))
        {
          radio_type = 1; // 802.15.4
          USB.println(F("--> XBee type: 802.15.4"));
        }
        else if ((firmware[0] < 0x20) && (firmware[1] > 0x00))
        {
          radio_type = 2; // 868MHz - 900MHz

          xbee802.OFF();
          xbee802.ON(SOCKET1);

          // send Hardware Serial command
          if (!xbee802.sendCommandAT("HS#"))
          {
            // USB.printHexln(xbee802.commandAT, 3);
          }

          // check for XBee 900HP
          if (xbee802.commandAT[0] == 3)
          {
            USB.println(F("--> XBee type: 900HP"));

            // check for available frequencies:
            // US: 00FFFFFFFFFFFFFFFF
            // BR: 00FFFFFFFE00000FFF
            // AU: 00FFFFFFFE00000000
            if (!xbee802.sendCommandAT("AF#"))
            {
              //USB.printHexln(xbee802.commandAT, 16);
              if ((xbee802.commandAT[1] == 0xFF)
                  && (xbee802.commandAT[2] == 0xFF)
                  && (xbee802.commandAT[3] == 0xFF)
                  && (xbee802.commandAT[4] == 0xFF)
                  && (xbee802.commandAT[5] == 0xFF)
                  && (xbee802.commandAT[6] == 0xFF)
                  && (xbee802.commandAT[7] == 0xFF)
                  && (xbee802.commandAT[8] == 0xFF))
              {
                USB.println(F("--> Hardware serie: USA"));
              }
              else if ((xbee802.commandAT[1] == 0xFF)
                       && (xbee802.commandAT[2] == 0xFF)
                       && (xbee802.commandAT[3] == 0xFF)
                       && (xbee802.commandAT[4] == 0xFE)
                       && (xbee802.commandAT[5] == 0x00)
                       && (xbee802.commandAT[6] == 0x00)
                       && (xbee802.commandAT[7] == 0x0F)
                       && (xbee802.commandAT[8] == 0xFF))
              {
                USB.println(F("--> Hardware serie: BRAZIL"));
              }
              else if ((xbee802.commandAT[1] == 0xFF)
                       && (xbee802.commandAT[2] == 0xFF)
                       && (xbee802.commandAT[3] == 0xFF)
                       && (xbee802.commandAT[4] == 0xFE)
                       && (xbee802.commandAT[5] == 0x00)
                       && (xbee802.commandAT[6] == 0x00)
                       && (xbee802.commandAT[7] == 0x00)
                       && (xbee802.commandAT[8] == 0x00))
              {
                USB.println(F("--> Hardware serie: AUSTRALIA"));
              }
            }
            else
            {
              USB.println(F("--> Hardware serie: ERROR"));
              errorFlag |= 1<<0x04;
            }
          }
          // check for XBee 868LP
          else if (xbee802.commandAT[0] == 8)
          {
            USB.println(F("--> XBee type: 868LP"));
          }

        }
        else if (firmware[0] >= 0x80)
        {
          radio_type = 3; // DigiMesh
          USB.println(F("--> XBee type: DigiMesh"));
        }
        else if (((firmware[0] >= 0x20) && (firmware[1] < 0xB0)) ||
                 ((firmware[0] == 0x70) && (firmware[1] == 0x5B)) )
        {
          radio_type = 4; //ZB
          USB.println(F("--> XBee type: ZigBee"));
        }
        else if (firmware[0] == 0x00 && firmware[1] >= 0x02)
        {
          radio_type = 5; // 900 MHz Intl
          USB.println(F("--> XBee type: 900 International"));
        }
        else
        {
          radio_type = 0;
        }

        /////////////////////////////////////////////////////////////
        // Get the XBee MAC address
        /////////////////////////////////////////////////////////////
        if (radio_type != 0)
        {
          xbee802.OFF();
          delay(1000);
          xbee802.ON(SOCKET1);
          delay(1000);
          xbee802.flush();

          // Get the XBee MAC address
          int counter = 0;
          while ((xbee802.getOwnMac() != 0) && (counter < 12))
          {
            xbee802.getOwnMac();
            counter++;
          }


          // convert mac address from array to string
          Utils.hex2str(xbee802.sourceMacHigh, macHigh, 4);
          Utils.hex2str(xbee802.sourceMacLow,  macLow,  4);

          // Get the XBee MAC address
          while ((xbee802.getOwnMac() != 0) && (counter < 12))
          {
            xbee802.getOwnMac();
            counter++;
          }

          // convert mac address from array to string
          Utils.hex2str(xbee802.sourceMacHigh, macHigh, 4);
          Utils.hex2str(xbee802.sourceMacLow,  macLow,  4);

          USB.print(F("--> MAC address: "));
          USB.print(macHigh);
          USB.println(macLow);

        }

        if (radio_type < 5)
        {
          USB.print(F("--> Firmware version: "));
          USB.print(firmware[0], HEX);
          USB.println(firmware[1], HEX);
        }

        if (radio_type == 5)
        {
          USB.print(F("--> Firmware version: "));
          USB.printHex(firmware[0]);
          USB.printHex(firmware[1]);
          USB.printHex(firmware[2]);
          USB.printHex(firmware[3]);
          USB.println();
        }
      }
    }


    /////////////////////////////////////////////////////////////
    // 9.3. check for LORAWAN module
    /////////////////////////////////////////////////////////////
    if (radio_type == 0)
    {
      // init object in SOCKET0
      xbee802.OFF();
      uart.setUART(SOCKET1);
      uart.setBaudrate(57600);

      // switch module OFF
      uart.closeUART();
      Utils.setMuxUSB();
      PWR.powerSocket(SOCKET1, LOW);

      delay(500);

      // select multiplexer
      Utils.setMuxSocket1();

      // begin serial communication
      uart.beginUART();

      // power on the socket
      PWR.powerSocket(SOCKET1, HIGH);
      delay(500);
      serialFlush(SOCKET1);

      // check for XBees in SOCKET0
      static char cmd_lorawan[] = "sys get ver\r\n";

      // send command & receive answer
      answer = uart.sendCommand((char*)cmd_lorawan, "RN2483", "RN2903", 1000);

      // send command & receive answer
      uint8_t dev_eui_answer = uart.sendCommand((char*)"mac get deveui\r\n", "\r\n", 1000);

      // check response:
      if (answer == 1)
      {
        USB.println(F("LoRaWAN module is plugged on socket 1:"));
        USB.println(F("--> Hardware serie: LoRaWAN EU"));
        if (dev_eui_answer == 1)
        {
          USB.print(F("--> Device EUI: "));
          USB.print(uart._buffer, uart._length);
        }
        radio_type = 7;
      }
      else if (answer == 2)
      {
        USB.println(F("LoRaWAN module is plugged on socket 1:"));
        USB.println(F("--> Hardware serie: LoRaWAN US"));
        if (dev_eui_answer == 1)
        {
          USB.print(F("--> Device EUI: "));
          USB.print(uart._buffer, uart._length);
        }
        radio_type = 7;
      }
    }



    /////////////////////////////////////////////////////////////
    // 9.4. check for SIGFOX module
    /////////////////////////////////////////////////////////////
    if (radio_type == 0)
    {
      // init object in SOCKET0
      uart.setUART(SOCKET1);
      uart.setBaudrate(9600);

      // switch module OFF
      uart.closeUART();
      Utils.setMuxUSB();
      PWR.powerSocket(SOCKET1, LOW);

      delay(500);

      // select multiplexer
      Utils.setMuxSocket1();

      // begin serial communication
      uart.beginUART();

      // power on the socket
      PWR.powerSocket(SOCKET1, HIGH);
      delay(6000);
      serialFlush(SOCKET1);

      // check for XBees in SOCKET1
      static char cmd_sigfox[] = "AT&V\r";

      // send command & receive answer
      answer = uart.sendCommand((char*)cmd_sigfox, "TD1207", "TD1508", 1000);
      char* sigfox_id;

      // get IMEI
      if (answer != 0)
      {
        // send command & receive answer
        delay(1000);
        response = uart.sendCommand((char*)"ATI7\r", "\r\n", 1000);

        uart. waitFor("\r\n", 1000);
        if (response == 1)
        {
          sigfox_id = strtok( (char*)uart._buffer, "\r\n");
        }
      }

      // check response:
      if (answer == 1)
      {
        USB.println(F("SIGFOX module is plugged on socket 1:"));
        USB.println(F("--> Hardware serie: Sigfox EU"));
        USB.print(F("--> Serial Number: "));
        USB.println(sigfox_id);
        radio_type = 8;
      }
      else if (answer == 2)
      {
        USB.println(F("SIGFOX module is plugged on socket 1:"));
        USB.println(F("--> Hardware serie: Sigfox US"));
        USB.print(F("--> Serial Number: "));
        USB.println(sigfox_id);
        radio_type = 8;
      }
    }




    /////////////////////////////////////////////////////////////
    // 9.5. check for WIFI module
    /////////////////////////////////////////////////////////////
    if (radio_type == 0)
    {
      // init object in SOCKET1
      uart.setUART(SOCKET1);
      uart.setBaudrate(115200);

      // switch module OFF
      uart.closeUART();
      Utils.setMuxUSB();
      PWR.powerSocket(SOCKET1, LOW);

      delay(500);

      // select multiplexer
      Utils.setMuxSocket1();

      // begin serial communication
      uart.beginUART();

      // power on the socket
      PWR.powerSocket(SOCKET1, HIGH);
      delay(3000);
      serialFlush(SOCKET1);

      // check for XBees in SOCKET0
      static char cmd_wifi[] = "AT+i\r";

      // send command & receive answer
      answer = uart.sendCommand((char*)cmd_wifi, "I/OK", 1000);

      // check response:
      if (answer == 1)
      {
        USB.println(F("WIFI PRO module is plugged on socket 1"));
        radio_type = 9;
      }
    }

    if (radio_type == 0)
    {
      USB.println(F("No radio module detected into socket 1"));
      errorFlag |= 1<< 0x00;
    }
  }


  /////////////////////////////////////////////////////////////
  // 10. Test RTC
  /////////////////////////////////////////////////////////////
  RTC.setTime("00:01:01:01:00:00:00");
  PWR.deepSleep("00:00:00:05", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
  if(RTC.second < 5){
    errorFlag |= 1<< 0x06;
  }


  /////////////////////////////////////////////////////////////
  // 11. Print error information
  /////////////////////////////////////////////////////////////
  USB.println();
  USB.println(F("==============================="));
  
  if(errorFlag != 0){

    // set red LED button P&S
    Utils.setLED(LED1, LED_ON);
    USB.println(F(" TEST: ERROR")); 
    
    if((errorFlag & 1) != 0){
      USB.println(F("   - No radio module detected"));
    }
    if((errorFlag & 2) != 0){
      USB.println(F("   - Battery error"));
    }
    if((errorFlag & 4) != 0){
      USB.println(F("   - SD error"));
    }
    if((errorFlag & 8) != 0){
      USB.println(F("   - No SD detected"));
    }
    if((errorFlag & 16) != 0){
      USB.println(F("   - XBee 900HP error"));
    }
    if((errorFlag & 32) != 0){
      USB.println(F("   - SIM card error"));
    }
    if((errorFlag & 64) != 0){
      USB.println(F("   - deepSleep error"));
    }
    
  }
  else{
    
    USB.println(F(" TEST: OK"));  

  }
  
}





void loop()
{
  RTC.ON();
  ACC.ON();
  
  ////////////////////////////////////////////////
  // 1. Waspmote Frame composition
  ////////////////////////////////////////////////

  // Create new frame
  frame.setID(node_id);
  frame.createFrame(ASCII);

  // add low MAC address in the case it is an XBee module
  if ((radio_type == 1) ||
      (radio_type == 2) ||
      (radio_type == 3) ||
      (radio_type == 5)  )
  {
    frame.addSensor(SENSOR_MAC, macLow);
  }
  frame.addSensor(SENSOR_ACC, ACC.getX(), ACC.getY(), ACC.getZ());
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());
  frame.showFrame();


  ////////////////////////////////////////////////
  // 2. Send the packet
  ////////////////////////////////////////////////

  if (radio_type == 0)
  {
    USB.println(F("the frame above is printed just by USB (no radio module detected)"));
  }
  else if (radio_type < 6)
  {
    // // In the case of XBee 802.15.4
    if (radio_type == 1)
    {
      // turn XBee on
      xbee802.ON();
      // sets Destination parameters
      xbee_error = xbee802.send(destination, frame.buffer, frame.length);
      // check TX flag
      if (xbee_error == 0)
      {
        USB.println(F("the frame above was sent"));
      }
      else
      {
        USB.println(F("sending error"));
      }
    }
    else
    {
      // In the case of DigiMesh / 868 / 900 / ZigBee
      // turn XBee on
      xbeeZB.ON();

      if (radio_type == 4)
      {
        do
        {
          delay(1000);
          xbeeZB.getAssociationIndication();
          
          // get operating 64-b PAN ID
          xbeeZB.getOperating64PAN();

          USB.print(F("operating 64-b PAN ID: "));
          USB.printHex(xbeeZB.operating64PAN[0]);
          USB.printHex(xbeeZB.operating64PAN[1]);
          USB.printHex(xbeeZB.operating64PAN[2]);
          USB.printHex(xbeeZB.operating64PAN[3]);
          USB.printHex(xbeeZB.operating64PAN[4]);
          USB.printHex(xbeeZB.operating64PAN[5]);
          USB.printHex(xbeeZB.operating64PAN[6]);
          USB.printHex(xbeeZB.operating64PAN[7]);
          USB.println();
        }
        while ( xbeeZB.associationIndication != 0 );
      }
      // sets Destination parameters
      xbee_error = xbeeZB.send(destination, frame.buffer, frame.length);

      // check TX flag
      if (xbee_error == 0)
      {
        USB.println(F("the frame above was sent"));
      }
      else
      {
        USB.println(F("sending error"));
      }
    }
  }



  ///////////////////////////////////////////////////////////////////////////////////////////
  // 3. Deep Sleep
  ///////////////////////////////////////////////////////////////////////////////////////////

  USB.println(F("enter deep sleep"));
  // Go to sleep disconnecting all switches and modules
  // After 10 seconds, Waspmote wakes up thanks to the RTC Alarm
  PWR.deepSleep("00:00:00:05", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);

  USB.ON();
  USB.println(F("\nwake up"));

  // After wake up check interruption source
  if ( intFlag & RTC_INT )
  {
    // clear interruption flag
    intFlag &= ~(RTC_INT);

    USB.println(F("---------------------"));
    USB.println(F("RTC INT captured"));
    USB.println(F("---------------------"));
  }

}
Could you please share some images of your devices?

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 » Mon Sep 17, 2018 1:55 pm

I configured both of the modules to 115200 baud rate using XCTU.
I uploaded the code and this was the output:

Starting Waspmote factory default program
Global variable '_serial_id':320367057C10541A
Waspmote serial ID: 320367057C10541A
No SD card detected

No radio module detected into socket 0

No radio module detected into socket 1

===============================
TEST: ERROR
- No radio module detected
- No SD detected
===============================
Current ASCII Frame:
Length: 57
Frame Type: 134
frame (HEX): 3C3D3E86022333323033363730353743313035343141236E6F64655F69642330234143433A2D37333B2D39343B393935234241543A31303023
frame (STR): <=>†#320367057C10541A#node_id#0#ACC:-73;-94;995#BAT:100#
===============================
the frame above is printed just by USB (no radio module detected)
enter deep sleep

wake up
---------------------
RTC INT captured
---------------------
===============================
Current ASCII Frame:
Length: 57
Frame Type: 134
frame (HEX): 3C3D3E86022333323033363730353743313035343141236E6F64655F69642331234143433A2D3130343B2D39303B393932234241543A343223
frame (STR): <=>†#320367057C10541A#node_id#1#ACC:-104;-90;992#BAT:42#
===============================
the frame above is printed just by USB (no radio module detected)
enter deep sleep

Image
I am using these devices, where the one on the left is configured as a coordinator, and on the left is configured as a router. I want both of them to be able to send and receive data

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

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Tue Sep 18, 2018 8:41 am

Hi,

It seems that the module isn't configured properly to be used with waspmote. Please check also if AP mode is set to API 2.

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 Sep 18, 2018 1:40 pm

I configured them both to be API 2 and i was able to send packets from the node to the module. But how can I read the data I sent? For example If i send "okay", how can I read or see "okay" in the XCTU monitor?
Image
Image

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 Sep 18, 2018 2:05 pm

And can I send and receive data from and to 2 or waspmotes nodes? i.e two routers

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

Re: Xbee Zigbee PRO S2C network

Post by libelium-dev » Wed Sep 19, 2018 9:38 am

Hi,

Can you set the API mode of the module connected to the gateway to 0? We think that in this way the data received is printed through the serial monitor.

You can use the example codes to send and receive data from 2 waspmotes.

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 Sep 19, 2018 4:49 pm

I used the examples ZB_03_send_packets and ZB_04_receive_packets on both waspmotes and it worked.
I tried to send "hello" but i got "<=>† #320367057C10541A#Hello#0#".
I want to receive only "hello" or any other value without the other data. How can I do that?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest