vectronic / homebridge-jvc-projector

A Homebridge plugin providing standby control for JVC projectors over IP
MIT License
2 stars 2 forks source link

Basic Error: Command failed #4

Closed aschmidt74 closed 2 years ago

aschmidt74 commented 2 years ago

Hi there & happy holidays! My present works fine otherwise, but refuses to be controlled my your nice plugin ;)

I seem to miss something basic here:

[12/24/2021, 12:41:10 AM] [Beamer] stateTimeout error: Error: Command failed: /usr/bin/python /homebridge/node_modules/homebridge-jvc-projector/dist/get_power_state.py 192.168.0.95
Traceback (most recent call last):
  File "/homebridge/node_modules/homebridge-jvc-projector/dist/get_power_state.py", line 1, in <module>
    from jvc_projector import JVCProjector
ImportError: No module named jvc_projector

wherefrom should jvc_projector be known?!

vectronic commented 2 years ago

Hi there, nice present👍

This isn’t a pure nodejs project - it relies on a python module for the heavy lifting.

Did you follow these installation steps from the readme?

  1. Ensure python is installed and on the path

  2. Install the python project: pip install jvc_projector_remote

aschmidt74 commented 2 years ago

The N5 is a beast and big fun indeed!

Yes, python is installed, and apparently invoked with the script. And yes I installed the package too, but can't verify that location and owner are correct. What's the requirement there?

vectronic commented 2 years ago

Maybe the version of python in use e.g. via the config for this plugin (python_path) is not the same python in use when you did pip install jvc_projector_remote. This would explain why the pip install completed, but when python is invoked from this plugin, it can't find the installed module.

You will need to check the python location used and the path it installs the jvc_projector_remote when you run pip install jvc_projector_remote and ensure the same python location is configured as python_path.

Maybe use a combination of pip show: https://pip.pypa.io/en/stable/cli/pip_show/ and which python (assuming you are on a unix environment).

If this doesn't work you will need to delve deeper following something like this: https://www.devdungeon.com/content/python-import-syspath-and-pythonpath-tutorial#toc-5

Maybe try something like:

pip install jvc_projector_remote

then:

python

>>> from jvc_projector import JVCProjector

as per the article you can also check:

>>> import sys
>>> sys.path

and you might need to set PYTHONPATH

aschmidt74 commented 2 years ago

thank you much for the helping hand! I got it up and running without obvious errors now.

little backround: homebridge runs ina synology docker container little documentation:

/homebridge # pip install jvc_projector_remote                                                      
Requirement already satisfied: jvc_projector_remote in /usr/lib/python3.8/site-packages (0.1.0)
/homebridge # pip show jvc_projector_remote                                                         
Version: 0.1.0                                                                                      
Name: jvc-projector-remote                                                                          
Summary: A small package to control jvc projectors over IP                                          
Home-page: https://github.com/bezmi/jvc_projector                                                   
Author: bezmi                                                                                       
Author-email: None                                                                                  
License: UNKNOWN                                                                                    
Location: /usr/lib/python3.8/site-packages                                                          
Requires:                                                                                           
Required-by:
/homebridge # python                                                                                
Python 2.7.18 (default, Apr 21 2020, 01:56:54)                                                      
[GCC 9.3.0] on linux2                                                                               
Type "help", "copyright", "credits" or "license" for more information.                              
>>> from jvc_projector import JVCProjector                                                          
Traceback (most recent call last):                                                                  
  File "<stdin>", line 1, in <module>                                                               
ImportError: No module named jvc_projector                                                          
>>>

and here's the problem: Python 2.7.18 invoked vs. python3.8 install-path in /usr/bin python was linked to python2 - I removed that and relinked it to python3 looks like this now:

