mchrisgm / bambulabs_api

Unofficial BambuLab 3D Printers Python API
https://mchrisgm.github.io/bambulabs_api/
MIT License
56 stars 9 forks source link

Can't connect with the simple example #41

Closed yanshay closed 1 day ago

yanshay commented 3 months ago

I'm unable to connect with the example (code as of today, after the fix made in #39 that was reported in #38 as connection issues). I have the correct IP/Serial/Access Code, I'm not on lan-only mode and have other software (OctoEverywhere) that connects to the printer properly from the same local network. I also tested that ports 8883, 990 and 6000 are all open on the printer (using nmap). And the example provided in #38 by @CCJv does work for me.

I get the following log:

Starting bambulabs_api example
Connecting to Bambulabs 3D printer
IP: 192.168.10.78
Serial: 01P00A3A2900822
Access Code: 26259876
Starting camera thread.
ERROR:root:Not connected to the MQTT server
Printer status: UNKNOWN

and then it hangs

if I press ^C, I get:

Traceback (most recent call last):
  File "/Users/my_user/ProgProj/bambulab/try1.py", line 27, in <module>
    printer.disconnect()
  File "/usr/local/lib/python3.11/site-packages/bambulabs_api/client.py", line 47, in disconnect
    self.__printerCamera.stop()
  File "/usr/local/lib/python3.11/site-packages/bambulabs_api/camera_client.py", line 31, in stop
    self.__thread.join()
  File "/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1119, in join
    self._wait_for_tstate_lock()
  File "/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1139, in _wait_for_tstate_lock
    if lock.acquire(block, timeout):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ohmdelta commented 3 months ago

There's a small issue with previous versions of the example. Try using the example in the README

yanshay commented 3 months ago

There's a small issue with previous versions of the example. Try using the example in the README

I'm using the code from the README. Maybe something changed with recent firmware updates?

Here is the code I'm using (removed the sensitive variables here, but they are there when running) (with a Bambulab P1S):

    print('Starting bambulabs_api example')
    print('Connecting to Bambulabs 3D printer')
    print(f'IP: {IP}')
    print(f'Serial: {SERIAL}')
    print(f'Access Code: {ACCESS_CODE}')

    # Create a new instance of the API
    printer = bl.Printer(IP, ACCESS_CODE, SERIAL)

    # Connect to the Bambulabs 3D printer
    printer.connect()

    # Get the printer status
    status = printer.get_state()
    print(f'Printer status: {status}')

    # Disconnect from the Bambulabs 3D printer
    printer.disconnect()
ohmdelta commented 3 months ago

The example should be working with the latest firmware, could you check again that your configs are all correct?

yanshay commented 3 months ago

The configs (IP, ACCESS_CODE, SERIAL) are surely correct because I use the same variables (copy/pasted) in the 2nd code provided in https://github.com/acse-ci223/bambulabs_api/issues/38#issuecomment-2261420451 , and it is connecting and working.

I'm not missing any other config there, right?

ohmdelta commented 3 months ago

Are you using the pip package or have you cloned the repo? If you're using pip it could be a version issue.

yanshay commented 3 months ago

I'm using pip, when I check the version, this is what I see (which seems newer than the latest release published on this repo (2.3.1) (but not uncommon to see versions released without the release showing on github):

Name: bambulabs_api
Version: 2.3.3
Summary: API for BambuLabs 3D Printers over MQTT
Home-page: https://github.com/acse-ci223/bambulabs_api
Author: Chris Ioannidis
Author-email: Chris Ioannidis <chris.ioannidis23@imperial.ac.uk>
License:
Location: /usr/local/lib/python3.11/site-packages
Requires: paho-mqtt
Required-by:

Could the released version be not working and need to use the cloned repo?

ohmdelta commented 3 months ago

The released version should be working. 2.3.1 has been tested

yanshay commented 3 months ago

So 2.3.3 I have should work?

ohmdelta commented 3 months ago

Yes, it should be working

CCJv commented 3 months ago

@yanshay I get the same issue. unable to connect.

ohmdelta commented 3 months ago

The issue seems to be that the pushall command (which triggers the printer to publish a more complete report) is temperamental.

As a temporary fix try sleeping for a couple seconds and then call get state twice. If that doesn't work change the line self.command_topic = f"device/{printer_serial}/request" to self.command_topic = f"device/{printer_serial}/report"

CCJv commented 3 months ago

thanks, fixed by putting a sleep in the def __publish_command function within the PrinterMQTTClient class and calling get_state twice

JustJace1 commented 1 week ago

im getting this same issue how do i fix this?

mchrisgm commented 1 week ago

@JustJace1 Have you updated to the latest version and using the example found in the README or the examples folder?

JustJace1 commented 1 week ago

yes it still wont connect. i have tried both examples

ohmdelta commented 2 days ago

This should be fixed now in #64