Git Product home page Git Product logo

Comments (22)

postlund avatar postlund commented on May 30, 2024

Thanks for reporting! Can you try pairing and run with the --debug flag? Would help me with troubleshooting.

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

sure!

root@raspberrypi:/home/homeassistant/.homeassistant # atvremote --debug pair
Use pin 1234 to pair with "pyatv" (press ENTER to stop)
Using pairing guid: 0x15543EE13C74C43C
Note: If remote does not show up, try rebooting your Apple TV
DEBUG: Started pairing web server at port 37832
DEBUG: Published zeroconf service: ServiceInfo(type='_touch-remote._tcp.local.', name='0000000000000000000000000000000000000001._touch-remote._tcp.local.', address=b'\x7f\x00\x01\x01', port=37832, weight=0, priority=0, server='0000000000000000000000000000000000000001._touch-remote._tcp.local.', properties={b'RemN': b'Remote', b'Pair': '15543EE13C74C43C', b'DvTy': b'iPod', b'RemV': b'10000', b'DvNm': 'pyatv', b'txtvers': b'1'})

then complete silence... 👎

from pyatv.

postlund avatar postlund commented on May 30, 2024

Ok, so that basically means that the Apple TV does not succeed when it tries to connect back to pyatv. A couple of things that comes to mind:

Do you have iptables configured?
Multiple network cards on your rpi?
Are both devices on the same network?
Have you tried from another computer?
Are you running from a virtual machine or container?

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

Something seems to be up with my network.

No iptables as far as I know,
Only 1 network card on the rpi
Same network, same wifi router, different bands (2,4 and 5)
Tried from my mac, things started out interesting. At first it seem to accept my pin, then a spinning wheel for a minute or two, then message "invalid pin".
No virtual machine.

Will continue investigate the network traffic, all though no network guru. Do you have any tips for areas to look into extra?

Thanks

from pyatv.

postlund avatar postlund commented on May 30, 2024

I see the initial problem. The address announced in the bonjour service is 127.0.1.1, that won't work. I will have to come up with a better solution. Can you provide the same output from your mac, just to see if it's the same issue there?

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

Cool 👍

here you go

Marcus-MacBook-Pro-2:pyatv Marcus$ atvremote --debug pair
Use pin 1234 to pair with "pyatv" (press ENTER to stop)
Using pairing guid: 0x7C3E560451EE7657
Note: If remote does not show up, try rebooting your Apple TV
DEBUG: Started pairing web server at port 49933
DEBUG: Published zeroconf service: ServiceInfo(type='_touch-remote._tcp.local.', name='0000000000000000000000000000000000000001._touch-remote._tcp.local.', address=b'\xc0\xa8\x01\x02', port=49933, weight=0, priority=0, server='0000000000000000000000000000000000000001._touch-remote._tcp.local.', properties={b'DvNm': 'pyatv', b'RemV': b'10000', b'DvTy': b'iPod', b'RemN': b'Remote', b'txtvers': b'1', b'Pair': '7C3E560451EE7657'})

Thanks for your engagement

from pyatv.

postlund avatar postlund commented on May 30, 2024

The log from your mac looks good from what I can see. Can you verify that it had IP-address 192.168.1.2? Otherwise that might be a problem.

Of course, I want to sort out as many bugs as possible! 😄 It's good that you reported the issue.

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

Yes, My Mac is using IP 192.168.1.2

from pyatv.

postlund avatar postlund commented on May 30, 2024

Ok, that's good start. Then we should probably check if it's possible to reach the web server correctly. First of all, just run atvremote --debug pair as before and look for the port property (it is randomly chosen every time you try to pair). In the case above it's 49933. Then try to access it locally at http://127.0.0.1:49933, you should get a HTTP 500 error if it works as expected. If that works, try doing the same thing from another device on your network, but of course use the network address, e.g. http://192.168.1.2:49933. We can try to draw additional conclusions after that.

from pyatv.

