我正在从 Android 设备发送一个字符串到 esp32,我想将 SerialBT.readString() 值存储到字符串变量,但它存储为空字符串,我该怎么办?
if (SerialBT.available()) {
Serial.println(SerialBT.readString()); // this prints the message as well
String ts=SerialBT.readString();
Serial.println(ts); // prints nothing
最佳答案
您第一次调用 SerialBT.readString()
会消耗可用数据。您的第二次调用不会重新读取相同的字符串。
删除该行:
Serial.println(SerialBT.readString()); // this prints the message as well
关于c - SerialBT.readString() 保存为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58418969/