ryanolf / node-sonos-nfc

Access your streaming music through physical NFC tokens, like putting on a CD or record. Great for children and adult aesthetics.
MIT License
34 stars 13 forks source link

Unable to play after alexa has played music #15

Open johnnyfleet opened 2 years ago

johnnyfleet commented 2 years ago

Hi there - I'm posting here, but don't know if this should go to one of the underlying libraries. I've noticed a specific scenario which seems to be generating an error when trying to play something using the NFC tag reader.

The issues invovles when music is already playing that was triggered by a request via Alexa and then attempts made to play via nfc tag reader.

Steps to recreate

  1. Reset sonos and raspberry pi.
  2. Play something through the nfc tag - all works fine (see logs below)
  3. Ask alexa to play something e.g. 'Alexa, play Kings of leon'. Music switches and plays new request.
  4. Remove the nfc tag and replace it. Errors with a comment about setting crossfade.
  5. nfc approach will continue to fail, even when the music stopped, until I use the sonos app to choose something manually from spotify/mylibrary.
  6. After manually setting, add the nfc tag, works all fine.

Logs

From pm2 log

1. Add an nfc tag after resetting sonos and raspberry pi

0|npm  | [0] ACS ACR122U 00 00 detected TAG_ISO_14443_3 with UID 041ea9b2ed6c81
0|npm  | [0] 
0|npm  | Read from NFC tag with message:  spotify:user:spotify:playlist:37i9dQZF1DWVFJtzvDHN4L
0|npm  | [0] Detected 'spotify' service request
0|npm  | [0] Resetting repeat
0|npm  | [0] Resetting shuffle
0|npm  | [0] 
0|npm  | Resetting crossfade
0|npm  | [0] Clearing Sonos queue
0|npm  | [0] Fetching URL via HTTP api: http://localhost:5005/Sun Room/spotify/now/spotify:user:spotify:playlist:37i9dQZF1DWVFJtzvDHN4L
0|npm  | [0] 
0|npm  | Sonos API reports:  { status: 'success' }
0|npm  | [0] 
0|npm  | Read from NFC tag with message:  command:shuffle/on
0|npm  | [0] Detected 'command' service request
0|npm  | [0] Fetching URL via HTTP api: http://localhost:5005/Sun Room/shuffle/on
0|npm  | [0] Sonos API reports:  { status: 'success' }
0|npm  | [0] 
0|npm  | Read from NFC tag with message:  command:next
0|npm  | [0] Detected 'command' service request
0|npm  | [0] Fetching URL via HTTP api: http://localhost:5005/Sun Room/next
0|npm  | [0] 
0|npm  | Sonos API reports:  { status: 'success' }

2. Logs after playing something via alexa and then re-tagging the nfc tag

0|npm  | [0] 
0|npm  | ACS ACR122U 00 00: TAG_ISO_14443_3 with UID 041ea9b2ed6c81 removed
0|npm  | [0] 
0|npm  | ACS ACR122U 00 00 detected TAG_ISO_14443_3 with UID 041ea9b2ed6c81
0|npm  | [0] 
0|npm  | Read from NFC tag with message:  spotify:user:spotify:playlist:37i9dQZF1DWVFJtzvDHN4L
0|npm  | [0] Detected 'spotify' service request
0|npm  | [0] Resetting repeat
0|npm  | [0] 
0|npm  | Resetting shuffle
0|npm  | [0] 
0|npm  | Resetting crossfade
0|npm  | [1] 
0|npm  | 2022-08-25T22:11:52.981Z ERROR 
0|npm  | [1]   Error: Got status 500 when invoking /MediaRenderer/AVTransport/Control
0|npm  | [1]     at Object.invoke (/home/pi/node-sonos-nfc/node_modules/sonos-discovery/lib/helpers/soap.js:99:10)
0|npm  | [1]     at /home/pi/node-sonos-nfc/node_modules/sonos-discovery/lib/models/Player.js:682:19
0|npm  | [0] Error: Unexpected response while turning crossfade off: 500

3. Logs after changing song int he sonos app, then re-tagging the nfc tag

0|npm  | [0] ACS ACR122U 00 00: TAG_ISO_14443_3 with UID 041ea9b2ed6c81 removed
0|npm  | [0] 
0|npm  | ACS ACR122U 00 00 detected TAG_ISO_14443_3 with UID 041ea9b2ed6c81
0|npm  | [0] Read from NFC tag with message:  spotify:user:spotify:playlist:37i9dQZF1DWVFJtzvDHN4L
0|npm  | [0] Detected 'spotify' service request
0|npm  | [0] Resetting repeat
0|npm  | [0] 
0|npm  | Resetting shuffle
0|npm  | [0] 
0|npm  | Resetting crossfade
0|npm  | [0] 
0|npm  | Clearing Sonos queue
0|npm  | [0] Fetching URL via HTTP api: http://localhost:5005/Sun Room/spotify/now/spotify:user:spotify:playlist:37i9dQZF1DWVFJtzvDHN4L
0|npm  | [0] 
0|npm  | Sonos API reports:  { status: 'success' }
0|npm  | [0] 
0|npm  | Read from NFC tag with message:  command:shuffle/on
0|npm  | [0] Detected 'command' service request
0|npm  | [0] Fetching URL via HTTP api: http://localhost:5005/Sun Room/shuffle/on
0|npm  | [0] 
0|npm  | Sonos API reports:  { status: 'success' }
0|npm  | [0] Read from NFC tag with message:  command:next
0|npm  | [0] Detected 'command' service request
0|npm  | [0] Fetching URL via HTTP api: http://localhost:5005/Sun Room/next
0|npm  | [0] 
0|npm  | Sonos API reports:  { status: 'success' }

Notes on hardware set up

Just in case it helps to narrow down, this is my set up:

johnnyfleet commented 3 months ago

Cross posted: https://github.com/jishi/node-sonos-http-api/issues/899

johnnyfleet commented 3 months ago

I also tried creating a new instance of node-sonos-http-api on a separate machine using https://github.com/chrisns/docker-node-sonos-http-api.

I updated the usersettings/json to point to it and re-run. This produced the same results. I wanted to check whether a newer version on node-sonos-http-api ficed the issue but it seems not.

I've cross-posted the issue there as seems the error may be lower down the stack than this nfc part of the program.

johnnyfleet commented 3 months ago

I seem to be able to workaround the issue by removing "reset_crossfade": true from the usersettings.json

ryanolf commented 3 weeks ago

Hi there! That's really annoying. I'm glad you found a workaround. I think we should probably not be giving up the music playing when we fail to set crossfade. Apparently the system can't set crossfade in this situation, but that's probably OK. I'll have some time soon to fix this.