Skip to content

BLE Name Length Too Long Cause Crash #7894

Closed
@GodayMax

Description

@GodayMax

Board

ESP32 Dev Module

Device Description

ESP32-WROOM-32

Hardware Configuration

n/a

Version

v1.0.6

IDE Name

PlatformIO

Operating System

MacOS 12

Flash frequency

40Mhz

PSRAM enabled

yes

Upload speed

115200

Description

Using BLEDevice to init ble device name with a name longer than 30 character
Module will crash when init

BLEDevice::init(String("MZ_MZL-FC-E-XX-999999-C8F09EE7C0CC").c_str());

Sketch

#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

uint8_t txValue = 0;
BLEServer *pServer = NULL;                   //BLEServer指针 pServer
BLECharacteristic *pTxCharacteristic = NULL; //BLECharacteristic指针 pTxCharacteristic
bool deviceBleConnected = false;             //本次连接状态
bool oldDeviceConnected = false;             //上次连接状态

// See the following for generating UUIDs: https://www.uuidgenerator.net/
#define SERVICE_UUID "83677baa-3eb8-4866-b6b6-96e5ed5cc48d" // UART service UUID
#define CHARACTERISTIC_UUID_RX "f5d2b3fe-e6b5-49b5-aa5f-a00bb4156d1d"
#define CHARACTERISTIC_UUID_TX "6f588463-f8f1-44f8-bdae-a1272a1b0f6e"


class MyServerCallbacks : public BLEServerCallbacks
{
    void onConnect(BLEServer *pServer) {};
    void onDisconnect(BLEServer *pServer) {}
};

//ble相关
class MyBLECallbacks : public BLECharacteristicCallbacks {
  void onWrite(BLECharacteristic *pCharacteristic) {}
};

void setup() {
  Serial.begin(115200);
  Serial.println("START >>>>>>>>>>>>>>>>>>>> ");

  BLEDevice::init(String("MZ_MZL-FC-E-XX-999999-C8F09EE7C0CC").c_str());

  // 创建一个 BLE 服务
  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks()); //设置回调
  BLEService *pService = pServer->createService(SERVICE_UUID);

  // 创建一个 BLE 特征
  pTxCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY);
  pTxCharacteristic->addDescriptor(new BLE2902());
  BLECharacteristic *pRxCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_WRITE);
  pRxCharacteristic->setCallbacks(new MyBLECallbacks()); //设置回调

  BLEAdvertisementData d = BLEAdvertisementData();
  d.setManufacturerData("123");

  pService->start();                  // 开始服务
  pServer->getAdvertising()->setAdvertisementData(d);

  pServer->getAdvertising()->start(); // 开始广播
  Serial.println("ble inited, waiting for connection.....");
}

void loop() {
}

Debug Message

START >>>>>>>>>>>>>>>>>>>> 
[I][BLEDevice.cpp:569] getAdvertising(): create advertising
ble inited, waiting for connection.....

Stack smashing protect failure!

abort() was called at PC 0x4016007b on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x4008ecac:0x3ffd0910 0x4008ef29:0x3ffd0930 0x4016007b:0x3ffd0950 0x400fef8d:0x3ffd0970 0x40123c25:0x3ffd09d0 0x40124251:0x3ffd09f0 0x4012e75e:0x3ffd0a10 0x40103546:0x3ffd0a30 0x4008ff9e:0x3ffd0a60

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Area: BLEIssues related to BLESprintIssue is in current sprint

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions