Skip to content

Commit a4ee41b

Browse files
authored
v2.5.2
V2.5.2
2 parents a15cbe3 + 94fa9ff commit a4ee41b

File tree

6 files changed

+91
-1
lines changed

6 files changed

+91
-1
lines changed

bambulabs_api/client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
__all__ = ['Printer']
77

8+
import base64
9+
from io import BytesIO
810
from typing import Any, BinaryIO
911

1012
from bambulabs_api.ams import AMSHub
@@ -14,6 +16,7 @@
1416
from .ftp_client import PrinterFTPClient
1517
from .mqtt_client import PrinterMQTTClient
1618
from .filament_info import Filament, AMSFilamentSettings
19+
from PIL import Image
1720

1821

1922
class Printer:
@@ -492,8 +495,23 @@ def get_camera_frame(self) -> str:
492495
str
493496
Base64 encoded image of the camera frame.
494497
"""
498+
return self.get_camera_frame_()
499+
500+
def get_camera_frame_(self) -> str:
495501
return self.__printerCamera.get_frame()
496502

503+
def get_camera_image(self) -> Image.Image:
504+
"""
505+
Get the camera frame of the printer.
506+
507+
Returns
508+
-------
509+
Image.Image
510+
Pillow Image of printer camera frame.
511+
"""
512+
im = Image.open(BytesIO(base64.b64decode(self.get_camera_frame_())))
513+
return im
514+
497515
def get_current_state(self) -> PrintStatus:
498516
"""
499517
Get the current state of the printer.

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ dependencies:
1111
- flake8
1212
- webcolors
1313
- pip:
14-
- paho_mqtt
14+
- paho_mqtt
15+
- pillow
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import time
2+
import bambulabs_api as bl
3+
4+
IP = '192.168.1.200'
5+
SERIAL = 'AC12309BH109'
6+
ACCESS_CODE = '12347890'
7+
8+
if __name__ == '__main__':
9+
print('Starting bambulabs_api example')
10+
print('Connecting to Bambulabs 3D printer')
11+
print(f'IP: {IP}')
12+
print(f'Serial: {SERIAL}')
13+
print(f'Access Code: {ACCESS_CODE}')
14+
15+
# Create a new instance of the API
16+
printer = bl.Printer(IP, ACCESS_CODE, SERIAL)
17+
18+
# Connect to the Bambulabs 3D printer
19+
printer.connect()
20+
21+
time.sleep(5)
22+
frame = printer.get_camera_image()
23+
frame.save("image.png")
24+
25+
printer.disconnect()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import time
2+
import bambulabs_api as bl
3+
import os
4+
5+
IP = '192.168.1.200'
6+
SERIAL = 'AC12309BH109'
7+
ACCESS_CODE = '12347890'
8+
9+
env = os.getenv("env", "debug")
10+
11+
if __name__ == '__main__':
12+
print('Starting bambulabs_api example')
13+
print('Connecting to Bambulabs 3D printer')
14+
print(f'IP: {IP}')
15+
print(f'Serial: {SERIAL}')
16+
print(f'Access Code: {ACCESS_CODE}')
17+
18+
# Create a new instance of the API
19+
printer = bl.Printer(IP, ACCESS_CODE, SERIAL)
20+
21+
# Connect to the Bambulabs 3D printer
22+
printer.connect()
23+
24+
try:
25+
while True:
26+
time.sleep(5)
27+
28+
# Get the printer status
29+
status = printer.get_state()
30+
bed_temperature = printer.get_bed_temperature()
31+
nozzle_temperature = printer.get_nozzle_temperature()
32+
print(
33+
f'Printer status: {status}, Bed temp: {bed_temperature}, '
34+
f'Nozzle temp: {nozzle_temperature}')
35+
36+
if env == "debug":
37+
print("=" * 100)
38+
print("Printer MQTT Dump")
39+
print(printer.mqtt_dump())
40+
print("=" * 100)
41+
finally:
42+
# Disconnect from the Bambulabs 3D printer
43+
printer.disconnect()

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
]
2020
dependencies = [
2121
"paho-mqtt>=2.0.0",
22+
"pillow>=11.0.0",
2223
]
2324

2425
[project.urls]
@@ -29,3 +30,4 @@ Issues = "https://github.com/acse-ci223/bambulabs_api/issues"
2930
[tool.poetry.dependencies]
3031
python = "^3.10"
3132
paho-mqtt = "^2.0.0"
33+
pillow = "^11.0.0"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ sphinx
44
sphinx_rtd_theme
55
paho_mqtt
66
webcolors
7+
pillow

0 commit comments

Comments
 (0)