繁体   English   中英

完成读取缓冲区后,ESP32蓝牙连接断开连接

[英]ESP32 Bluetooth Connection disconnects when finished with reading buffer

我正在编程ESP32以接受蓝牙命令并使用串行配置文件将蓝牙数据发送回我的手机。 为此,我使用的是Arduino Espressif蓝牙串行库。 每当我向ESP32发送信息时,它会对其进行处理,然后突然关闭蓝牙连接。

据我所知,我已经尝试了各种延迟,因为我认为可能处理器没跟上其他东西,因为它崩溃了。 但是,当通过USB使用串行连接进行监控时,它仍然会继续发送状态更新。 除此之外我无法找到解决方案(也在互联网上)。

因为我几乎是初学者,所以我不想尝试建立自己的串行蓝牙库。 ESP在发送数据时不会崩溃。 它还会继续处理发送的数据。 我可以看到,因为它发送了字符,我收集后通过蓝牙使用串行接口发送它。

无论我等多久,无法在此事件后重建连接。

我的Main函数,包含函数调用以及写入结果的缓冲区,因为我认为可能是我误用了它。

void loop() {

  if (ESP_BT.available() > 0)
  {
    char *buffer = (char*) malloc(InputSize);
    getCurrentMessage(ESP_BT, buffer, InputSize);
    Serial.println(buffer);
    strncpy(currentMessage, buffer, InputSize);
    free(buffer);
  }
  if (millis() %2000 == 0){
    Serial.println("Debug");
    delay(1);
  }
} 

被调用的函数应该将BluetoothSerial的inputBuffer读入我的Buffer。

void getCurrentMessage(BluetoothSerial ESP_BT, char* receivedChars, int InputSize)
{
 Serial.println("DEBUG: getCurrentMessageInit");
 static byte ndx = 0;

 char rc;

 while (ESP_BT.available() > 0){
   ESP_BT.println("DEBUG: Message Available");    
   Serial.println("DEBUG: Message Available");
   rc = ESP_BT.read();
   receivedChars[ndx] = rc;
   ndx++;
   delay(100);
   if (ndx >= InputSize){
     while(ESP_BT.available() > 0){
       ESP_BT.read();
     }
   }
 }
} 

我希望蓝牙连接能继续工作。 这不行。 我也得到错误代码“queue.c:1442(xQueueGenericReceive) - 断言失败!” 当不使用延迟和ESP然后重新启动。 这包括延迟后它没有做。

问题是我没有通过引用调用我的蓝牙对象。 而不是给我的功能蓝牙对象我应该指向它:

void getCurrentMessage(BluetoothSerial* ESP_BT, char* receivedChars, int InputSize)
{
 Serial.println("DEBUG: getCurrentMessageInit");
 static byte ndx = 0;

 char rc;

 while (ESP_BT->available() > 0){
   ESP_BT->println("DEBUG: Message Available");    
   Serial.println("DEBUG: Message Available");
   rc = ESP_BT.read();
   receivedChars[ndx] = rc;
   ndx++;
   delay(100);
   if (ndx >= InputSize){
     while(ESP_BT->available() > 0){
       ESP_BT->read();
     }
   }
 }
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM