Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 Bluetooth Source Range limited when not debugging #1526

Open
1 task done
Al-Zahir opened this issue Apr 25, 2024 · 2 comments
Open
1 task done

ESP32 Bluetooth Source Range limited when not debugging #1526

Al-Zahir opened this issue Apr 25, 2024 · 2 comments

Comments

@Al-Zahir
Copy link

Al-Zahir commented Apr 25, 2024

Problem Description

Expected: ESP32 as a bluetooth source should play music at normal bluetooth distance when not debugging (i.e. plugged into a computer without PlatformIO/Arduino or plugged into a wall)

I am using player-sdfat-a2dp.ino example sketch to play music from an SD card to a bluetooth speaker using an ESP32.

When I upload the sketch to the ESP32 from PlatformIO and start the device monitor, everything seems to be working; the bluetooth speaker is connected, music is playing, and I can move the bluetooth speaker around the room. The moment I exit the device monitor script and restart the esp32, the bluetooth range is severely limited. It will stop playing the music if I move the speaker more than a few inches away from the esp32. This also happens when I use power from the wall. The only time I was able to get it to work was when I had the serial monitor running. This is not ideal because I would like to plug the ESP32 into the wall and have it play music to a bluetooth speaker. I do not want to have to constantly run the serial monitor.

Here is my platformio.ini file:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
build_flags = -DCORE_DEBUG_LEVEL=5 -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -Wno-format-extra-args 
monitor_speed = 115200
board_build.partitions = huge_app.csv
lib_ldf_mode = chain+
lib_deps = 
	https://github.com/pschatzmann/arduino-audio-tools
	https://github.com/pschatzmann/arduino-libhelix
	https://github.com/greiman/SdFat
	https://github.com/pschatzmann/ESP32-A2DP

Device Description

ESP-WROOM-32

Sketch

/**
 * @file player-sdfat-a2dp.ino
 * @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-player/player-sdfat-a2dp/README.md
 * 
 * @author Phil Schatzmann
 * @copyright GPLv3
 */

//remove this, to find issues regarding mp3 decoding
#define HELIX_LOGGING_ACTIVE false

#include "AudioTools.h"
#include "AudioLibs/A2DPStream.h"
#include "AudioLibs/AudioSourceSDFAT.h"
#include "AudioCodecs/CodecMP3Helix.h"

const char *startFilePath="/";
const char* ext="mp3";
AudioSourceSDFAT source(startFilePath, ext); // , PIN_AUDIO_KIT_SD_CARD_CS);
A2DPStream out;
MP3DecoderHelix decoder;
AudioPlayer player(source, out, decoder);


void setup() {
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Warning);

  // Setting up SPI if necessary with the right SD pins by calling 
  // SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);

  // setup output - We send the test signal via A2DP - so we conect to a Bluetooth Speaker
  auto cfg = out.defaultConfig(TX_MODE);
  //cfg.name = "LEXON MINO L";  // set the device here. Otherwise the next available device is used for output
  //cfg.auto_reconnect = true;  // if this is use we just quickly connect to the last device ignoring cfg.name
  out.begin(cfg);

  // setup player
  player.setVolume(0.1);
  player.begin();

}

void loop() {
  player.copy();
}

Other Steps to Reproduce

Things I have tried or learned:

  • My computer does not have bluetooth support, so the ESP32 cannot be using the computer’s bluetooth range when it is working in debug mode (therefore this is probably a software issue and nothing is wrong with the board itself)
  • I used multiple different cables with multiple outlets and nothing worked except for the device monitor.
  • Running the device monitor works, but unplugging and replugging the esp32 caused the bluetooth range to diminish
  • I tried multiple bluetooth speakers in case it was the speakers fault, and they all resulted in the same issue
  • I tried multiple ESP32s and they all also result in the same issue
  • I also tried updating the firmware on one of the boards and still did not fix the issue
  • I tried streams-generator-a2dp.ino example sketch with an ESP32 with no pins connected (as this sketch sends a sine wave and maybe the SD reader did something), but it still had the same issue.
  • I tried switching to the denky32 board and removing the build_flags in the platformio.ini file, but I got the same issue in both cases
  • I tried switching to the espidf framework, but that broke a whole ton of things.
  • I tried increasing the TX power level of the bluetooth to P9 with esp_bredr_tx_power_set in the btStart() method and that did not work either.
  • I tried setting the bluetooth mode to ESP_BT_MODE_BTDM in BluetoothA2DPCommon.h, and that didn't work either.
  • I tried using the ArudinoIDE on both a windows and mac computer in case PlatformIO was doing something weird, but the bluetooth range was still limited
  • I also posted on the PlatformIO forum in case there is some weird setting or function I am missing: https://community.platformio.org/t/esp32-bluetooth-range-limited-unless-debugging/39905

What is your development environment

PlatformIO

I have checked existing issues, discussions and online documentation

  • I confirm I have checked existing issues, discussions and online documentation
@pschatzmann
Copy link
Owner

Did you try to set the log level to a reasonable value ?
You should use 5 only to debug your functionality and otherwise leave it at 2 (to see warnings) or 1 (to see errors only)

@Al-Zahir
Copy link
Author

Yes, the AudioLogger is set to Warning in the setup function of the sketch. I also tried removing the build_flags entirely and I still got the same issue. I just tried to remove the logging entirely and see if that would help, but I still got the same issue.

The problem is, I cannot debug this, because it works properly in debug. Everytime I try to see the logs, it works as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants