mattcar15 / bambu-connect

Connect to the stats, controls, and camera of your bambu printer
Other
47 stars 8 forks source link

Error when running printer_stream.py #3

Closed lixxbox closed 8 months ago

lixxbox commented 8 months ago

Hi,

the printer_stream.py example runs fine at first:

{'ams': {'ams': [{'humidity': '4',
                  'id': '0',
                  'temp': '0.0',
                  'tray': [{'bed_temp': '0',
                            'bed_temp_type': '0',
                            'id': '0',
                            'k': 0.019999999552965164,
                            'n': 1,
                            'nozzle_temp_max': '280',
                            'nozzle_temp_min': '240',
                            'remain': -1,
                            'tag_uid': '0000000000000000',
                            'tray_color': '057748FF',
                            'tray_diameter': '0.00',
                            'tray_id_name': '',
                            'tray_info_idx': 'GFB99',
                            'tray_sub_brands': '',
                            'tray_temp': '0',
                            'tray_time': '0',
                            'tray_type': 'ABS',
                            'tray_uuid': '00000000000000000000000000000000',
                            'tray_weight': '0',
                            'xcam_info': '000000000000000000000000'},
                           {'bed_temp': '0',
                            'bed_temp_type': '0',
                            'id': '1',
                            'k': 0.019999999552965164,
                            'n': 1,
                            'nozzle_temp_max': '280',
                            'nozzle_temp_min': '240',
                            'remain': -1,
                            'tag_uid': '0000000000000000',
                            'tray_color': 'F72323FF',
                            'tray_diameter': '0.00',
                            'tray_id_name': '',
                            'tray_info_idx': 'GFB99',
                            'tray_sub_brands': '',
                            'tray_temp': '0',
                            'tray_time': '0',
                            'tray_type': 'ABS',
                            'tray_uuid': '00000000000000000000000000000000',
                            'tray_weight': '0',
                            'xcam_info': '000000000000000000000000'},
                           {'bed_temp': '0',
                            'bed_temp_type': '0',
                            'id': '2',
                            'k': 0.019999999552965164,
                            'n': 1,
                            'nozzle_temp_max': '280',
                            'nozzle_temp_min': '240',
                            'remain': -1,
                            'tag_uid': '0000000000000000',
                            'tray_color': '161616FF',
                            'tray_diameter': '0.00',
                            'tray_id_name': '',
                            'tray_info_idx': 'GFB99',
                            'tray_sub_brands': '',
                            'tray_temp': '0',
                            'tray_time': '0',
                            'tray_type': 'ABS',
                            'tray_uuid': '00000000000000000000000000000000',
                            'tray_weight': '0',
                            'xcam_info': '000000000000000000000000'},
                           {'bed_temp': '0',
                            'bed_temp_type': '0',
                            'id': '3',
                            'k': 0.019999999552965164,
                            'n': 1,
                            'nozzle_temp_max': '280',
                            'nozzle_temp_min': '240',
                            'remain': -1,
                            'tag_uid': '0000000000000000',
                            'tray_color': 'FFFFFFFF',
                            'tray_diameter': '0.00',
                            'tray_id_name': '',
                            'tray_info_idx': 'GFB99',
                            'tray_sub_brands': '',
                            'tray_temp': '0',
                            'tray_time': '0',
                            'tray_type': 'ABS',
                            'tray_uuid': '00000000000000000000000000000000',
                            'tray_weight': '0',
                            'xcam_info': '000000000000000000000000'}]}],
         'ams_exist_bits': '1',
         'insert_flag': True,
         'power_on_flag': False,
         'tray_exist_bits': 'f',
         'tray_is_bbl_bits': 'f',
         'tray_now': '1',
         'tray_pre': '1',
         'tray_read_done_bits': 'f',
         'tray_reading_bits': '0',
         'tray_tar': '3',
         'version': 295},
 'ams_rfid_status': 2,
 'ams_status': 260,
 'bed_target_temper': 90,
 'bed_temper': 90.0625,
 'big_fan1_speed': '0',
 'big_fan2_speed': '0',
 'chamber_temper': 5,
 'command': 'push_status',
 'cooling_fan_speed': '0',
 'fan_gear': 0,
 'force_upgrade': False,
 'gcode_file': 'Gnome.3mf',
 'gcode_file_prepare_percent': '100',
 'gcode_state': 'RUNNING',
 'heatbreak_fan_speed': '15',
 'hms': [],
 'home_flag': 16687,
 'hw_switch_state': 0,
 'ipcam': {'ipcam_dev': '1',
           'ipcam_record': 'enable',
           'mode_bits': 3,
           'timelapse': 'enable'},
 'layer_num': 286,
 'lifecycle': 'product',
 'lights_report': [{'mode': 'on', 'node': 'chamber_light'}],
 'mc_percent': 86,
 'mc_print_line_number': '4398163',
 'mc_print_stage': '2',
 'mc_print_sub_stage': 4,
 'mc_remaining_time': 203,
 'mess_production_state': 'active',
 'msg': 1,
 'nozzle_target_temper': 270,
 'nozzle_temper': 270.84375,
 'online': {'ahb': False, 'rfid': False, 'version': 917312286},
 'print_error': 0,
 'print_type': 'cloud',
 'profile_id': '34246804',
 'project_id': '34528729',
 'queue_est': 0,
 'queue_number': 0,
 'queue_sts': 0,
 'queue_total': 0,
 's_obj': [],
 'sdcard': True,
 'sequence_id': '39759',
 'spd_lvl': 2,
 'spd_mag': 100,
 'stg': [2, 14, 1],
 'stg_cur': 0,
 'subtask_id': '67063663',
 'subtask_name': 'Gnome',
 'task_id': '67063662',
 'total_layer_num': 576,
 'upgrade_state': {'consistency_request': False,
                   'dis_state': 0,
                   'err_code': 0,
                   'force_upgrade': False,
                   'message': '',
                   'module': '',
                   'new_ver_list': [],
                   'new_version_state': 2,
                   'progress': '',
                   'sequence_id': 0,
                   'status': ''},
 'upload': {'message': '', 'progress': 0, 'status': 'idle'},
 'vt_tray': {'bed_temp': '0',
             'bed_temp_type': '0',
             'id': '254',
             'k': 0.019999999552965164,
             'n': 1,
             'nozzle_temp_max': '0',
             'nozzle_temp_min': '0',
             'remain': 0,
             'tag_uid': '0000000000000000',
             'tray_color': '00000000',
             'tray_diameter': '0.00',
             'tray_id_name': '',
             'tray_info_idx': '',
             'tray_sub_brands': '',
             'tray_temp': '0',
             'tray_time': '0',
             'tray_type': '',
             'tray_uuid': '00000000000000000000000000000000',
             'tray_weight': '0',
             'xcam_info': '000000000000000000000000'},
 'wifi_signal': '-69dBm'}

But after some time I get the following error:

Exception in thread Thread-1 (_thread_main):
Traceback (most recent call last):
  File "C:\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Python311\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "C:\Python311\Lib\site-packages\bambu_connect\WatchClient.py", line 54, in on_message
    self.printerStatus = PrinterStatus(**self.values)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\bambu_connect\utils\models.py", line 197, in __init__
    self.ams = AMS(**data["ams"]) if "ams" in data else None
               ^^^^^^^^^^^^^^^^^^
TypeError: AMS.__init__() missing 10 required positional arguments: 'ams', 'ams_exist_bits', 'tray_exist_bits', 'tray_is_bbl_bits', 'tray_tar', 'tray_pre', 'tray_read_done_bits', 'tray_reading_bits', 'insert_flag', and 'power_on_flag'

I don't know exactly how this works, but is it possible that MQTT doesn't always send all the entire data, although it is expected by your script?

mattcar15 commented 8 months ago

Interesting, it's trying to construct it in the ams class. I'll add a check for this later today thanks!

mattcar15 commented 8 months ago

I don't have ams so hard for me to verify the change worked, but going off of your commit I think the most recent commit should fix it. Let me know / reopen it if that didn't work!

lixxbox commented 8 months ago

It has been running smoothly for a few hours now with the commit. If there will be an error later, I will let you know.

lixxbox commented 8 months ago

It's been running for quite a while now. But now I get the following error, very similar to the previous error, but not concerning the AMS. Unfortunately, I cannot reproduce/force the error. My code is based on the example. Seems like to happen, when I send a print from OrcaSlicer to the printer. I'll test with the original example code. Edit: Can confirm the error with original example.

Exception in thread Thread-1 (_thread_main):
Traceback (most recent call last):
  File "C:\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Python311\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "C:\Python311\Lib\site-packages\bambu_connect\WatchClient.py", line 54, in on_message
    self.printerStatus = PrinterStatus(**self.values)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\bambu_connect\utils\models.py", line 206, in __init__
    self.ipcam = IPCam(**data["ipcam"]) if "ipcam" in data else None
                 ^^^^^^^^^^^^^^^^^^^^^^
TypeError: IPCam.__init__() missing 3 required positional arguments: 'ipcam_dev', 'ipcam_record', and 'mode_bits'

Looks like I can't re-open the issue. :-/

mattcar15 commented 8 months ago

Add initialziation for all of them in the most recent commit so should fix all those issues:

https://github.com/mattcar15/bambu-connect/commit/7510a00b404bd86c372de2d50081e75dc65f37f2

Lemme know!

lixxbox commented 8 months ago

@mattcar15 I have only been able to start one test print so far. No error message has appeared. 🤞 I will keep an eye on it and get back to you if something similar happens again.