Sending char Array via Bluetooth in ESP32

Hi everyone,
I used this simple sketch to sending char array from ESP32 to my laptop via Bluetooth communication.

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

char aaa[128] = {"Hello_Everyone...This_is_char_arry_from_ESP32_device..."};

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); 
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void loop() {
    SerialBT.write(*aaa);
  delay(20);
}

I used Bluetooth Serial Terminal software for receive data in my laptop. but it shows output as

HHHHHHHHHHHHHHHHHHHHH

I need your help to solve this problem. My array is much large and how to send it via Bluetooth to get known sentence.
Thank You.

*aaa is just the first byte of your message, a char. so it sends the 'H' every 20ms which is why you see HHHHHHHHHHHHHHHHHHHHH

try

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

char message[] = "Hello_Everyone.";

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); 
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void loop() {
    SerialBT.write(message, strlen(message));
  delay(5000);
}

there is indeed a max size for the payload. You'll have to deal with that.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.