rgerganov / py-air-control

Command line app for controlling Philips air purifiers
MIT License
256 stars 52 forks source link

Connection to a AC2729/10 failes with urlopen error [Errno 111] Connection refused> #89

Open JoeKN2 opened 3 years ago

JoeKN2 commented 3 years ago

Hi, I have new AC2729/10 device (AWS_Philips_AIR@54.2 Firmware). The android app is able to connect to the device. It has the fix IP 192.168.178.74 (host has the IP 192.168.178.11) I tried to connect but get an error:

pi@192.168.178.11:~$ sudo airctrl --ipaddr 192.168.178.74 Exchanging secret key with the device ... Traceback (most recent call last): File "/usr/local/lib/python3.8/urllib/request.py", line 1317, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/usr/local/lib/python3.8/http/client.py", line 1230, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/lib/python3.8/http/client.py", line 1276, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.8/http/client.py", line 1225, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.8/http/client.py", line 1004, in _send_output self.send(msg) File "/usr/local/lib/python3.8/http/client.py", line 944, in send self.connect() File "/usr/local/lib/python3.8/http/client.py", line 915, in connect self.sock = self._create_connection( File "/usr/local/lib/python3.8/socket.py", line 807, in create_connection raise err File "/usr/local/lib/python3.8/socket.py", line 796, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/bin/airctrl", line 8, in sys.exit(main()) File "/usr/local/lib/python3.8/site-packages/pyairctrl/airctrl.py", line 444, in main c = HTTPAirCli(device["ip"]) File "/usr/local/lib/python3.8/site-packages/pyairctrl/airctrl.py", line 100, in init self._client = HTTPAirClient(host, debug) File "/usr/local/lib/python3.8/site-packages/pyairctrl/http_client.py", line 108, in init self.load_key() File "/usr/local/lib/python3.8/site-packages/pyairctrl/http_client.py", line 156, in load_key self._get_key() File "/usr/local/lib/python3.8/site-packages/pyairctrl/http_client.py", line 119, in _get_key with urllib.request.urlopen(req) as response: File "/usr/local/lib/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/usr/local/lib/python3.8/urllib/request.py", line 525, in open response = self._open(req, data) File "/usr/local/lib/python3.8/urllib/request.py", line 542, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "/usr/local/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(*args) File "/usr/local/lib/python3.8/urllib/request.py", line 1346, in http_open return self.do_open(http.client.HTTPConnection, req) File "/usr/local/lib/python3.8/urllib/request.py", line 1320, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

I tried it with and without sudo.

Any explanation for this behavior?

rgerganov commented 3 years ago

You can try switching the protocol with either:

airctrl --ipaddr 192.168.178.74 --protocol coap

or

airctrl --ipaddr 192.168.178.74 --protocol plain_coap

JoeKN2 commented 3 years ago

I tried booth:

pi@192.168.178.11:~$ airctrl --ipaddr 192.168.178.74 --protocol coap 2021-05-26 19:57:05,920 - MainThread - coapthon.layers.messagelayer - DEBUG - send_request - From None, To ('192.168.178.74', 5683), None-None, POST-Gz, [Uri-Path: sys, Uri-Path: dev, Uri-Path: sync, ] EA9262F7...8 bytes 2021-05-26 19:57:05,927 - MainThread - coapthon.client.coap - DEBUG - send_datagram - From None, To ('192.168.178.74', 5683), CON-17349, POST-Gz, [Uri-Path: sys, Uri-Path: dev, Uri-Path: sync, ] EA9262F7...8 bytes 2021-05-26 19:57:05,938 - Thread-1 - coapthon.client.coap - DEBUG - Start receiver Thread 2021-05-26 19:57:05,949 - Thread-1 - coapthon.client.coap - DEBUG - receive_datagram - From ('192.168.178.74', 5683), To None, NON-17349, CONTENT-Gz, [Content-Type: 0, ] 2FBE7DCE...8 bytes 2021-05-26 19:57:05,957 - Thread-1 - coapthon.layers.messagelayer - DEBUG - receive_response - From ('192.168.178.74', 5683), To None, NON-17349, CONTENT-Gz, [Content-Type: 0, ] 2FBE7DCE...8 bytes 2021-05-26 19:57:05,954 - MainThread-Retry-17349 - coapthon.client.coap - DEBUG - retransmit loop ... enter 2021-05-26 19:57:05,967 - MainThread-Retry-17349 - coapthon.client.coap - DEBUG - retransmit loop ... exit 2021-05-26 19:57:05,963 - Thread-1 - coapthon.client.coap - DEBUG - Waiting for retransmit thread to finish ... 2021-05-26 19:57:05,996 - MainThread - coapthon.layers.messagelayer - DEBUG - send_request - From None, To ('192.168.178.74', 5683), None-None, GET-None, [Uri-Path: sys, Uri-Path: dev, Uri-Path: status, Observe: 0, ] No payload 2021-05-26 19:57:06,002 - MainThread - coapthon.client.coap - DEBUG - send_datagram - From None, To ('192.168.178.74', 5683), CON-17350, GET-None, [Uri-Path: sys, Uri-Path: dev, Uri-Path: status, Observe: 0, ] No payload 2021-05-26 19:57:06,014 - MainThread-Retry-17350 - coapthon.client.coap - DEBUG - retransmit loop ... enter 2021-05-26 19:57:06,041 - Thread-1 - coapthon.client.coap - DEBUG - receive_datagram - From ('192.168.178.74', 5683), To None, CON-3270, CONTENT-None, [Observe: 0, Content-Type: 50, Max-Age: 60, ] EA9262F8948FB229EAF3...1142 bytes 2021-05-26 19:57:06,047 - Thread-1 - coapthon.layers.messagelayer - DEBUG - receive_response - From ('192.168.178.74', 5683), To None, CON-3270, CONTENT-None, [Observe: 0, Content-Type: 50, Max-Age: 60, ] EA9262F8948FB229EAF3...1142 bytes 2021-05-26 19:57:06,053 - Thread-1 - coapthon.client.coap - DEBUG - Waiting for retransmit thread to finish ... 2021-05-26 19:57:06,055 - MainThread-Retry-17350 - coapthon.client.coap - DEBUG - retransmit loop ... exit 2021-05-26 19:57:06,074 - Thread-1 - coapthon.layers.messagelayer - DEBUG - send_empty - From None, To None, ACK-None, EMPTY-None, [] No payload 2021-05-26 19:57:06,079 - Thread-1 - coapthon.client.coap - DEBUG - send_datagram - From None, To ('192.168.178.74', 5683), ACK-3270, EMPTY-None, [] No payload 2021-05-26 19:57:06,087 - Thread-1 - coapthon.layers.messagelayer - DEBUG - send_empty - From None, To None, ACK-None, EMPTY-None, [] No payload 2021-05-26 19:57:06,092 - Thread-1 - coapthon.client.coap - DEBUG - send_datagram - From None, To ('192.168.178.74', 5683), ACK-3270, EMPTY-None, [] No payload Message from device got corrupted 2021-05-26 19:57:06,203 - Thread-1 - coapthon.client.coap - DEBUG - Exiting receiver Thread due to request

pi@192.168.178.11:~$ airctrl --ipaddr 192.168.178.74 --protocol plain_coap Traceback (most recent call last): File "/usr/local/bin/airctrl", line 8, in sys.exit(main()) File "/home/pi/.local/lib/python3.8/site-packages/pyairctrl/airctrl.py", line 488, in main c.get_status(debug=args.debug) File "/home/pi/.local/lib/python3.8/site-packages/pyairctrl/airctrl.py", line 361, in get_status status = self._client.get_status(debug) File "/home/pi/.local/lib/python3.8/site-packages/pyairctrl/plain_coap_client.py", line 224, in get_status status = self._get() File "/home/pi/.local/lib/python3.8/site-packages/pyairctrl/plain_coap_client.py", line 61, in _get return json.loads(response.payload)["state"]["reported"] File "/usr/local/lib/python3.8/json/init.py", line 357, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

raphoun commented 1 year ago

Same here with AC3036/10 and firmware 69.1 pi@raspberrypi:~ $ airctrl --ipaddr 192.168.2.159 --wifi Exchanging secret key with the device ... Traceback (most recent call last): File "/usr/lib/python3.7/urllib/request.py", line 1324, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/usr/lib/python3.7/http/client.py", line 1260, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1306, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1255, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1030, in _send_output self.send(msg) File "/usr/lib/python3.7/http/client.py", line 970, in send self.connect() File "/usr/lib/python3.7/http/client.py", line 942, in connect (self.host,self.port), self.timeout, self.source_address) File "/usr/lib/python3.7/socket.py", line 727, in create_connection raise err File "/usr/lib/python3.7/socket.py", line 716, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/bin/airctrl", line 10, in sys.exit(main()) File "/usr/local/lib/python3.7/dist-packages/pyairctrl/airctrl.py", line 201, in main c = HTTPAirCli(device["ip"]) File "/usr/local/lib/python3.7/dist-packages/pyairctrl/airctrl.py", line 116, in init super().init(HTTPAirClient(host, debug)) File "/usr/local/lib/python3.7/dist-packages/pyairctrl/http_client.py", line 111, in init self.load_key() File "/usr/local/lib/python3.7/dist-packages/pyairctrl/http_client.py", line 159, in load_key self._get_key() File "/usr/local/lib/python3.7/dist-packages/pyairctrl/http_client.py", line 122, in _get_key with urllib.request.urlopen(req) as response: File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.7/urllib/request.py", line 525, in open response = self._open(req, data) File "/usr/lib/python3.7/urllib/request.py", line 543, in _open '_open', req) File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain result = func(*args) File "/usr/lib/python3.7/urllib/request.py", line 1352, in http_open return self.do_open(http.client.HTTPConnection, req) File "/usr/lib/python3.7/urllib/request.py", line 1326, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

pi@raspberrypi:~ $ airctrl --ipaddr 192.168.2.159 --protocol plain_coap Traceback (most recent call last): File "/usr/local/bin/airctrl", line 10, in sys.exit(main()) File "/usr/local/lib/python3.7/dist-packages/pyairctrl/airctrl.py", line 245, in main c.get_status(debug=args.debug) File "/usr/local/lib/python3.7/dist-packages/pyairctrl/airctrl.py", line 32, in get_status status = self._client.get_status(debug) File "/usr/local/lib/python3.7/dist-packages/pyairctrl/plain_coap_client.py", line 228, in get_status status = self._get() File "/usr/local/lib/python3.7/dist-packages/pyairctrl/plain_coap_client.py", line 65, in _get return json.loads(response.payload, object_pairs_hook=OrderedDict)["state"]["reported"] File "/usr/lib/python3.7/json/init.py", line 361, in loads return cls(**kw).decode(s) File "/usr/lib/python3.7/json/decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 1 column 2 (char 1)