Add BLE diagnostics: controller status, MAC, advertising result
Remove getMinInterval/getMaxInterval (not available in v1.4.0). Add esp_bt_controller_get_status() before/after init. Add esp_bt_dev_get_address() for MAC address. Print adv->start() return value. Add explicit advertising interval settings (100-200ms).
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
#include "ble_midi_transport.h"
|
#include "ble_midi_transport.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <NimBLEDevice.h>
|
#include <NimBLEDevice.h>
|
||||||
|
#include <esp_bt.h>
|
||||||
|
#include <esp_bt_main.h>
|
||||||
|
#include <esp_bt_device.h>
|
||||||
|
|
||||||
#define BLE_MIDI_SERVICE_UUID "03B80E5A-EDE8-4B33-A751-6CE34EC4C700"
|
#define BLE_MIDI_SERVICE_UUID "03B80E5A-EDE8-4B33-A751-6CE34EC4C700"
|
||||||
#define BLE_MIDI_CHAR_UUID "7772E5DB-3868-4112-A1A9-F2669D106BF3"
|
#define BLE_MIDI_CHAR_UUID "7772E5DB-3868-4112-A1A9-F2669D106BF3"
|
||||||
@@ -44,14 +47,24 @@ BleMidiTransport::~BleMidiTransport() {
|
|||||||
bool BleMidiTransport::begin() {
|
bool BleMidiTransport::begin() {
|
||||||
Serial.println("[BLE] Initializing BLE MIDI...");
|
Serial.println("[BLE] Initializing BLE MIDI...");
|
||||||
|
|
||||||
// NimBLE-Arduino v1.4.0+ handles ESP32-S3 internally, using
|
|
||||||
// bt_cfg.bluetooth_mode = ESP_BT_MODE_BLE. Do NOT pre-init the
|
|
||||||
// BT controller here or NimBLEDevice::init() will see an
|
|
||||||
// error from double-init and abort via ESP_ERROR_CHECK.
|
|
||||||
Serial.println("[BLE] NimBLEDevice init...");
|
Serial.println("[BLE] NimBLEDevice init...");
|
||||||
|
esp_bt_controller_status_t ctrl_status = esp_bt_controller_get_status();
|
||||||
|
Serial.printf("[BLE] BT controller status before init: %d (0=IDLE,1=INITED,2=ENABLED)\n", ctrl_status);
|
||||||
|
|
||||||
NimBLEDevice::init("JOC Midi");
|
NimBLEDevice::init("JOC Midi");
|
||||||
Serial.println("[BLE] NimBLEDevice initialized");
|
Serial.println("[BLE] NimBLEDevice initialized");
|
||||||
|
|
||||||
|
ctrl_status = esp_bt_controller_get_status();
|
||||||
|
Serial.printf("[BLE] BT controller status after init: %d\n", ctrl_status);
|
||||||
|
|
||||||
|
const uint8_t* mac = esp_bt_dev_get_address();
|
||||||
|
if (mac) {
|
||||||
|
Serial.printf("[BLE] Device MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||||
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
} else {
|
||||||
|
Serial.println("[BLE] Device MAC: NOT AVAILABLE");
|
||||||
|
}
|
||||||
|
|
||||||
Serial.println("[BLE] Creating server...");
|
Serial.println("[BLE] Creating server...");
|
||||||
ble_server = NimBLEDevice::createServer();
|
ble_server = NimBLEDevice::createServer();
|
||||||
if (!ble_server) {
|
if (!ble_server) {
|
||||||
@@ -95,7 +108,12 @@ bool BleMidiTransport::begin() {
|
|||||||
NimBLEAdvertising* adv = NimBLEDevice::getAdvertising();
|
NimBLEAdvertising* adv = NimBLEDevice::getAdvertising();
|
||||||
adv->addServiceUUID(BLE_MIDI_SERVICE_UUID);
|
adv->addServiceUUID(BLE_MIDI_SERVICE_UUID);
|
||||||
adv->setScanResponse(true);
|
adv->setScanResponse(true);
|
||||||
adv->start();
|
adv->setMinInterval(160); // 100ms (160 * 0.625ms)
|
||||||
|
adv->setMaxInterval(320); // 200ms (320 * 0.625ms)
|
||||||
|
bool adv_started = adv->start();
|
||||||
|
Serial.printf("[BLE] adv->start() returned: %d\n", adv_started);
|
||||||
|
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
|
|
||||||
if (adv->isAdvertising()) {
|
if (adv->isAdvertising()) {
|
||||||
Serial.println("[BLE] Advertising confirmed started");
|
Serial.println("[BLE] Advertising confirmed started");
|
||||||
@@ -103,6 +121,7 @@ bool BleMidiTransport::begin() {
|
|||||||
Serial.println("[BLE] WARNING: isAdvertising() reports false!");
|
Serial.println("[BLE] WARNING: isAdvertising() reports false!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
Serial.println("[BLE] BLE MIDI advertising as 'JOC Midi'");
|
Serial.println("[BLE] BLE MIDI advertising as 'JOC Midi'");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user