Skip to content

Commit a62bfc5

Browse files
committed
Adding better wording for the Bambu Connect issue.
1 parent 258bb01 commit a62bfc5

File tree

8 files changed

+35
-3
lines changed

8 files changed

+35
-3
lines changed

bambu_octoeverywhere/bambuclient.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,16 @@ def _OnDisconnect(self, client:Any, userdata:Any, disconnect_flags:Any, reason_c
292292
# If the serial number is wrong in the subscribe call, instead of returning an error the Bambu Lab printers just disconnect.
293293
# So if we were pending a subscribe call, give the user a better error message so they know the likely cause.
294294
if self.IsPendingSubscribe:
295+
self.Logger.error("")
296+
self.Logger.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
295297
self.Logger.error("Bambu printer mqtt connection lost when trying to sub for events.")
296-
self.Logger.error(f"THIS USUALLY MEANS THE PRINTER SERIAL NUMBER IS WRONG. We tried to use the serial number '{self.PrinterSn}'. Double check the SN is correct.")
298+
self.Logger.error("This might indicate the printer ACCESS CODE - OR - SERIAL NUMBER IS WRONG.")
299+
self.Logger.error(f" Current Serial Number: '{self.PrinterSn}'")
300+
self.Logger.error(f" Current Access Code: '{self.LanAccessCode}'")
301+
self.Logger.error("")
302+
self.Logger.error("Check these values match your printer. If they changed, run the OctoEverywhere installer again to update them or update your Docker configuration.")
303+
self.Logger.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
304+
self.Logger.error("")
297305
else:
298306
self.Logger.warning("Bambu printer connection lost. We will try to reconnect in a few seconds.")
299307
# Clear the state since we lost the connection and won't stay synced.

elegoo_octoeverywhere/elegooclient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ def _ClientWorker(self):
328328

329329
# Setup the websocket client for this connection.
330330
self.WebSocket = Client(url, onWsOpen=self._OnWsConnect, onWsClose=self._OnWsClose, onWsError=self._OnWsError, onWsData=self._OnWsData)
331+
self.WebSocket.SetDisableCertCheck(True)
331332

332333
# Connect to the server
333334
with self.WebSocket:

linux_host/networksearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def onWsError(ws:IWebSocketClient, exception:Exception):
363363
try:
364364
logger.debug(f"Connecting to Elegoo on {url}...")
365365
client = Client(url, onWsOpen=onWsOpen, onWsData=onWsData, onWsClose=onWsClose, onWsError=onWsError)
366+
client.SetDisableCertCheck(True)
366367
# We must run async, so we don't block this testing thread.
367368
client.RunAsync()
368369
failedToConnect = False

moonraker_octoeverywhere/moonrakerclient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ def _WebSocketWorkerThread(self) -> None:
499499
onWsClose=self._onWsClose,
500500
onWsError=self._onWsError
501501
)
502+
self.WebSocket.SetDisableCertCheck(True)
502503

503504
# Run until the socket closes
504505
# When it returns, ensure it's closed.

octoeverywhere/WebStream/octowebstreamwshelper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ def AttemptConnection(self):
113113
if ws is None:
114114
return False
115115

116+
# Disable SSLs checks to support locally signed certs.
117+
ws.SetDisableCertCheck(True)
118+
116119
# To ensure we never leak a websocket, we need to use this lock.
117120
# We need to check the is closed flag and then only set the ws if it's not closed.
118121
with self.StateLock:
@@ -256,7 +259,7 @@ def _GetWebsocketObject(self) -> Optional[IWebSocketClient]:
256259

257260
# Make the websocket object and start it running.
258261
self.Logger.debug(self.getLogMsgPrefix()+"opening websocket to "+str(uri) + " attempt "+ str(self.ConnectionAttempt))
259-
return Client(url=uri, onWsOpen=self.onWsOpened, onWsData=self.onWsData, onWsClose=self.onWsClosed, onWsError=self.onWsError, subProtocolList=self.SubProtocolList)
262+
return Client(url=uri, onWsOpen=self.onWsOpened, onWsData=self.onWsData, onWsClose=self.onWsClosed, onWsError=self.onWsError, subProtocolList=self.SubProtocolList)
260263