/usr/bin # which python                                                                             
/usr/bin/python                                                                                     
/usr/bin # ls -al pyt*                                                                              
lrwxrwxrwx 1 root root     7 Dec 25 19:46 python -> python3                                         
lrwxrwxrwx 1 root root     9 Dec  2 00:44 python2 -> python2.7                                      
-rwxr-xr-x 1 root root 13992 Apr 21  2020 python2.7                                                 
lrwxrwxrwx 1 root root     9 Dec  1 23:12 python3 -> python3.8                                      
-rwxr-xr-x 1 root root 13992 May  6  2021 python3.8                                                 

I did NOT set a PYTHONPATH in the container environment, for this led to a strange concatenation of paths and is aparently not neccesary.

Homebridge log looks like this now:

[12/25/2021, 8:14:14 PM] [Beamer] Initializing JvcProjectorPower accessory...
[12/25/2021, 8:14:14 PM] [Beamer] projectorIp: 192.168.0.16
[12/25/2021, 8:14:14 PM] [Beamer] pythonPath: /usr/bin/python
[12/25/2021, 8:14:14 PM] [Beamer] setPowerScript: /homebridge/node_modules/homebridge-jvc-projector/dist/set_power_state.py
[12/25/2021, 8:14:14 PM] [Beamer] getPowerScript: /homebridge/node_modules/homebridge-jvc-projector/dist/get_power_state.py
[12/25/2021, 8:14:14 PM] [Beamer] Projector finished initializing!

however: Homebridge log also reads: [12/25/2021, 8:28:14 PM] [Beamer] Returning projector power: OFF whereas the beast is verymuch ON. furthermore I got this:

[12/26/2021, 1:21:37 AM] [Beamer] stateTimeout error: Error: Command failed: /usr/bin/python /homebridge/node_modules/homebridge-jvc-projector/dist/get_power_state.py 192.168.0.16
Traceback (most recent call last):
  File "/homebridge/node_modules/homebridge-jvc-projector/dist/get_power_state.py", line 12, in <module>
    if projector.is_on():
  File "/usr/lib/python3.8/site-packages/jvc_projector/__init__.py", line 182, in is_on
    return self.power_state() in on
  File "/usr/lib/python3.8/site-packages/jvc_projector/__init__.py", line 177, in power_state
    message = self._send_command(Commands.power_status.value, ack=ACKs.power_ack.value)
  File "/usr/lib/python3.8/site-packages/jvc_projector/__init__.py", line 126, in _send_command
    jvc_sock.connect((self.host, self.port)) # connect to projector
ConnectionRefusedError: [Errno 111] Connection refused
vectronic commented 2 years ago

OK so it looks like a network connection issue between homebridge (python module) and the projector:

ConnectionRefusedError: [Errno 111] Connection refused

It could be A. a setup issue or B. this bug noted here:

https://github.com/bezmi/jvc_projector#bugs

For A, can you confirm the IP of the projector is 192.168.0.16 and that from home bridge you can connect to the projector manually (JVC control protocol seems to be port 20554). Use something like http://nmap.org from the synology container:

nmap -A 192.168.0.16/32 -p 20554

You should at least see it is open if you get different behaviour than when trying to connect to another random port e.g. 20555

Maybe also check if you need to enable network control in the projector settings?

For B, it could be that the plugin configured delay for connection_delay_interval is not a long enough delay between commands and hence you see the mentioned bug. I am using a JVC NX7 so maybe it is ok for me, but not for the NX5. If you can confirm point A seems OK, try also increasing connection_delay_interval.

If you still have an issue, send me the full clean logs from home bridge startup and maybe I can see what is happening further. e.g. maybe the delay I have implemented isn't working correctly.

aschmidt74 commented 2 years ago

Thank you for your time spent to get to the bottom of this! Re "A" (tcp connectivity):

pi@raspberrypi:~ $ nmap -A 192.168.0.16/32 -p 20554

