Skip to content

Commit

Permalink
extend websocket connection logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nlef committed Nov 9, 2024
1 parent ff174bc commit 6c201ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bot/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ def _rotate_img(self, img: Image.Image) -> Image.Image:

@cam_light_toggle
def take_photo(self, ndarr: ndarray = None, force_rotate: bool = True) -> BytesIO:
response = httpx.get(f"{self._host_snapshot}", timeout=5)
# Todo: speedup coonections?
response = httpx.get(f"{self._host_snapshot}", timeout=5, verify=False)
bio = BytesIO()

os_nice(15)
Expand Down
7 changes: 4 additions & 3 deletions bot/websocket_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from apscheduler.schedulers.base import BaseScheduler # type: ignore
import orjson
import websockets
from websockets.asyncio.client import ClientConnection, connect
from websockets.protocol import State

Expand Down Expand Up @@ -434,6 +433,8 @@ async def run_forever_async(self):
uri=f"{self._protocol}://{self._host}:{self._port}/websocket{await self._klippy.get_one_shot_token()}",
process_exception=self.on_error,
open_timeout=5.0,
ping_interval=10.0, # as moonraker
ping_timeout=30.0, # as moonraker
close_timeout=5.0,
max_queue=1024,
logger=logger,
Expand All @@ -444,6 +445,6 @@ async def run_forever_async(self):
self._scheduler.add_job(self.reshedule, "interval", seconds=2, id="ws_reschedule", replace_existing=True)
async for message in self._ws:
await self.websocket_to_message(message)
except websockets.ConnectionClosed:
except Exception as ex:
logger.error(ex)
self._scheduler.remove_job("ws_reschedule")
continue

0 comments on commit 6c201ea

Please sign in to comment.