I used a simple example to test Bluetooth transmission, and everything worked fine. I think this may be related to the fact that serialBT.write() does not have its own delimiter when writing, because the data I see on the serial monitor is continuous.
The example to test Bluetooth transmission code:
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
// define deviceName
const char *deviceName = "ESP32_BT_Example";
// counter
int count = 0;
void setup() {
Serial.begin(115200);
// initial Bluetooth
if (!SerialBT.begin(deviceName)) {
Serial.println("Bluetooth initialization failed!");
while (1);
}
Serial.println("Bluetooth is activated, waiting for connection...");
Serial.print("deviceName:");
Serial.println(deviceName);
}
void loop() {
// waiting for connection
if (SerialBT.connected()) {
// send data
String message = "Hello World #" + String(count++);
SerialBT.println(message);
Serial.println("sendmessage:" + message);
senddata();
} else {
Serial.println("waiting for connection...");
}
delay(1000);
}
void senddata(){
const char DataPacketHeader[5] = {0x01, 0x02, 0x03, 0x04, 0x05};
for (int i = 0; i < 5; i++) {
SerialBT.write(DataPacketHeader[i]);
}
SerialBT.write(0x0A);
}
In addition, I also saw that the transmission packet on the Bluetooth transmission serial port complies with the transmission protocol.
This may be back to the previous transmission protocol problem.