04-22-2021, 04:38 PM
I have had an issue with some python code, I'm running on my moode installation, where the code breaks after I updated moode, and enabled bluetooth. I addressed the issue here: http://moodeaudio.org/forum/showthread.php?tid=3709 although my initial premise was completely wrong. After asking here: https://github.com/Mic92/python-mpd2/issues/171 , I got a bit closer to the issue.
It turns out that Bluetooth apparently breaks the connection to mpd in python-mpd2
If I run the following code:
Everything runs fine until I connect a bluetooth device, then this happens:
If i run the code at startup, through etc/rc.local, the code breaks immediately.
1. Is it expected behavior, that mpd closes/breaks the connection, when a Bluetooth connection is made?
2. Is there any explanation as to why mpd would close/break the connection immediately, when I start the script from etc/rc.local?
It turns out that Bluetooth apparently breaks the connection to mpd in python-mpd2
If I run the following code:
Code:
import logging, mpd, time
logging.basicConfig(level=logging.DEBUG)
client = mpd.MPDClient()
client.timeout = None
client.idletimeout = None
client.connect("localhost", 6600)
print(client.status())
while True:
if client.status()['state'] == "play": # Playing or Airplay active
print(client.status())
else: # Either stopped or paused
print(client.status())
time.sleep(0.1)
client.close() # send the close command
client.disconnect() # disconnect from the server
Everything runs fine until I connect a bluetooth device, then this happens:
Code:
DEBUG:mpd.base:Calling MPD status()
DEBUG:mpd.base:Calling MPD status()
{'volume': '0', 'repeat': '0', 'random': '0', 'single': '0', 'consume': '0', 'partition': 'default', 'playlist': '2', 'playlistlength': '7', 'mixrampdb': '0.000000', 'state': 'play', 'song': '6', 'songid': '7', 'time': '335:335', 'elapsed': '334.685', 'bitrate': '32', 'duration': '334.889', 'audio': '44100:24:2'}
DEBUG:mpd.base:Calling MPD status()
DEBUG:mpd.base:Calling MPD status()
{'volume': '0', 'repeat': '0', 'random': '0', 'single': '0', 'consume': '0', 'partition': 'default', 'playlist': '2', 'playlistlength': '7', 'mixrampdb': '0.000000', 'state': 'play', 'song': '6', 'songid': '7', 'time': '335:335', 'elapsed': '334.788', 'bitrate': '32', 'duration': '334.889', 'audio': '44100:24:2'}
DEBUG:mpd.base:Calling MPD status()
DEBUG:mpd.base:Calling MPD status()
INFO:mpd.base:Calling MPD disconnect()
Traceback (most recent call last):
File "mpd_test2.py", line 15, in
print(client.status())
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 469, in mpd_command
return wrapper(self, name, args, callback)
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 532, in _execute
return retval()
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 454, in command_callback
res = function(self, self._read_lines())
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 394, in _parse_object
objs = list(self._parse_objects(lines))
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 240, in _parse_objects
for key, value in self._parse_pairs(lines):
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 235, in _parse_pairs
for line in lines:
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 586, in _read_lines
line = self._read_line()
File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 571, in _read_line
raise ConnectionError("Connection lost while reading line")
mpd.base.ConnectionError: Connection lost while reading line
root@moode:/home/pi#
If i run the code at startup, through etc/rc.local, the code breaks immediately.
1. Is it expected behavior, that mpd closes/breaks the connection, when a Bluetooth connection is made?
2. Is there any explanation as to why mpd would close/break the connection immediately, when I start the script from etc/rc.local?