Skip to content

Commit

Permalink
Merge pull request #69 from markwal/feature/python-socketio5.5.2
Browse files Browse the repository at this point in the history
Upgrade printer server connection (socket 4.x) and socket sleep time optimizations
  • Loading branch information
vmorrisPolar authored Jul 30, 2024
2 parents f508ee1 + e76a7f5 commit 7573a0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions octoprint_polarcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from Cryptodome.Signature import pkcs1_15
from Cryptodome.Hash import SHA256

from socketIO_client import SocketIO, LoggingNamespace, TimeoutError, ConnectionError
import socketio
import sarge
import flask
from flask_babel import gettext, _
Expand Down Expand Up @@ -79,7 +79,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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -268,8 +268,9 @@ 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):
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()))
return
Expand All @@ -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:
Expand Down Expand Up @@ -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)
self._socket.sleep(1)
if not self._connected:
self._socket = None
return False
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
plugin_author_email = "[email protected]"
plugin_url = "https://github.com/markwal/OctoPrint-PolarCloud"
plugin_license = "AGPLv3"
plugin_requires = ["SocketIO-client", "pycryptodomex"]
plugin_requires = ["python-socketio", "pycryptodomex"]

### --------------------------------------------------------------------------------------------------------------------
### More advanced options that you usually shouldn't have to touch follow after this point
Expand Down

0 comments on commit 7573a0e

Please sign in to comment.