SteveEasley / pyjvcprojector

A python library for controlling a JVC Projector over a network connection.
MIT License
0 stars 1 forks source link

Timeout error on handshake #4

Open evershade opened 5 months ago

evershade commented 5 months ago

I've been trying to connect to my JVC LX-NZ30 projector via Home Assistant which seems to use this module. Was getting a generic connection message so I traced down to here and tried to run this module directly form Python on my Home Assistant server.

Here's my test code, based on your example:

import asyncio

from jvcprojector.projector import JvcProjector
from jvcprojector import const

async def main():
    jp = JvcProjector(host="192.168.1.19", port=4661, timeout=2)
    await jp.connect()

    print("Projector info:")
    print(await jp.get_info())

    await jp.disconnect()

asyncio.run(main())

Here's the error output I get:

Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/streams.py", line 689, in read
    await self._wait_for_data('read')
  File "/usr/lib/python3.11/asyncio/streams.py", line 522, in _wait_for_data
    await self._waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/jvcprojector/device.py", line 117, in _connect
    data = await self._conn.read(len(PJOK))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/jvcprojector/connection.py", line 50, in read
    return await asyncio.wait_for(self._reader.read(n), timeout=self._timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/homeassistant/jvc_get_info.py", line 15, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/homeassistant/jvc_get_info.py", line 8, in main
    await jp.connect()
  File "/usr/local/lib/python3.11/dist-packages/jvcprojector/projector.py", line 90, in connect
    if not await self.test():
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/jvcprojector/projector.py", line 152, in test
    await self._send([cmd])
  File "/usr/local/lib/python3.11/dist-packages/jvcprojector/projector.py", line 180, in _send
    await self._device.send(cmds)
  File "/usr/local/lib/python3.11/dist-packages/jvcprojector/device.py", line 73, in send
    await self._connect()
  File "/usr/local/lib/python3.11/dist-packages/jvcprojector/device.py", line 119, in _connect
    raise JvcProjectorConnectError("Handshake init timeout") from err
jvcprojector.error.JvcProjectorConnectError: Handshake init timeout

It seems to be failing waiting on a handshake response. I've seen other mention of this handshake protocol on the web but the LX-NZ30 doesn't seem to require/support it. I've managed to successfully control my projector with as little as this:

import socket
import binascii

host = '192.168.1.19'
port = 4661

ctrl_power_on = b'\x06\x14\x00\x04\x00\x34\x11\x00\x00\x5D'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.send(ctrl_power_on)

received_data = s.recv(1024)
print (binascii.hexlify(received_data))
SteveEasley commented 5 months ago

Oh bummer, it does look like its fundamentally an entirely different protocol. It's going to take a fair amount of work to restructure the code to provide multiple device/protocol implementations. I think the code is already a good bit there in its current structure though. I might start looking at it in the coming days.

SteveEasley commented 5 months ago

I have been talking to a JVC support person for more context around the various protocols to help inform the new development. Will report when I have more info.

evershade commented 4 months ago

Cool, thanks for the update!

I got these from JVC support, I'm guessing you'll get something similar.

Sean LX-NZ30_External_Command_List_r.pdf https://drive.google.com/file/d/1JYmgdmCFSBAHSAQoPQWSEPL2rOn1rIf1/view?usp=drivesdk

Setting of LAN password for SB327 Compliance.pdf https://drive.google.com/file/d/1fgpsOd_s47UyX116d4IGVkdpAS50G5Ua/view?usp=drivesdk

On Tue, Jan 30, 2024, 16:17 Steve Easley @.***> wrote:

I have been talking to a JVC support person for more context around the various protocols to help inform the new development. Will report when I have more info.

— Reply to this email directly, view it on GitHub https://github.com/SteveEasley/pyjvcprojector/issues/4#issuecomment-1918134226, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADSWJOVFIXYF4BJN42ZZV3YRGER5AVCNFSM6AAAAABCHWWO7GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJYGEZTIMRSGY . You are receiving this because you authored the thread.Message ID: @.***>