acse-ci223 / bambulabs_api

Unofficial Bambulabs API
https://acse-ci223.github.io/bambulabs_api/
MIT License
23 stars 6 forks source link

Can't connect with the simple example #41

Open yanshay opened 1 month ago

yanshay commented 1 month 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 1 month ago

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

yanshay commented 1 month 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 1 month ago

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

yanshay commented 1 month 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 1 month 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 1 month 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 1 month ago

The released version should be working. 2.3.1 has been tested

yanshay commented 1 month ago

So 2.3.3 I have should work?

ohmdelta commented 1 month ago

Yes, it should be working

CCJv commented 1 month ago

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

ohmdelta commented 1 month 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 weeks ago

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