Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何通过heltec esp32读取串行监视器中的LoRa信息_C++_C++11_Esp32_Lora - Fatal编程技术网

C++ 如何通过heltec esp32读取串行监视器中的LoRa信息

C++ 如何通过heltec esp32读取串行监视器中的LoRa信息,c++,c++11,esp32,lora,C++,C++11,Esp32,Lora,我是esp32和LoRa消息的新手 下面是heltect esp32 lora库中的两个示例 我用来发送和接收数据的两个模块有一个oled显示屏。。。我把它们的值打印到串行监视器上。数据值显示在oled显示屏上,但它们在串行监视器中是随机字符,如下所示。。。"⸮⸮3.⸮⸮JS⸮ ⸮⸮⸮⸮(J)⸮⸮". 我的问题是,我如何从String/浮标/整数形式接收发送者的数据,以便我可以对它们执行逻辑。我是C++和lora的新手,所以欢迎任何帮助。 我很确定这段代码(本段正下方的第一个代码块)是负责打印接

我是esp32和LoRa消息的新手

下面是heltect esp32 lora库中的两个示例

我用来发送和接收数据的两个模块有一个oled显示屏。。。我把它们的值打印到串行监视器上。数据值显示在oled显示屏上,但它们在串行监视器中是随机字符,如下所示。。。"⸮⸮3.⸮⸮JS⸮ ⸮⸮⸮⸮(J)⸮⸮".

我的问题是,我如何从String/浮标/整数形式接收发送者的数据,以便我可以对它们执行逻辑。我是C++和lora的新手,所以欢迎任何帮助。 我很确定这段代码(本段正下方的第一个代码块)是负责打印接收到的消息的代码,但即使我将“char”数据类型更改为String,它也不会以任何我可以使用的格式打印

while (LoRa.available()) {
  Serial.print((char)LoRa.read());
}
接收代码

/* 
  Check the new incoming messages, and print via serialin 115200 baud rate.
  
  by Aaron.Lee from HelTec AutoMation, ChengDu, China
  成都惠利特自动化科技有限公司
  www.heltec.cn
  
  this project also realess in GitHub:
  https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
*/

#include "heltec.h"

#define BAND    915E6  //you can set band here directly,e.g. 868E6,915E6
void setup() {
    //WIFI Kit series V1 not support Vext control
  Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);

}

void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");
    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
}
发送方代码

    /* 
  Basic test program, send date at the BAND you seted.
  
  by Aaron.Lee from HelTec AutoMation, ChengDu, China
  成都惠利特自动化科技有限公司
  www.heltec.cn
  
  this project also realess in GitHub:
  https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
*/
#include "heltec.h"
#define BAND    915E6  //you can set band here directly,e.g. 868E6,915E6

int counter = 0;

void setup() {
  
  //WIFI Kit series V1 not support Vext control
  Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);

  
}

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);
  // send packet
  LoRa.beginPacket();
/*
* LoRa.setTxPower(txPower,RFOUT_pin);
* txPower -- 0 ~ 20
* RFOUT_pin could be RF_PACONFIG_PASELECT_PABOOST or RF_PACONFIG_PASELECT_RFO
*   - RF_PACONFIG_PASELECT_PABOOST -- LoRa single output via PABOOST, maximum output 20dBm
*   - RF_PACONFIG_PASELECT_RFO     -- LoRa single output via RFO_HF / RFO_LF, maximum output 14dBm
*/
  LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();
  
  counter++;
  digitalWrite(25, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(25, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

也许,串行监视器的波特率配置错误?在我的情况下,IDE中的默认值是9600,但ESP32随115200一起发送。您可以在串行监视器的组合框中更改波特率。

这正是问题所在。谢谢。我查看了ESP32文档,发现它要求115200的波特率。我看到了它们的原始版本但是我不知道我在找什么。谢谢