c++ - 如何通过 heltec esp32 在串行监视器中读取 LoRa 消息
问题描述
我是 esp32 和 LoRa 消息传递的新手。
我正在关注 heltect esp32 lora 库中的两个示例。
我用来发送和接收数据的两个模块都有一个 oled 显示器……我将它们的值打印到串行监视器上。数据值出现在 oled 显示屏上,但它们是串行监视器中的随机字符,如下所示……“⸮⸮3⸮⸮JS⸮⸮⸮⸮⸮J)⸮⸮”。
我的问题是如何以类似字符串/浮点数/整数的形式从发送方接收数据,以便对它们执行逻辑。我是 C++ 和 lora 的新手,所以欢迎任何帮助。
我很确定这(本段正下方的第一个代码块)是负责打印接收到的消息的代码段,但即使我更改“char”dtype,它也不会以我可以使用的任何格式打印到字符串。
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。您可以在串行监视器的组合框中更改波特率。
推荐阅读
- c# - 作为对话提示选择的结果发送主动消息
- email - 如何使我的代码适用于 Blackberry,适用于 iOS 和最新的黑莓迭代?
- sql - 查看增量日期
- image - 棱镜图像不会加载到 vue 站点并创建运行时/编译器错误
- java - 如何获取 textField 的输入并将其替换为另一个 JFrame 中的文本
- amazon-web-services - 如何从 AWS SES-SNS 传入电子邮件中删除附件?
- slack - 在没有公共可访问服务器的情况下与 slack bot 交互
- bash - 在 BASH 脚本中捕获 curl 的错误消息并检查状态
- javascript - 如何在 Test Cafe 中使用 Javascript 将表作为数组返回
- git - 按顺序合并两个 repos 的提交