无线mesh网络:RadioHead Mesh网络通信

我正在使用带有 ESP32 的LilyGO TTGO T-beam创建带有RadioHead Library的 LoRa 网状网络。我遇到了一个问题,即我的网状客户端能够与网状服务器连接,但服务器从客户端接收 0 个字节。有什么建议吗?谢谢。Current Outcome Picture

设置:

#define SCK     5   // GPIO5  -- SX1278's SCK
#define MISO    19  // GPIO19 -- SX1278's MISnO
#define MOSI    27  // GPIO27 -- SX1278's MOSI
#define SS      18  // GPIO18 -- SX1278's CS
#define RST     23  // GPIO14 -- SX1278's RESET --- I tried both of them, none of them works.
#define DI0     26  // GPIO26 -- SX1278's IRQ(Interrupt Request)
#define SELF_ID 1
#define SERVER_ID 254
RHSoftwareSPI spi;
RH_RF95 rf95(SS, DI0, spi);
RHMesh loraMesh(rf95, SELF_ID);  // Server would be SERVER_ID

发送代码:

int MeshSend(String message) {
  int msgLen = message.length() + 1;
  uint8_t byteData[msgLen] = {'\0'};
  message.getBytes(byteData, message.length());
  if (DEBUG) {
    Serial.print("Sending \'");
    Serial.print((char*)byteData);
    Serial.println("\' to rf95_server, length is " + String(msgLen) + ".");
  }
  sleep(50);  // Stop whole process for cleaning buff
  counter += 50;
  return loraMesh.sendtoWait(byteData, msgLen, SERVER);
}

接收代码:

void loop() {
    uint8_t len = RH_MESH_MAX_MESSAGE_LEN;  // 250
    uint8_t from;
    driver.setModeRx();
    if (manager.recvfromAck(buf, &len, &from)) {
      if (DEBUG) {
        Serial.print("Got ");
        Serial.print(len);
        Serial.print(" bytes of message from ");
        Serial.print(from, HEX);
        Serial.print(": ");
      }
      Serial.println((char*) buf);
    }
}
2

好的,问题解决了,我需要使用manager.available()检查状态并删除manager.setModeRx()

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(970)
华为代码大全对照表:在乳胶中创建完全对齐的表(翻页)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(36条)