sle118 / squeezelite-esp32

ESP32 Music streaming based on Squeezelite, with support for multi-room sync, AirPlay, Bluetooth, Hardware buttons, display and more
1.22k stars 109 forks source link

1231 and 1245 won't connect to BT speaker #207

Closed daduke closed 1 year ago

daduke commented 1 year ago

Hi,

I use BT output to Divoom speakers [1] (yes I know it's not the preferred output, but it's what they have and it's always been working great). With 1231 (and 1234), squeezelite won't connect to those speakers any more. 1230 still works. Hardware: a naked WROVER module. Log output at the end. Let me know if I can test anything else.

thanks, -Christian

[1] https://www.divoom-gz.com/product/tivoo.html

log:

I (1875) esp_app_main: Setting up config subsystem.
W (1945) nvs_utilities: Configuration memory usage.  Heap internal:224535 (min:224407) (used:200) external:4058503 (min:4051051) (used:12916)
I (1945) esp_app_main: Registering default values
I (1945) system_api: Base MAC address is not set
I (1945) system_api: read default base MAC address from EFUSE
W (1955) config: Waiting for config commit ...
I (2945) config: configuration has some uncommitted entries
I (2945) config: Committing configuration to nvs. Locking config object.
I (2945) config: Done Committing configuration to nvs.
I (2945) config: Config committed!
I (2945) esp_app_main: Configuring services
I (2945) services: Configuring I2C sda:-1 scl:-1 port:1 speed:400000
W (2945) services: no I2C configured
I (2955) services: Configuring SPI mosi:-1 miso:-1 clk:-1 host:1 dc:-1
W (2955) services: no SPI configured
W (2955) led: LED GPIO -1 ignored
W (2955) led: LED GPIO -1 ignored
I (2955) led: Configuring LEDs green:-1 (active:0 -1%), red:-1 (active:0 -1%)
I (2955) battery: No battery
I (2955) monitor: Initializing monitoring
I (2955) monitor: Heap internal:225327 (min:224315) external:4042023 (min:4042003) dma:217131 (min:216131)
I (2955) esp_app_main: Initializing display
I (2955) display: Trying to configure display with N/A
W (2955) display: No display driver
I (2955) esp_app_main: Checking if certificates need to be updated
I (2955) esp_app_main: About to check if certificates need to be updated in flash
I (2955) esp_app_main: Running partition [ota_0] type 0 subtype 16 (offset 0x00150000)
I (2955) esp_app_main: Running version: local.500.cmake-master
I (2955) esp_app_main: Certificate version: I2S-4MFlash.16.2.1230.master-v4
W (2955) esp_app_main: Found a different software version. Updating certificates
I (3005) messaging: HTTPS Certificates were updated with version: local.500.cmake-master
I (3005) esp_app_main: Checking for update url
W (3005) config: Value not found for key fwurl
W (3005) config: Value not found for key
I (3005) esp_app_main: Starting Network Manager
I (3005) uart: queue free spaces: 3
W (3005) config: Value not found for key apdelay
I (3005) network_handlers: Network manager configuration: polling max 10176, polling min 15000, ap delay 20000, dhcp timeout 8000, eth timeout 8000
W (3005) network_wifi: No known access point found
I (3005) network_wifi: Adding legacy/active wifi connection to the known list
I (3005) http_server: Initializing HTTP Server
I (3015) network_ethernet: Attempting to initialize Ethernet
I (3015) network_ethernet: No Ethernet configuration, or configuration invalid
I (3025) wifi:wifi driver task: 3ffdfd04, prio:23, stack:6656, core=0
I (3035) wifi:wifi firmware version: eb52264
I (3035) wifi:wifi certification version: v7.0
I (3035) wifi:config NVS flash: enabled
I (3035) wifi:config nano formating: disabled
I (3045) wifi:Init data frame dynamic rx buffer num: 40
I (3045) wifi:Init management frame dynamic rx buffer num: 40
I (3045) wifi:Init management short buffer num: 32
I (3045) wifi:Init static tx buffer num: 12
I (3045) wifi:Init tx cache buffer num: 32
I (3045) wifi:Init static rx buffer size: 1600
I (3045) wifi:Init static rx buffer num: 12
I (3045) wifi:Init dynamic rx buffer num: 40
I (3045) wifi_init: tcpip mbox: 32
I (3045) wifi_init: udp mbox: 32
I (3045) wifi_init: tcp mbox: 32
I (3045) wifi_init: tcp tx win: 8192
I (3045) wifi_init: tcp rx win: 32768
I (3045) wifi_init: tcp mss: 1440
I (3045) wifi_init: WiFi/LWIP prefer SPIRAM
I (3045) network_wifi: Starting wifi
I (3045) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
W (3045) phy_init: failed to load RF calibration data (0xffffffff), falling back to full calibration
I (3295) wifi:mode : sta (ac:67:b2:f2:3d:dc)
I (3295) wifi:enable tsf
I (3295) network_handlers: Existing wifi config found. Attempting to connect.
I (3295) network: Starting DHCP client
I (3305) network_wifi: Wifi Connecting to horeizoIoT...

Type 'help' to get the list of commands.
Use UP/DOWN arrows to navigate through command history.
Press TAB when typing command name to auto-complete.

To automatically execute lines at startup:
    Set NVS variable autoexec (U8) = 1 to enable, 0 to disable automatic execution.
    Set NVS variable autoexec[1~9] (string)to a command that should be executed automatically

****************************
Your terminal application does not support escape sequences.
Line editing and history features are disabled.
On Windows, try using Putty instead.
****************************
W (3315) console: Processing autoexec commands while network manager active.  Wifi related commands will be ignored.
I (3315) console: autoexec is set to perform auto-process
I (3325) console: Running command autoexec1 = squeezelite -b 500:2000 -d all=info -C 30 -W -o BT -R -Z 192000 -s 192.168.0.1 -n "Bad"
W (3325) config: Value not found for key autoexec2
squeezelite-esp32> I (3325) squeezelite_cmd: Calling squeezelite
[00:07:56.646243] stream_init:387 init stream
[00:07:56.646932] sb_controls_init:244 initializing audio (buttons/rotary/ir) controls (raw:0)
[00:07:56.647198] sb_displayer_init:318 no display or led visualizer for LMS
[00:07:56.647379] output_init_embedded:70 init device: BT
[00:07:56.648465] equalizer_init:42 initializing equalizer
[00:07:56.649166] output_init_common:433 supported rates: 44100
[00:07:56.649436] output_init_embedded:86 init Bluetooth
I (3325) BTDM_INIT: BT controller compile version [6a07b06]
[00:07:56.650307] output_visu_init:75 Initialize VISUEXPORT 512 16 bits samples
[00:07:56.650906] output_init_embedded:100 init completed.
[00:07:56.651248] decode_init:153 init decode
[00:07:56.651823] register_alac:547 using alac to decode alc
[00:07:56.652151] register_helixaac:686 using helix-aac to decode aac
[00:07:56.652461] register_vorbis:387 using vorbis to decode ogg
E (3325) btappcore: bt_app_task_handler enable controller failed: ESP_ERR_INVALID_ARG

[00:07:56.652851] register_opus:332 using opus to decode ops
[00:07:56.653066] register_flac:332 using flac to decode ogf,flc
[00:07:56.653247] register_pcm:468 using pcm to decode wav,aif,pcm
[00:07:56.653430] register_mad:417 using mad to decode mp3
[00:07:56.654056] resample_init:159 Resampling with filter 0
[00:07:56.656979] slimproto:942 connecting to 192.168.0.1:3483
[00:07:56.657809] slimproto:967 unable to connect to server 0
I (5345) wifi:new:<10,0>, old:<1,0>, ap:<255,255>, sta:<10,0>, prof:1
I (5895) wifi:state: init -> auth (b0)
I (5905) wifi:state: auth -> assoc (0)
I (5905) wifi:state: assoc -> run (10)
I (5925) wifi:connected with horeizoIoT, aid = 3, channel 10, BW20, bssid = 10:c3:7b:55:6a:51
I (5925) wifi:security: WPA2-PSK, phy: bgn, rssi: -8
I (5925) wifi:pm start, type: 1

I (5985) wifi:AP's beacon interval = 102400 us, DTIM period = 3
I (6515) network: Got an IP address from interface Wifi. IP=192.168.8.33, Gateway=192.168.8.1, NetMask=255.255.255.0, Address was changed
I (6515) esp_netif_handlers: sta ip: 192.168.8.33, mask: 255.255.255.0, gw: 192.168.8.1
I (6515) esp_app_main: Network connected and mDNS initialized with Bad
I (7335) httpd_handlers: serving /messages.json to peer 192.168.2.4 port 18620
[00:08:01.665178] slimproto:989 connected
[00:08:01.665825] sendHELO:153 mac: ac:67:b2:f2:3d:dc
[00:08:01.666063] sendHELO:155 cap: Model=squeezeesp32,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Balance=1,Depth=16,Firmware=v1.0-1234-16,ModelName=SqueezeESP32,MaxSampleRate=192000,alc,aac,ogg,ops,ogf,flc,wav,aif,pcm,mp3
[00:08:01.670133] notify:223 notified server 192.168.0.1 hport 9000 cport 9090
I (8345) network_status: LMS IP: 192.168.0.1, hport: 9000, cport: 9090
[00:08:01.674218] decode_flush:251 decode flush
[00:08:01.674584] output_flush:446 flush output buffer
[00:08:03.001385] codec_open:279 codec open: 'm'
[00:08:03.006192] stream_sock:508 connecting to 192.168.0.1:9000
[00:08:03.032479] stream_sock:582 header: GET /stream.mp3?player=ac:67:b2:f2:3d:dc HTTP/1.0

[00:08:03.035466] handler:54 got equalizer 14
[00:08:03.127968] stream_thread:264 headers: len: 491
HTTP/1.1 200 OK
Server: Logitech Media Server (8.3.1 - 1669201751)
Connection: close
Content-Type: audio/mpeg
Set-Cookie: Squeezebox-albumView=; path=/
Set-Cookie: Squeezebox-expandPlayerControl=true; path=/
Set-Cookie: Squeezebox-expanded-MY_MUSIC=1; path=/
Set-Cookie: Squeezebox-expanded-FAVORITES=1; path=/
Set-Cookie: Squeezebox-expanded-PLUGINS=0; path=/
Set-Cookie: Squeezebox-expanded-PLUGIN_MY_APPS_MODULE_NAME=1; path=/
Set-Cookie: Squeezebox-expanded-RADIO=0; path=/

[00:08:03.163256] mad_decode:247 setting track_start
[00:08:03.163943] resample_newstream:125 disable resampling - rates match
[00:08:03.164101] process_newstream:124 processing: inactive
I (22915) httpd_handlers: serving /status.json to peer 192.168.2.4 port 48278
I (115845) httpd_handlers: serving /status.json to peer 192.168.2.4 port 49891
I (115865) httpd_handlers: serving /config.json to peer 192.168.2.4 port 43235
I (117525) network_wifi: Initiating wifi network scan
I (120015) httpd_handlers: serving /messages.json to peer 192.168.2.4 port 47331
I (151295) telnet: We have a new client connection 57
wizmo2 commented 1 year ago

@sle118, I can look at adding a switch for the legacy pairing support but looking again, this did not get added until 1234.

daduke commented 1 year ago

do I have to pair in a different way?

wizmo2 commented 1 year ago

I had issues with BT recently, and added a PR with a couple of improvements that got merged with 1234. I cant say its very stable, as I still have to reboot / repair. This is especially true if I have it synced with another device.

sle118 commented 1 year ago

We were in the readme that we wouldn't support Bluetooth output anymore. But that doesn't apply to @daduke 🥇

I will try to take a look and make sure we align with the latest espressif demo. As for UI option, that is a possibility and it's actually done via the configuration commands of the console, which expose all their metadata to the UI.

daduke commented 1 year ago

We were in the readme that we wouldn't support Bluetooth output anymore. But that doesn't apply to @daduke 1st_place_medal

awwwwwwwwwww 😍

don't wreck yourself over it. I can stay on 1230.

wizmo2 commented 1 year ago

@sle118 I think there's a sdkconfig change need on the Bluetooth controller configuration for BTDM mode (8462de1c1665da9d8316831c30ab546a224da785)

sle118 commented 1 year ago

@wizmo2 could you be more specific please? I haven't had a chance to dig much into this today

wizmo2 commented 1 year ago

image

wizmo2 commented 1 year ago

@philippe44 changed the bbt controller mode from ESP_BT_MODE_CLASSIC_BT to ESP_BT_MODE_BTDM. The latter requires the IDF option above.

Haven't looked at how you create your images, but I guess you need to update all the build-scripts defaults.

sle118 commented 1 year ago

I will look into this today. hoping this doesn't inflate the binaries too much, as we're really short on Flash right now

philippe44 commented 1 year ago

I did not change anything - that was somebody's else PR

wizmo2 commented 1 year ago

I did not change anything - that was somebody's else PR

Apologies!

philippe44 commented 1 year ago

There is like 15kB (of flash!) or less left and it took me extraordinary measures to make cspot fit so this might be challenging

sle118 commented 1 year ago

Too bad it's not simple to create dynamic linked libraries. We could compile out some features and then download/run them on demand. I think I just had an idea. @philippe44 I'll ping you later

wizmo2 commented 1 year ago

I've made a some progress on bt source capabilities,

  1. I'm not convinced of the need for BTDM. If we are not going to use BLE, then I don't think its needed. Saying that, it does not look like there is much of an overhead in flash or memory use when using BTDM without actually implementing BLE.
  2. I have code that is able to successfully allow a device to reconnect at boot. This actually helps significantly, as it makes bt output a lot more practical, plus some of my devices connect with choppy sound on discovery connection, but then is fine when reconnecting from a ESP reboot.

As part of the investigation, I have made a lot of changes to optimize the code (mostly to get a grip of whats going on). So I'm not sure if its ready for a PR. It's also raised more questions than answers, making the project a little more intriguing!. For example, I have a couple of JBL devices that are always choppy. I vaguely remember there are some bit-rate configurations in Squeezelite core that may help, but would think that there is probably a way to make this automatic.

@sle118 and @philippe44 Do you think I should submit a draft PR as-is, or do I just keep at it for a while?

philippe44 commented 1 year ago

You should submit a PR if you want our opinions :smile: and AFAIC, I'd be interested to see the changes. If you need help for the sample/bitrate changes, let me know. The "choppy" might simply be a lack of buffering that likely have a very simple solution, but will then require a delay to be added in LMS for such players, if you want sync.

Now, the whole "multiple sources" in squeezelite-esp32 is a dirty hack but I'm not sure a refactoring to have a "plug-in" architecture makes sense. It's not like we are going to add many other clients in addition to LMS, BT, AirPlay and Spotify. Chromecast is simply not possible.

philippe44 commented 1 year ago

re BTDM, I finally got it so yes @sle118 I think that part in https://github.com/sle118/squeezelite-esp32/commit/8462de1c1665da9d8316831c30ab546a224da785 is a typo that should be removed.

philippe44 commented 1 year ago

I've pushed some Spotify changes at brought rollback the BTDM change (just the one variable at init)

sle118 commented 1 year ago

@daduke could you please confirm that BT Source works now for you?

wizmo2 commented 1 year ago

I think this is now closed with #210 ?

I'll push a draft PR with an optimized bt_source hopefully before EOY. Have made a number of improvements, but want to work on a few compatibility issues.

@daduke, but now I've have Divoom timebox-evo and now need to integrate bt path-through and HA integration for the built in display!

daduke commented 1 year ago

@daduke, but now I've have Divoom timebox-evo and now need to integrate bt path-through and HA integration for the built in display!

nice. The displays of the Tivoo and Tivoo Max are not readily accessible (one would have to reverse engineer the BT protocol I guess)

sle118 commented 1 year ago

I'll go ahead and close this one then.