ND没有回应。 Zigbee 网状套件

No respond from ND. Zigbee Mesh kit

我想知道我网络中所有节点的地址(目前只有两个节点,集中器和路由器,但我想在深入之前先简单一点)。我通过创建我的 PANID、分配一个频道并放置 DH 0DL 0F 来使用我的集中器创建我的网络。这是我的 Xbee S2D

的配置

集中器

CE 1 - OK
ATOP - A8E4F62D42AB6EE1
ATOI - 4AAA
MY ID - 0
Operating Channel - 14
ATAI - 0
DH 0- OK
DL 0F- OK
ATAP 1 - OK

我的路由器

ATID - 0
ATOP - A8E4F62D42AB6EE1
MY ID - D6F5
ATOI - 4AAA
JV 1 - OK
ATAP 1 - OK

这是我发送的数组

byte API_AT[] = {0x7E, 0x00, 0x04, 0x08, 0x01, 0x4E,0x44, 0x64};

但是当我读取串行端口时,我什么也没得到。

这是我来自路由器的代码


#define OK "OK"
#define ERROR "ERROR"
#define CR '\r'
#define LR '\n'

byte API_AT[] = {0x7E, 0x00, 0x04, 0x08, 0x01, 0x4E,0x44, 0x64};
byte AT_Frame[] = {0x7E, 0x00, 0x04, 0x08, 0x01, 0x4E,0x44, 0x64};

int sendATCommands(char AT[], char *expected1, char *expected2, long unsigned int timeout = 1000){
  char response[10];
  memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print(AT);
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
      else if ((i > 0))
      {
        if ((memcmp(response, "OK",2) == 0)){
          Serial.println("OK");
          return 1;
        }
        else if ((memcmp(response, "ERROR",5) == 0)){
          Serial.println("Error");
          return 2;
        } 
      }
    }
  }while (millis() - last < timeout);
  Serial.println("NULL");
  return 0;
}

char* readPANID(char PANID[]){
  char response[10];
  memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print(PANID);
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
    }
  }while (millis() - last < 1000);
  Serial.println((String)response);
  return response;
}

void readOperatingPAN(char PANID[]){
  char response[20];
  memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print(PANID);
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
    }
  }while (millis() - last < 2000);
  Serial.println((String)response);
}

void readOperatingID_16bits(char ATOI[]){
  char response[20];
  memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print(ATOI);
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
    }
  }while (millis() - last < 2000);
  Serial.println((String)response);
}

void readMYID(char MYID[]){
  char response[10];
  memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print(MYID);
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
    }
  }while (millis() - last < 2000);
  Serial.println((String)response);
}

void readOperatingChannel(){
  Serial.print("Operating Channel:");
  char response[10];
  memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print("ATCH\r");
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
    }
  }while (millis() - last < 1000);
  Serial.println((String)response);
}

void Association_Report(){
  Serial.print("Association Report:");
  char response[10];
  memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print("ATAI\r");
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
    }
  }while (millis() - last < 2000);
  Serial.println((String)response);
}

void NodeDiscovery(){
  String S;
  //memset(response, '[=13=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  // AT Command Frame
  Serial2.write(0x7E);
  Serial2.write(0x00);
  Serial2.write(0x04);
  Serial2.write(0x08);
  Serial2.write(0x01);
  Serial2.write(0x4E);
  Serial2.write(0x44);
  Serial2.write(0x64);
  delay(5000);
}

void setup() {
  Serial.begin(9600);
  Serial2.begin(9600);
  //Enter to AT Mode
  if (sendATCommands("+++",OK,ERROR,10000) != 1)
    Serial.println("Error AT Mode");
  //Set or read the 64-bit extended PAN ID
  char *PANID = readPANID("ATID\r");
  //Read the 64-bit extended PAN ID. The OP value reflects the operating extended PAN ID where the
  //device is running. If ID > 0, OP equals ID.
  readOperatingPAN("ATOP\r");
  //Reads the 16-bit network address of the device.
  readMYID("ATMY\r");
  //Read the 16-bit PAN ID. The OI value reflects the actual 16-bit PAN ID where the device is running
  readOperatingID_16bits("ATOI\r");
  readOperatingChannel();
  Association_Report();
  //Set or read the channel verification parameter.
  //If JV = 1, a router or end device verifies the coordinator is on its operating channel when joining or
  //coming up from a power cycle. If a coordinator is not detected, the router or end device leaves its
  //current channel and attempts to join a new PAN. If JV = 0, the router or end device continues
  //operating on its current channel even if a coordinator is not detected.
  if (sendATCommands("ATJV 1\r", OK, ERROR)!= 1)
    Serial.println("Error JV");
  //Enables API Mode. The device ignores this command when using SPI. API mode 1 is always used.
  if (sendATCommands("ATAP 1\r", OK, ERROR) != 1)
    Serial.println("Error JV");
  if (sendATCommands("ATDH 0\r", OK, ERROR)!= 1)
    Serial.println("Error DH");
  //Enables API Mode. The device ignores this command when using SPI. API mode 1 is always used.
  if (sendATCommands("ATDL 0F\r", OK, ERROR) != 1)
    Serial.println("Error DL");
  NodeDiscovery();
}

void loop() {
  // put your main code here, to run repeatedly:
  //Serial.print("+++:");
  static bool Waiting_Message = true;
  static char msg[128];
   while (Serial2.available()){
     char aux;
     if (Waiting_Message){
      aux = Serial2.read();
      Serial.println(aux);
      if (aux == '7E' ){
        Serial.println("Received Started byte");
        Waiting_Message = false;
      }
      else{
        char S = Serial2.read();
        Serial.println(S);
        if (S == '\r')
          Waiting_Message = true;
      }

     }
   }
   delay(100);
}

我的协调员

#include <Arduino.h>
#define OK "OK"
#define ERROR "ERROR"
#define CR '\r'
#define LR '\n'

String PANID_16 = "C7F6";
String PAIND_64 = "A8E4F62D42AB6EE1C";

uint8_t  PANID[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};

char response[150];


int sendATCommands(char AT[], char *expected1, char *expected2, long unsigned int timeout = 1000){
  char response[10];
  memset(response, '[=14=]', sizeof(response));
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.print(AT);
  delay(300);
  int i = 0;
  unsigned long last = millis();
  do{
    while (Serial2.available() > 0){
      response[i++] = Serial2.read();
      if (((i == 2) && (response[0] == CR) && (response[1] == LR)) ||((i == 1) && (response[0] == LR)))
        i = 0;
      else if ((i > 0))
      {
        if ((memcmp(response, "OK",2) == 0)){
          Serial.println("OK");
          return 1;
        }
        else if ((memcmp(response, "ERROR",5) == 0)){
          Serial.println("Error");
          return 2;
        } 
      }
    }
  }while (millis() - last < timeout);
  Serial.println("NULL");
  return 0;
}

void readPANID(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.println("ATOP");
  String ID = Serial2.readStringUntil(LR);
  Serial.println(ID);
  /*Serial2.println("ATID");
  ID = Serial2.readStringUntil(LR);
  Serial.println(ID);*/
}

void readPANID16(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.println("ATOI");
  String ID = Serial2.readStringUntil(LR);
  Serial.println(ID);
  /*Serial2.println("ATMY");
  ID = Serial2.readStringUntil(LR);
  Serial.println(ID);*/
}

void SetChannels(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial.print("ATSC 3FF:");
  Serial2.println("ATSC 3FF");
  String S = Serial2.readStringUntil(LR);
  Serial.println(S);
  while (Serial2.available() > 0)
    Serial2.read();
  Serial.print("ATSD 4:");
  Serial2.println("ATSD 4");
  String S1 = Serial2.readStringUntil(LR);
  Serial.println(S1);
}

void ScanChannels(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial.print("ATSC:");
  Serial2.println("ATSC");
  String ID = Serial2.readString();
  Serial.println(ID);
}

void GetOperating16PANID(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial.println("ATII1234:");
  Serial2.println("ATII4AAA");
  String S = Serial2.readString();
  Serial.println(S);
}

void GetOperating64PANID(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial.print("ATID A8E4F62D42AB6EE1:");
  Serial2.println("ATID A8E4F62D42AB6EE1");
  String S = Serial2.readString();
  Serial.println(S);
}

void readMY(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.println("ATMY");
  String S = Serial2.readString();
  Serial.println(S);
}

void OperatingChannel(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.println("ATCH");
  String S = Serial2.readString();
  Serial.println(S);
}

void AssociationStatus(){
  while (Serial2.available() > 0)
    Serial2.read();
  Serial2.println("ATAI");
  String S = Serial2.readString();
  Serial.println(S);
}

void EnterAT_Mode(){
  Serial.print("Enter AT Mode:");
  if (sendATCommands("+++",OK,ERROR,10000) != 1){
    Serial.println("Error AT Mode");
    EnterAT_Mode();
  }
  return;
}

void setup() {
  Serial.begin(9600);
  Serial2.begin(9600);
  delay(1000);
  EnterAT_Mode();
  Serial.print("AT:");
  if (sendATCommands("",OK,ERROR) != 1)
    Serial.println("Error AT Mode");
  Serial.print("ATCE 1:");
  sendATCommands("ATCE 1\r",OK,ERROR);
  Serial.print("Enter API Mode:");
  if (sendATCommands("ATAP 1\r", OK, ERROR) != 1)
    Serial.println("Error API Mode");
  Serial.print("PAN ID 64:");
  readPANID();
  Serial.print("ATSC:");
  ScanChannels();
  SetChannels();
  Serial.print("ATAC:");
  sendATCommands("ATAC\r",OK,ERROR);
  GetOperating16PANID();
  GetOperating64PANID();
  Serial.print("Change to PAN ID 16:");
  readPANID16();
  Serial.print("MY Address:");
  readMY();
  Serial.print("Change to PAN ID 64:");
  readPANID();
  Serial.print("Operating Channel:");
  OperatingChannel();
  Serial.print("Association status");
  AssociationStatus();
  if (sendATCommands("ATAP 1\r", OK, ERROR) != 1)
    Serial.println("Error Enter API Mode");
  if (sendATCommands("ATDH 0\r", OK, ERROR)!= 1)
    Serial.println("Error DH");
  //Enables API Mode. The device ignores this command when using SPI. API mode 1 is always used.
  if (sendATCommands("ATDL 0F\r", OK, ERROR) != 1)
    Serial.println("Error DL");
    Serial.print("ATAC:");
  sendATCommands("ATAC\r",OK,ERROR);
  Serial.print("ATWR:");
  sendATCommands("ATWR\r",OK,ERROR);
  delay(1000);
}

void loop() {
  while (Serial2.available()){
    char S = Serial2.read();
    Serial.println(S);
  }
}

我也尝试发送远程 AT 命令请求帧 (0x17) 这是数据包

byte AT_Frame[] = {0x7E, 0x00, 0x0F, 0x17, 0x01, 0x00,0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFE, 0x02, 0x4E, 0x44, 0x58};

但结果相同

我可以解决我的问题。当我进入 AT 模式时,我必须在从我的 Xbee 发送任何消息之前退出。