Starting Nmap 7.40 ( https://nmap.org ) at 2021-12-27 14:17 CET
Nmap scan report for 192.168.0.16
Host is up (0.0029s latency).
PORT      STATE SERVICE    VERSION
20554/tcp open  tcpwrapped

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 7.56 seconds

port is open, and actually talks JVCish to me:

pi@raspberrypi:~ $ telnet 192.168.0.16 20554
Trying 192.168.0.16...
Connected to 192.168.0.16.
Escape character is '^]'.
PJ_OK
PJNAK
PJNAKPJREQ
PJACK

as for B (intercommand delay): I've set "connection_delay_interval": 2, (was 1) and - the errors are gone.

and lo and behold, on Boxing Day in the year two after Corona I can switch my N5 on and off!

Yet the plebs was dissatisfied and asked for more :-> For sure you've already thought of expressing various other commands in addition to power-on/off :-> just curious II; Do you see a powerstate=ON reflected in the homebridge/homekit button? Mine remains gray, and [Beamer] Returning projector power: OFF is logged even when device is ON.

vectronic commented 2 years ago

While the projector is turning on or off it reports the previous state for a while. Is that what you are seeing?

My projector looks like the following in the home app and it will reflect the state as on when it is turns on from here. 4C081835-DC00-4052-B6EF-8F016E856B7E

AviatorBimmer commented 2 years ago

and here's the problem: Python 2.7.18 invoked vs. python3.8 install-path in /usr/bin python was linked to python2 - I removed that and relinked it to python3 looks like this now:

/usr/bin # which python                                                                             
/usr/bin/python                                                                                     
/usr/bin # ls -al pyt*                                                                              
lrwxrwxrwx 1 root root     7 Dec 25 19:46 python -> python3                                         
lrwxrwxrwx 1 root root     9 Dec  2 00:44 python2 -> python2.7                                      
-rwxr-xr-x 1 root root 13992 Apr 21  2020 python2.7                                                 
lrwxrwxrwx 1 root root     9 Dec  1 23:12 python3 -> python3.8                                      
-rwxr-xr-x 1 root root 13992 May  6  2021 python3.8                                                 

I did NOT set a PYTHONPATH in the container environment, for this led to a strange concatenation of paths and is aparently not neccesary.

Homebridge log looks like this now:

[12/25/2021, 8:14:14 PM] [Beamer] Initializing JvcProjectorPower accessory...
[12/25/2021, 8:14:14 PM] [Beamer] projectorIp: 192.168.0.16
[12/25/2021, 8:14:14 PM] [Beamer] pythonPath: /usr/bin/python
[12/25/2021, 8:14:14 PM] [Beamer] setPowerScript: /homebridge/node_modules/homebridge-jvc-projector/dist/set_power_state.py
[12/25/2021, 8:14:14 PM] [Beamer] getPowerScript: /homebridge/node_modules/homebridge-jvc-projector/dist/get_power_state.py
[12/25/2021, 8:14:14 PM] [Beamer] Projector finished initializing!

Hello! I'm having the same issue trying to get this plugin to connect. I also have Homebridge running on a Docker container within my Synology server.

This is where I am stuck:

/usr/bin # which python
/usr/bin/python
/usr/bin # ls -al pyt*
lrwxrwxrwx 1 root root 7 Dec 25 19:46 python -> python3
lrwxrwxrwx 1 root root 9 Dec 2 00:44 python2 -> python2.7
-rwxr-xr-x 1 root root 13992 Apr 21 2020 python2.7
lrwxrwxrwx 1 root root 9 Dec 1 23:12 python3 -> python3.8
-rwxr-xr-x 1 root root 13992 May 6 2021 python3.8

How can I get to switch to /usr/bin # ? So I can run that ls -al pyt* command and link it to the correct path?

Thanks for any help!

aschmidt74 commented 2 years ago

problem is, the python module jvc_projector never, even after along while, reports the projector as ON. though blind switching it ON/OFF works.

How can I get to switch to /usr/bin ? So I can run that ls -al pyt* command and link it to the correct path?

so in your browser:

this indeed is the most challenging issue, that the python version used and installedto in the shell matches the version invoked in homebridge.

AviatorBimmer commented 2 years ago

problem is, the python module jvc_projector never, even after along while, reports the projector as ON. though blind switching it ON/OFF works.

How can I get to switch to /usr/bin ? So I can run that ls -al pyt* command and link it to the correct path?

so in your browser:

  • login to your Synology's DSM and
  • in the Docker App open the
  • homebridge container, Terminal Tab
  • create / Launch with command a new sh shell and find yourself in /homebridge
  • there type cd /usr/bin and set the python symlink(s) straight...

this indeed is the most challenging issue, that the python version used and installedto in the shell matches the version invoked in homebridge.

Thanks for your reply!

Please excuse my ignorance, but once I type cd /usr/bin, how do I set the python symlinks straight?

aschmidt74 commented 2 years ago

[...] once I type cd /usr/bin, how do I set the python symlinks straight?

better copy&post the output of ls -al pyt* before you set anything!

AviatorBimmer commented 2 years ago

[...] once I type cd /usr/bin, how do I set the python symlinks straight? better copy&post the output of ls -al pyt* before you set anything!

Ok, I got it working and I was able to turn on the NX7 using the switch but the switch will go back to OFF seconds after I click on it. It will go back to OFF but the NX7 will still be ON.

I guess I just need to have the switch show the current projector state.

vectronic commented 2 years ago

@aschmidt74 i wonder if this PR would fix the issue with the state check in the python module? https://github.com/bezmi/jvc_projector/pull/10

I can’t work out why I am not seeing this. I will check again when I get a chance.

aschmidt74 commented 2 years ago

✅ yeees! that line 181 did it for me. thanks for the hint! The N5's powerstate is reflected correctly in homekit now.

AviatorBimmer commented 2 years ago

So how do I apply that change?

Thanks,

Efrain

This email was composed and sent from my mobile device. Excuse my grammar and pardon my brevity.

On Jan 9, 2022, at 6:28 PM, Andreas @.***> wrote:

 ✅ yeees! that line 181 did it for me. thanks for the hint! The N5's powerstate is reflected correctly in homekit now.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

aschmidt74 commented 2 years ago

tbh; as it's only one line 181 that changed, I just went to a shell (see above) located and edited the __init__.py see: https://github.com/bezmi/jvc_projector/pull/10/commits/433ea2bbb68884c9ec40b6226056af489fb6080f

AviatorBimmer commented 2 years ago

tbh; as it's only one line 181 that changed, I just went to a shell (see above) located and edited the __init__.py see: bezmi/jvc_projector@433ea2b

Ok, I opened up a SU terminal window as shown above in this thread. Now, how do I edit the init.py file's line 181 to read on = [PowerStates.lamp_on.name, PowerStates.reserved.name] ?

I would greatly appreciate it!

vectronic commented 2 years ago

With a text editor...? vi is likely to be installed, plenty of info on the web on how to use it.

AviatorBimmer commented 2 years ago

Cool and can anyone tell me which folder is the init.py file in? I looked around but couldn't find it.

Thanks,

Efrain R.

This email was composed and sent from my mobile device. Excuse my grammar and pardon my brevity.

On Jan 17, 2022, at 1:53 PM, vectronic @.***> wrote:

 With a text editor...? vi is likely to be installed, plenty of info on the web on how to use it.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

aschmidt74 commented 1 year ago

interestingly with the update to Version: 0.1.1.post1 I had to change the files: /homebridge/node_modules/homebridge-jvc-projector/dist/get_power_state.py and /homebridge/node_modules/homebridge-jvc-projector/dist/set_power_state.py line 3 from: from jvc_projector_remote import JVCProjector ^^^^^^^ to: from jvc_projector import JVCProjector

vectronic commented 1 year ago

Please try with https://github.com/bezmi/jvc_projector/releases/tag/v0.2.3 i.e.

python3 -m pip install jvc-projector-remote