Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print doesn't work for Instax Mini 2 #16

Open
saharmor opened this issue Feb 6, 2024 · 8 comments
Open

Print doesn't work for Instax Mini 2 #16

saharmor opened this issue Feb 6, 2024 · 8 comments

Comments

@saharmor
Copy link

saharmor commented Feb 6, 2024

Hey, I'm trying to print an image from my Mac using this Python SDK to no avail.

My spec
MacBook Pro M2 Max

Code

from InstaxBLE import InstaxBLE

try:
    instax = InstaxBLE(
        print_enabled=True,
        dummy_printer=False
    )
    instax.connect()
    instax.enable_printing()
    instax.print_image('image.jpg')
except Exception as e:
    print(e)
finally:
    instax.disconnect()

Terminal output

2024-02-05 21:36:05.767 Python[53807:51297307] Peripheral ready to send: <CBPeripheral: 0x103b10080, identifier = ABA62E9E-5061-2DD0-DB72-471F64D0AB3A, name = INSTAX-45148263(IOS), mtu = 185, state = connected>
2024-02-05 21:36:05.820 Python[53807:51297307] Peripheral ready to send: <CBPeripheral: 0x103b10080, identifier = ABA62E9E-5061-2DD0-DB72-471F64D0AB3A, name = INSTAX-45148263(IOS), mtu = 185, state = connected>
2024-02-05 21:36:05.873 Python[53807:51297307] Peripheral ready to send: <CBPeripheral: 0x103b10080, identifier = ABA62E9E-5061-2DD0-DB72-471F64D0AB3A, name = INSTAX-45148263(IOS), mtu = 185, state = connected>

Printer details:
Model: Instax Mini Link
Photos left: 7/10
Battery level: 95%
Charging: False
Required image size: 600x800px
MTU: 182

2024-02-05 21:36:06.917 Python[53807:51297307] Peripheral ready to send: <CBPeripheral: 0x103b10080, identifier = ABA62E9E-5061-2DD0-DB72-471F64D0AB3A, name = INSTAX-45148263(IOS), mtu = 185, state = disconnecting>

I've put a few prints in InstaxBLE.py and this code is being called (line 399):

 if self.printEnabled:
   self.packetsForPrinting.append(self.create_packet(EventType.PRINT_IMAGE))
   self.packetsForPrinting.append(self.create_packet((0, 2), b'\x02'))

Followed by line 409:

if not self.dummyPrinter:
   packet = self.packetsForPrinting.pop(0)
   self.send_packet(packet)

So I'm not sure what's the problem.

@javl
Copy link
Owner

javl commented Feb 8, 2024

Just a quick check: did you run the code only as written in your post? Because the code in your post won't work: as soon as it's done sending the first package from the print_image('image.jpg') command, python will quit. We need Python to stay active and listen for the printer's response, which indicate if it can send the next part of the image.

That is why in the example (just run python3 InstaxBLE.py) there is a sleep() command:

    finally:
        sleep(60)
        instax.disconnect()  # all done, disconnect

This will make sure Python stays active for at least 60 seconds, during which it can receive printer responses and reply to them by sending the next part of the image.

This isn't the most refined way of handling things, I'll see if I can implement some sort of threading in the future. See issue #11

@javl
Copy link
Owner

javl commented Feb 20, 2024

Just checking in to see if you've had time to try this, @saharmor. Would be great to know if this was indeed the problem :)

@undefined99
Copy link

@javl Instax Mini 2 works after adding the sleep(60). Anyway, thanks for the cool library, i can now print it using python

@buj99
Copy link

buj99 commented May 14, 2024

Hi I have tried to connect to my instax mini link 2 using the demo function from the InstaxBLE file and it seems like some UUID is not found .