postlund avatar postlund commented on May 30, 2024

I tried to make a fix for the initial issue and have now pushed a branch, pair_ip_fix. It is not tested so I cannot guarantee anything, but I think it should work. Please give it a try when you get some time!

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

nice! I will try it out this instant. But first, here are the findings on your request to try out the webserver:

atvremote hosed on rpi:

http request from rpi:

[pi@raspberrypi:~ $ curl -I http://127.0.0.1:42104
HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=utf-8
Content-Length: 141
Date: Wed, 26 Apr 2017 17:57:33 GMT
Server: Python/3.4 aiohttp/2.0.7
Connection: close

http request from mac:

Marcus-MBP:Downloads Marcus$ curl -I http://192.168.1.6: 42104
HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=utf-8
Content-Length: 141
Date: Wed, 26 Apr 2017 17:58:34 GMT
Server: Python/3.4 aiohttp/2.0.7
Connection: close

atvremote debug:

[pi@raspberrypi:~ $ atvremote --debug pair
Use pin 1234 to pair with "pyatv" (press ENTER to stop)
Using pairing guid: 0xC4CE5A839A308091
Note: If remote does not show up, try rebooting your Apple TV
DEBUG: Started pairing web server at port 42104
DEBUG: Published zeroconf service: ServiceInfo(type='_touch-remote._tcp.local.', name='0000000000000000000000000000000000000001._touch-remote._tcp.local.', address=b'\x7f\x00\x01\x01', port=42104, weight=0, priority=0, server='0000000000000000000000000000000000000001._touch-remote._tcp.local.', properties={b'DvTy': b'iPod', b'txtvers': b'1', b'RemN': b'Remote', b'DvNm': 'pyatv', b'RemV': b'10000', b'Pair': 'C4CE5A839A308091'})
ERROR: Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/aiohttp/web_protocol.py", line 417, in start
    resp = yield from self._request_handler(request)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 141, in coro
    res = func(*args, **kw)
  File "/usr/local/lib/python3.4/dist-packages/pyatv/pairing.py", line 85, in handle_request
    service_name = request.rel_url.query['servicename']
  File "multidict/_multidict.pyx", line 124, in multidict._multidict._Base.__getitem__ (multidict/_multidict.c:3486)
  File "multidict/_multidict.pyx", line 119, in multidict._multidict._Base._getone (multidict/_multidict.c:3421)
KeyError: "Key not found: 'servicename'"
INFO: 127.0.0.1 - - [26/Apr/2017:17:57:37 +0000] "HEAD / HTTP/1.1" 500 189 "-" "curl/7.38.0"

atvremote hosed on mac:

http request from rpi:
no response.

http request from mac:

Marcus-MBP:JavaVirtualMachines Marcus$ curl -I http://127.0.0.1:61881
HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=utf-8
Content-Length: 141
Date: Wed, 26 Apr 2017 18:06:08 GMT
Server: Python/3.6 aiohttp/2.0.7
Connection: close

atvremote debug:

Marcus-MBP:Downloads Marcus$ atvremote --debug pair
Use pin 1234 to pair with "pyatv" (press ENTER to stop)
Using pairing guid: 0x84B9167772A108CF
Note: If remote does not show up, try rebooting your Apple TV
DEBUG: Started pairing web server at port 61881
DEBUG: Published zeroconf service: ServiceInfo(type='_touch-remote._tcp.local.', name='0000000000000000000000000000000000000001._touch-remote._tcp.local.', address=b'\xc0\xa8\x01\x02', port=61881, weight=0, priority=0, server='0000000000000000000000000000000000000001._touch-remote._tcp.local.', properties={b'DvNm': 'pyatv', b'RemV': b'10000', b'DvTy': b'iPod', b'RemN': b'Remote', b'txtvers': b'1', b'Pair': '84B9167772A108CF'})
ERROR: Error handling request
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 417, in start
    resp = yield from self._request_handler(request)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyatv/pairing.py", line 85, in handle_request
    service_name = request.rel_url.query['servicename']
  File "multidict/_multidict.pyx", line 124, in multidict._multidict._Base.__getitem__ (multidict/_multidict.c:3486)
  File "multidict/_multidict.pyx", line 119, in multidict._multidict._Base._getone (multidict/_multidict.c:3421)
KeyError: "Key not found: 'servicename'"
INFO: 127.0.0.1 - - [26/Apr/2017:18:06:59 +0000] "HEAD / HTTP/1.1" 500 189 "-" "curl/7.51.0"

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

good news @postlund ! changes made in branch pair_ip_fix seems to have solved the issue for me. I thank you a lot for the help and for a great piece of software

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

Another thing though, after pairing, im unable to authenticate the apple tv with Home Assistant with the new login id:

pairing:

pi@raspberrypi:~ $ atvremote --debug pair
Use pin 1234 to pair with "pyatv" (press ENTER to stop)
Using pairing guid: 0x6F6B5B10EEB098DB
Note: If remote does not show up, try rebooting your Apple TV
DEBUG: Started pairing web server at port 41133
DEBUG: Published zeroconf service: ServiceInfo(type='_touch-remote._tcp.local.', name='0000000000000000000000000000003232235782._touch-remote._tcp.local.', address=b'\xc0\xa8\x01\x06', port=41133, weight=0, priority=0, server='0000000000000000000000000000003232235782._touch-remote._tcp.local.', properties={b'DvTy': b'iPod', b'Pair': '6F6B5B10EEB098DB', b'RemV': b'10000', b'txtvers': b'1', b'DvNm': 'pyatv', b'RemN': b'Remote'})
INFO: Got pairing request from F0A7463F7CACADF5C31C79632405064318887B44 with code 308d593ce00196a6c268bbc33c58624d
DEBUG: Got code 308d593ce00196a6c268bbc33c58624d, expects 308d593ce00196a6c268bbc33c58624d
INFO: 192.168.1.3 - - [26/Apr/2017:18:45:27 +0000] "GET /pair?pairingcode=308D593CE00196A6C268BBC33C58624D&servicename=F0A7463F7CACADF5C31C79632405064318887B44 HTTP/1.1" 200 199 "-" "tvcontrold (unknown version) CFNetwork/811.5.4 Darwin/16.6.0"

DEBUG: Shutting down pairing server
Pairing seems to have succeeded, yey!
You may now use this login id: 0x6F6B5B10EEB098DB

ha configuration:

media_player:
  - platform: apple_tv
    host: 192.168.1.3
    login_id: 0x6F6B5B10EEB098DB
    name: vardagsrum

ha log:

17-04-26 20:47:34 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
17-04-26 20:47:34 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
17-04-26 20:47:34 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503

from pyatv.

postlund avatar postlund commented on May 30, 2024

Nice that the pairing works now! I will prepare the changes for 0.3.0.

That seems strange. Can you try it with atvremote and paste the debug printouts?

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

sure, heres the output. Nothing happens on the atv 192.168.1.3 when sending pause command below:

[pi@raspberrypi:~ $ atvremote --address 192.168.1.3 --login_id 0x6F6B5B10EEB098DB --debug pause
DEBUG: GET URL: http://192.168.1.3:3689/login?pairing-guid=0x6F6B5B10EEB098DB&hasFP=1
DEBUG: Data[32]: b'6d6c6f67000000186d73747400000004000000c86d6c69640000000400000003'
DEBUG: _login_request: mlog: [container, dmap.loginresponse]
  mstt: 200 [uint, dmap.status]
  mlid: 3 [uint, dmap.sessionid]

INFO: Logged in and got session id 3
DEBUG: GET URL: http://192.168.1.3:3689/ctrl-int/1/playstatusupdate?session-id=3&revision-number=0
DEBUG: Data[207]: b'636d7374000000c76d73747400000004000000c8636d7372000000040000000563616673000000010063616665000000010063617665000000010063617673000000010063616e74000000040011b70163617374000000040013b2d8636170730000000104636173680000000100636172700000000100636161720000000400'...
DEBUG: _get_request: cmst: [container, dmcp.playstatus]
  mstt: 200 [uint, dmap.status]
  cmsr: 5 [uint, dmcp.serverrevision]
  cafs: 0 [uint, dacp.fullscreen]
  cafe: False [bool, dacp.fullscreenenabled]
  cave: False [bool, dacp.dacpvisualizerenabled]
  cavs: 0 [uint, dacp.visualizer]
  cant: 1160961 [uint, dacp.remainingtime]
  cast: 1290968 [uint, dacp.tracklength]
  caps: 4 [uint, dacp.playstatus]
  cash: 0 [uint, dacp.shufflestate]
  carp: 0 [uint, dacp.repeatstate]
  caar: 6 [uint, dacp.albumrepeat]
  caas: 2 [uint, dacp.albumshuffle]
  cann: And the Turtle Sense [str, daap.nowplayingtrack]
  caks: 1 [uint, unknown tag]
  casc: 1 [uint, unknown tag]
  cavc: True [bool, dacp.volumecontrollable]
  casu: 0 [uint, dacp.su]

DEBUG: Already logged in, re-using seasion id 3
DEBUG: POST URL: http://192.168.1.3:3689/ctrl-int/1/pause?session-id=3&prompt-id=0
DEBUG: Data[0]: b''
DEBUG: _post_request: 

from pyatv.

postlund avatar postlund commented on May 30, 2024

I'm starting to believe that the commands are context (app) dependent on the ATV4. The plex app is in particular acting strange and I assume that is what you used? If that's the case, there's a section about it in the FAQ (https://github.com/postlund/pyatv/blob/master/docs/faq.rst). Using the DAAP-protocol, there does not seem to be much that can be done at the moment. I'm hoping for better support when I can try to implement the MediaRemote protocol instead (but I'm waiting for ATV5 before I can start that work).

from pyatv.

postlund avatar postlund commented on May 30, 2024

Right... It looks like the login id works correctly with atvremote so the issue should be with Home Assistant. Can you try adding debug logging for pyatv.daap in Home Assistant?

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

here's an output from my two apple tv's:

[pi@raspberrypi:~/.homeassistant $ less /home/pi/.homeassistant/home-assistant.log |grep pyatv.daap
17-05-01 15:13:09 DEBUG (MainThread) [pyatv.daap] GET URL: http://192.168.1.3:3689/login?hsgid=8028610889000196315&hasFP=1
17-05-01 15:13:09 DEBUG (MainThread) [pyatv.daap] GET URL: http://192.168.1.7:3689/login?hsgid=00000000-1092-dc12-7d1d-158da0c84566&hasFP=1
17-05-01 15:13:09 DEBUG (MainThread) [pyatv.daap] Data[3]: b'313033'
17-05-01 15:13:09 DEBUG (MainThread) [pyatv.daap] _login_request: 103: None [_unknown, unknown tag]
17-05-01 15:13:09 DEBUG (MainThread) [pyatv.daap] GET URL: http://192.168.1.3:3689/login?hsgid=8028610889000196315&hasFP=1
17-05-01 15:13:09 DEBUG (MainThread) [pyatv.daap] Data[3]: b'313033'
17-05-01 15:13:09 DEBUG (MainThread) [pyatv.daap] _login_request: 103: None [_unknown, unknown tag]
17-05-01 15:13:10 DEBUG (MainThread) [pyatv.daap] Data[32]: b'6d6c6f67000000186d73747400000004000000c86d6c6964000000040000008d'
17-05-01 15:13:10 DEBUG (MainThread) [pyatv.daap] _login_request: mlog: [container, dmap.loginresponse]
17-05-01 15:13:10 INFO (MainThread) [pyatv.daap] Logged in and got session id 141
17-05-01 15:13:10 DEBUG (MainThread) [pyatv.daap] GET URL: http://192.168.1.7:3689/ctrl-int/1/playstatusupdate?session-id=141&revision-number=0
17-05-01 15:13:10 DEBUG (MainThread) [pyatv.daap] Data[155]: b'636d7374000000936d73747400000004000000c8636d7372000000040000006463616673000000010063616665000000010063617665000000010063617673000000010063617073000000010363617368000000010063617270000000010063616172000000040000000663616173000000040000000263616b730000000101'...
17-05-01 15:13:10 DEBUG (MainThread) [pyatv.daap] _get_request: cmst: [container, dmcp.playstatus]
17-05-01 15:13:10 DEBUG (MainThread) [pyatv.daap] Already logged in, re-using seasion id 141
17-05-01 15:13:10 DEBUG (MainThread) [pyatv.daap] GET URL: http://192.168.1.7:3689/ctrl-int/1/playstatusupdate?session-id=141&revision-number=100

The HASS configuration looks like this:

media_player:
  - platform: apple_tv
    host: 192.168.1.3
    login_id: 0x6F6B5B10EEB098DB
    name: vardagsrum
  - platform: apple_tv
    host: 192.168.1.7
    login_id: 00000000-1092-dc12-7d1d-158da0c84566

I wonder about a few things, to start with, when I browse to http://192.168.1.3:3689/login?hsgid=8028610889000196315&hasFP=1 (the Apple TV and hsgid that I got when I paired the Apple TV with atvremote on the rpi) I'm getting the following text back "103".
But when I browse to http://192.168.1.7:3689/login?hsgid=00000000-1092-dc12-7d1d-158da0c84566&hasFP=1 i get a file downloaded which seems to be the accurate behavior :)

I also wonder about what the difference in HASS is between pairing the remote myself, like you helped me with above, compared to using the "default" login ID generated by command

[pi@raspberrypi:~/.homeassistant $ atvremote scan
Found Apple TVs:
 - Sovrum at 192.168.1.7 (login id: 00000000-1092-dc12-7d1d-158da0c84566)
 - Vardagsrum at 192.168.1.3 (login id: 00000000-1092-dc12-7d1d-158da0c84566)

Am I able to access more controls in the Apple TV through the HASS component when I pair like this? Im wondering about the advantage :)

Thanks in advanced

from pyatv.

postlund avatar postlund commented on May 30, 2024

Interesting! I think that voluptuous (the library doing input validation in Home Assistant) converts your login_id to an integer. You should see the exact same output in the log when it does login as what you have specified in the configuration (including 0x in the beginning). When using the pairing guid, it should also say pairing-guid instead of hsgid , i.e.:

http://192.168.1.3:3689/login?pairing-guid=&hasFP=1

Hopefully that works better. I will have to look at the validation in Home Assistant for this. It's obvious that I haven't tested this much 😉

Honestly, I don't know of any "real" benefit of pairing. It's mainly for people that don't use Home Sharing. Not sure if Home Sharing works if there is no Internet connection though. In that case pairing will work but not the home Sharing part.

from pyatv.

postlund avatar postlund commented on May 30, 2024

So, I got around trying this now. If you leave out quotes around what you enter in configuration.yaml, then voluptuous can automatically do some expansion for you. When entering 0xY where Y is a hex number, it will automatically be converted into an integer (which was my guess). This seems to be the case even when the input is specified as a string, because that's the type I have used in Home Assistant for login_id. So it should work better if you add " or ' around, like this:

media_player:
  - platform: apple_tv
    host: 192.168.1.3
    login_id: '0x6F6B5B10EEB098DB'
    name: vardagsrum

Hope it helps!

from pyatv.

mar-schmidt avatar mar-schmidt commented on May 30, 2024

Works file @postlund - thanks :)

from pyatv.

postlund avatar postlund commented on May 30, 2024

Great @Ronelius, then I think we can close this issue 😄 Thanks for all the help during troubleshooting!

from pyatv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.