Нет ответа от ND. Комплект Zigbee Me sh - PullRequest
0 голосов
/ 10 апреля 2020

Я пытаюсь узнать адрес всех узлов в моих сетях (на данный момент есть только два узла, концентратор и маршрутизатор, но я хочу сделать это проще, прежде чем углубляться). Я создал свою сеть с помощью моего Концентратора, создав свой PANID, назначив канал, а также поместив DH 0 и DL 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, '\0', 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, '\0', 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, '\0', 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, '\0', 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, '\0', 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, '\0', 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, '\0', 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, '\0', 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, '\0', 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};

, но с тем же результатом

1 Ответ

0 голосов
/ 14 апреля 2020

Я мог бы решить мою проблему. Когда я вошел в режим AT, мне пришлось выйти перед отправкой любого сообщения с моего Xbee.

...