From 4276922efacc79043a405e035c4ade04d24f1cc6 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Mon, 24 Jun 2024 04:11:11 +0100 Subject: [PATCH 1/3] Switch from SocketIO_Client to socketio --- octoprint_polarcloud/__init__.py | 15 +++++++++------ setup.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/octoprint_polarcloud/__init__.py b/octoprint_polarcloud/__init__.py index bf2bd8c..e746ebd 100755 --- a/octoprint_polarcloud/__init__.py +++ b/octoprint_polarcloud/__init__.py @@ -51,7 +51,8 @@ from Cryptodome.Signature import pkcs1_15 from Cryptodome.Hash import SHA256 -from socketIO_client import SocketIO, LoggingNamespace, TimeoutError, ConnectionError +import socketio +import time import sarge import flask from flask_babel import gettext, _ @@ -79,7 +80,7 @@ def get_ip(): return octoprint.util.address_for_client("google.com", 80) # take a server relative or localhost url and attempt to make absolute an absolute -# url out of it (guess about which interface) +# url out of it python-socketio(guess about which interface) def normalize_url(url): urlp = urlparse(url) scheme = urlp.scheme @@ -175,7 +176,7 @@ def __init__(self): def get_settings_defaults(self, *args, **kwargs): return dict( - service="https://printer2.polar3d.com", + service="https://status4test.polar3d.com", service_ui="https://polar3d.com", serial=None, machine_type="Cartesian", @@ -268,8 +269,8 @@ def _create_socket(self): self._challenge = None self._connected = True self._hello_sent = False - self._socket = SocketIO(self._settings.get(['service']), Namespace=LoggingNamespace, verify=True, wait_for_connection=False) - except (TimeoutError, ConnectionError, StopIteration): + self._socket = socketio.Client() + except: self._socket = None self._logger.exception('Unable to open socket {}'.format(get_exception_string())) return @@ -291,6 +292,8 @@ def _create_socket(self): self._socket.on('customCommand', self._on_custom_command) self._socket.on('jogPrinter', self._on_jog_printer) self._socket.on('unregisterResponse', self._on_unregister_response) + self._socket.connect(self._settings.get(['service'])) + def _start_polar_status(self): if self._polar_status_worker: @@ -505,7 +508,7 @@ def _wait_and_process(seconds, ignore_status_now=False): self._status_now = False self._logger.debug("_status_now break") return False - self._socket.wait(seconds=1) + time.sleep(1) if not self._connected: self._socket = None return False diff --git a/setup.py b/setup.py index 458632f..a3c1db5 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ plugin_author_email = "markwal@hotmail.com" plugin_url = "https://github.com/markwal/OctoPrint-PolarCloud" plugin_license = "AGPLv3" -plugin_requires = ["SocketIO-client", "pycryptodomex"] +plugin_requires = ["python-engineio==4.3.1", "python-socketio==5.5.2", "bidict==0.22.0", "pyopenssl", "pycryptodomex"] ### -------------------------------------------------------------------------------------------------------------------- ### More advanced options that you usually shouldn't have to touch follow after this point From a1f804c35fd0c521d30744273d307cbaa6f2c77c Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Sun, 7 Jul 2024 23:52:37 +0100 Subject: [PATCH 2/3] Use the socket sleep, minimal requires --- octoprint_polarcloud/__init__.py | 5 ++--- setup.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/octoprint_polarcloud/__init__.py b/octoprint_polarcloud/__init__.py index e746ebd..8948eff 100755 --- a/octoprint_polarcloud/__init__.py +++ b/octoprint_polarcloud/__init__.py @@ -52,7 +52,6 @@ from Cryptodome.Hash import SHA256 import socketio -import time import sarge import flask from flask_babel import gettext, _ @@ -176,7 +175,7 @@ def __init__(self): def get_settings_defaults(self, *args, **kwargs): return dict( - service="https://status4test.polar3d.com", + service="https://printer2.polar3d.com", service_ui="https://polar3d.com", serial=None, machine_type="Cartesian", @@ -508,7 +507,7 @@ def _wait_and_process(seconds, ignore_status_now=False): self._status_now = False self._logger.debug("_status_now break") return False - time.sleep(1) + self._socket.sleep(1) if not self._connected: self._socket = None return False diff --git a/setup.py b/setup.py index a3c1db5..232d41b 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ plugin_author_email = "markwal@hotmail.com" plugin_url = "https://github.com/markwal/OctoPrint-PolarCloud" plugin_license = "AGPLv3" -plugin_requires = ["python-engineio==4.3.1", "python-socketio==5.5.2", "bidict==0.22.0", "pyopenssl", "pycryptodomex"] +plugin_requires = ["python-socketio", "pycryptodomex"] ### -------------------------------------------------------------------------------------------------------------------- ### More advanced options that you usually shouldn't have to touch follow after this point From e76a7f55de5ef0c07c24f592ba9638fac0801c70 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Thu, 25 Jul 2024 05:41:30 +0100 Subject: [PATCH 3/3] Send verbose logging through to socketio library --- octoprint_polarcloud/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/octoprint_polarcloud/__init__.py b/octoprint_polarcloud/__init__.py index 8948eff..eab9ad7 100755 --- a/octoprint_polarcloud/__init__.py +++ b/octoprint_polarcloud/__init__.py @@ -175,7 +175,7 @@ def __init__(self): def get_settings_defaults(self, *args, **kwargs): return dict( - service="https://printer2.polar3d.com", + service="https://printer4.polar3d.com", service_ui="https://polar3d.com", serial=None, machine_type="Cartesian", @@ -268,7 +268,8 @@ def _create_socket(self): self._challenge = None self._connected = True self._hello_sent = False - self._socket = socketio.Client() + socketioLogging = self._settings.get(['verbose']) + self._socket = socketio.Client(logger=socketioLogging, engineio_logger=socketioLogging) except: self._socket = None self._logger.exception('Unable to open socket {}'.format(get_exception_string()))