261264

262265
# When close is called, all http operations should be shutdown.

octoeverywhere/interfaces.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ def Send(self, buffer:Buffer, msgStartOffsetBytes:Optional[int]=None, msgSize:Op
305305
def SendWithOptCode(self, buffer:Buffer, msgStartOffsetBytes:Optional[int]=None, msgSize:Optional[int]=None, optCode=WebSocketOpCode.BINARY) -> None:
306306
pass
307307

308+
@abstractmethod
309+
def SetDisableCertCheck(self, disable:bool) -> None:
310+
pass
311+
308312

309313
class IRelayWebSocketProvider(ABC):
310314

octoeverywhere/websocketimpl.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import queue
2+
import ssl
23
import threading
34
from typing import Any, Dict, List, Callable, Optional
45

@@ -39,6 +40,7 @@ def __init__(
3940
self.hasFiredWsErrorCallback = False
4041
self.hasPendingErrorCallbackFire = False
4142
self.hasDeferredCloseCallbackDueToPendingErrorCallback = False
43+
self.disableCertCheck = False
4244

4345
# We use a send queue thread because it allows us to process downloads about 2x faster.
4446
# This is because the downstream work of the WS can be made faster if it's done in parallel
@@ -96,6 +98,12 @@ def OnError(ws:WebSocket, exception:Exception):
9698
)
9799

98100

101+
# This has it's own function so the caller very explicitly has to call it, rather than it being an init overload.
102+
# If set to true, this websocket connection will not validate the cert it's connecting to. This should only be done locally!
103+
def SetDisableCertCheck(self, disable:bool):
104+
self.disableCertCheck = disable
105+
106+
99107
# Runs the websocket blocking until it closes.
100108
def RunUntilClosed(self, pingIntervalSec:Optional[int]=None, pingTimeoutSec:Optional[int]=None):
101109
#
@@ -133,12 +141,17 @@ def RunUntilClosed(self, pingIntervalSec:Optional[int]=None, pingTimeoutSec:Opti
133141
if pingIntervalSec > 0 and pingTimeoutSec <= 0:
134142
raise Exception("The ping timeout must be greater than 0.")
135143

144+
# Only if the client explicated called the function to disable this will we turn off cert verification.
145+
sslopt={"ca_certs":certifi.where()}
146+
if self.disableCertCheck:
147+
sslopt = {"cert_reqs": ssl.CERT_NONE, "check_hostname": False}
148+
136149
# Since some clients use RunAsync, check that we didn't close before the async action started.
137150
with self.isClosedLock:
138151
if self.isClosed:
139152
return
140153

141-
self.Ws.run_forever(skip_utf8_validation=True, ping_interval=pingIntervalSec, ping_timeout=pingTimeoutSec, sslopt={"ca_certs":certifi.where()}) #pyright: ignore[reportUnknownMemberType]
154+
self.Ws.run_forever(skip_utf8_validation=True, ping_interval=pingIntervalSec, ping_timeout=pingTimeoutSec, sslopt=sslopt) #pyright: ignore[reportUnknownMemberType]
142155
except Exception as e:
143156
# There's a compat issue where run_forever will try to access "isAlive" when the socket is closing
144157
# "isAlive" apparently doesn't exist in some PY versions of thread, so this throws. We will ignore that error,

py_installer/NetworkConnectors/MoonrakerConnector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def OnError(ws:IWebSocketClient, exception:Exception):
276276
Logger.Debug(f"Checking for moonraker using the address: `{url}`")
277277
try:
278278
with Client(url, onWsOpen=OnOpened, onWsData=OnData, onWsError=OnError, onWsClose=OnClosed) as ws:
279+
ws.SetDisableCertCheck(True)
279280
ws.RunAsync()
280281

281282
# Wait for the event or a timeout.

0 commit comments

Comments
 (0)