MrAsterisco / homebridge-hisense-tv

A Homebridge plugin to control RemoteNow-compatible HiSense TVs.
MIT License
18 stars 8 forks source link

Connection refused #20

Closed oliverwestall closed 2 years ago

oliverwestall commented 2 years ago

Hi, first of all thanks for this wonderful plugin. Whilst setting this up on Homebridge I encountered some strange problems which I hope I can get help on. Apologies if this has been addressed thru a closed issue earlier.

I have no problem running the python script hisensetv.py. pairing, get state, and even trying to press the buttons works! :)

The problem starts when I try to run this in home bridge. I have tried with both ssl on (using Custom option), and default, and both doesn't work. With the defaults, I have ended up with a "Connection Refused" error, as follows. Appreciate some insights into this ...

[9/8/2021, 11:35:09 PM] [HiSenseTV] Received Python command error: Error: [2021-09-08 23:35:09,104] [INFO ] Unverified SSL context created. Traceback (most recent call last): File "/usr/lib/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv.py", line 6, in main.main() File "/usr/lib/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/main.py", line 128, in main with tv: File "/usr/lib/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/init.py", line 137, in enter self._mqtt_client.connect(self.hostname, self.port) File "/home/homebridge/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 941, in connect return self.reconnect() File "/home/homebridge/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1075, in reconnect sock = self._create_socket_connection() File "/home/homebridge/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection return socket.create_connection(addr, source_address=source, timeout=self._keepalive) File "/usr/lib/python3.8/socket.py", line 807, in create_connection raise err File "/usr/lib/python3.8/socket.py", line 796, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

[9/8/2021, 11:35:09 PM] [HiSenseTV] An error occurred while fetching inputs: TypeError: Cannot read property 'join' of null

Plugin Config:

   {
        "ifname": "xxxx",
        "devices": [
            {
                "id": "u7a",
                "name": "Living Room TV",
                "ipaddress": "192.168.xx.xx",
                "macaddress": "5C:34:00:xx:xx:xx",
                "sslmode": "default",
                "sslcertificate": "/usr/lib/node_modules/homebridge-hisense-tv-remotenow/rcm_certchain_pem.cer",
                "sslprivatekey": "/usr/lib/node_modules/homebridge-hisense-tv-remotenow/rcm_pem_privkey.pkcs8"
            }
        ],
        "platform": "HiSenseTV"
    },

Environment:

MrAsterisco commented 2 years ago

@oliverwestall hi and thanks for reporting this!

The connection refused error is usually thrown when the TV is not in listening state (aka. the port on the TV is closed). Could you please confirm the following:

As a side note, I also found a small mistake in your configuration: if you want to pass custom SSL certificates, you have to set the sslmode to custom. Setting it to default will ignore the other parameters.

oliverwestall commented 2 years ago

Hi - thanks for reverting quickly.

The answer is yes to both:

The only thing is that I am running homebridge-ui-x, hence whilst on the same machine, the user account that I have successfully run hisensetv.py is different from the default service account that was set up to run Homebridge (not sure if this could be caused by this)

Thanks for pointing out the script config as well. I was last having it tested in non-SSL cert mode hence have left the certs path there. Figured that I am able to push "buttons" using hisensetv.py without SSL hence have left it off :)

MrAsterisco commented 2 years ago

@oliverwestall I am not familiar with homebridge-ui-x, so I wouldn't know how that might affect the plugin. The best approach would be to try to execute the hisentsetv.py script on the exact same configuration as Homebridge, so that you're suuuper sure that you're doing the same thing.

It might be that the service account that Homebridge is using on your machine is not allowed to connect via Python or something like that...?

seenve commented 2 years ago

Another problem, SSL mode Default

[2021-10-23 19:50:21,368] [INFO    ] Unverified SSL context created.
Traceback (most recent call last):
  File "hisensetv.py", line 6, in <module>
    __main__.main()
  File "/usr/lib/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/__main__.py", line 128, in main
    with tv:
  File "/usr/lib/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/__init__.py", line 137, in __enter__
    self._mqtt_client.connect(self.hostname, self.port)
  File "/usr/local/lib/python3.8/dist-packages/paho_mqtt-1.6.1-py3.8.egg/paho/mqtt/client.py", line 914, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.8/dist-packages/paho_mqtt-1.6.1-py3.8.egg/paho/mqtt/client.py", line 1073, in reconnect
    sock.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 104] Connection reset by peer

P.S. python call in homebridge, good work. Volume not control (iOS 15)

MrAsterisco commented 2 years ago

@seenve that error is caused by the wrong SSL mode being used. The TV is rejecting your connection, which means you'll have to play around with the sslmode option to find the one that works with your TV.

I'm closing this issue, as it seems the original poster fixed it (or didn't update it).