def test():
    instax = InstaxBLE(device_address="88:B4:36:XX:XX:XX",verbose= True)
    try:
        # To prevent misprints during development this script sends all the
        # image data except the final 'go print' command. To enable printing
        # uncomment the next line, or pass --print-enabled when calling
        # this script

        # instax.enable_printing()

        instax.connect()
        # instax.deviceName()
        # Set a rainbow effect to be shown while printing and a pulsating
        # green effect when printing is done
        instax.send_led_pattern(LedPatterns.rainbow, when=1)
        instax.send_led_pattern(LedPatterns.pulseGreen, when=2)
        # you can also read the current accelerometer values if you want
        # while True:
        #     instax.get_printer_orientation()
        #     sleep(.5)

        # send your image (.jpg) to the printer by
        # passing the image_path as an argument when calling
        # this script, or by specifying the path in your code
        if instax.image_path:
            instax.print_image(instax.image_path)
        else:
            instax.print_image(instax.printerSettings['exampleImage'])

    except Exception as e:
        print(type(e).__name__, __file__, e.__traceback__.tb_lineno)
        instax.log(f'Error: {e}')
    finally:
        sleep(60)
        print('finally, disconnect')
        instax.disconnect()  # all done, disconnect


test()

This is the console output :

Connecting to INSTAX-4211XXX(ANDROID) [88:B4:36:XX:XX:XX]
Connected
Error on attaching notification_handler: Service with UUID 70954782-2d83-473d-9e5f-81e1d02d5273 not found.
RuntimeError /home/XXXX/XXXX/instax-printing/printing-worker/main.py 55
Error: Service with UUID 70954782-2d83-473d-9e5f-81e1d02d5273 not found.
finally, disconnect

Process finished with exit code 0 ```

This error in trowed  from line 214 in  InstaxBLE.py file .

Maybe can you give me some info about how can I find the correct UUID   

@javl
Copy link
Owner

javl commented May 15, 2024

That's odd, @buj99
Can you try adding instax.print_services() to the code? This should print an overview of all available endpoints.

def test():
    instax = InstaxBLE(verbose=True)
    try:
        instax.connect()
        instax.print_services()
    except Exception as e:
        print(type(e).__name__, __file__, e.__traceback__.tb_lineno)
        instax.log(f'Error: {e}')
    finally:
        sleep(60)
        print('finally, disconnect')
        instax.disconnect()  # all done, disconnect

@buj99
Copy link

buj99 commented May 15, 2024

@javl It gives me the same error :

Searching for instax printer...
Connecting to INSTAX-42113XXX(ANDROID) [88:B4:36:XX:XX:XX]
Connected
Error on attaching notification_handler: Service with UUID 70954782-2d83-473d-9e5f-81e1d02d5273 not found.
Successfully connected, listing services...
RuntimeError /home/buj/Projects/testbanch/instax-test/main.py 21
Error: Service with UUID 70954782-2d83-473d-9e5f-81e1d02d5273 not found.

Also I observed in the Bluetooth settings that the connection is closed after 1-2 seconds , it might be a Bluetooth drive issue. It would be very helpful to point me where I can find some logs for the Bluetooth if you can :D .
I have installed Ubuntu on another device and tested it and the connection seems to be right . I'm going to do some more digging and post the results here if I find something .

Thx for the reply

@javl
Copy link
Owner

javl commented May 15, 2024

Ah yeah, I see it already attaches inside the connect() method.
You could try calling the print_services() directy after connecting, before it tries to attach the handlers:
Around this line:

if self.peripheral.is_connected():

But, if you say it works on a different system the address shouldn't be the problem. Would be great if you can report back if you find a solution.

@buj99
Copy link

buj99 commented May 15, 2024

This is the output , not very helpful i guess :))

/usr/bin/python3.10 /home/buj/Projects/testbanch/instax-test/main.py
Searching for instax printer...
Connecting to INSTAX-4211XXXX(ANDROID) [88:B4:36:XX:XX:XX]
Successfully connected, listing services...
Connected
Error on attaching notification_handler: Service with UUID 70954782-2d83-473d-9e5f-81e1d02d5273 not found.
Successfully connected, listing services...
RuntimeError /home/buj/Projects/testbanch/instax-test/main.py 21
Error: Service with UUID 70954782-2d83-473d-9e5f-81e1d02d5273 not found.

I'm going dig some more on the driver side of things .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants