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

SP-1 attempts #10

Open
vitorio opened this issue Sep 14, 2018 · 8 comments
Open

SP-1 attempts #10

vitorio opened this issue Sep 14, 2018 · 8 comments
Assignees

Comments

@vitorio
Copy link

vitorio commented Sep 14, 2018

Hi! Excited to see this project, and I'm interested in SP-1 support.

Using sp2.py as a base, initial communication with an SP-1 is successful if I remove:

printerSpecifications = self.getPrinterSpecifications()

and

'specs': printerSpecifications.payload,

from getPrinterInformation().

With that, it gets as far as attempting to send the photo to the printer:

--- Instax Printer Python Client ---

Connecting to Printer.
Model: SP-1
Firmware: 03.22
Battery State: 4
Prints Remaining: 10
Total Lifetime Prints: 119

Printing Image: /Users/vitorio/Downloads/IMG_20180713_121051175.jpg
[========================------------------------------------] 40.0% ...About to send Image.                       
Traceback (most recent call last):
  File "/Users/vitorio/Documents/instax-print/.venv/bin/instax-print", line 116, in <module>
    myInstax.printPhoto(encodedImage, printProgress)
  File "/Users/vitorio/Documents/instax-print/.venv/lib/python3.7/site-packages/instax/sp2.py", line 239, in printPhoto
    self.sendSendImageCommand(segment, bytes(segmentBytes))
  File "/Users/vitorio/Documents/instax-print/.venv/lib/python3.7/site-packages/instax/sp2.py", line 143, in sendSendImageCommand
    response = self.sendCommand(cmdPacket)
  File "/Users/vitorio/Documents/instax-print/.venv/lib/python3.7/site-packages/instax/sp2.py", line 80, in sendCommand
    reply = self.send_and_recieve(encodedPacket, 5)
  File "/Users/vitorio/Documents/instax-print/.venv/lib/python3.7/site-packages/instax/sp2.py", line 72, in send_and_recieve
    raise(CommandTimedOutException())
instax.exceptions.CommandTimedOutException

According to the log, the "prep command" receives a response; it's the first "Send Image" command that does not.

@vitorio
Copy link
Author

vitorio commented Sep 14, 2018

I got testServer.py working, and I modified it to report itself as an SP-1 to the Android app. The Android app is able to eventually print, although the test server has a couple tracebacks in the console output:

pi@raspberrypi:~/instax_api $ python3 testServer.py --verbose --debug --log --version 1
---------- Instax SP-2 Test Server ---------- 
2018-09-14 21:01:14,401:instax_server:INFO:Instax SP-1 Server Listening on 0.0.0.0 port 8080
2018-09-14 21:01:20,848:instax_server:INFO:New Client Connected
2018-09-14 21:01:20,853:instax_server:INFO:Processing message type: Version
2018-09-14 21:01:20,955:instax_server:INFO:Processing message type: Model Name
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pi/instax_api/instax/testServer.py", line 80, in listenToClient
    response = self.processIncomingMessage(buffer)
  File "/home/pi/instax_api/instax/testServer.py", line 128, in processIncomingMessage
    decodedPacketObj = decodedPacket.getPacketObject()
AttributeError: 'NoneType' object has no attribute 'getPacketObject'

2018-09-14 21:02:52,032:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:02:52,036:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,139:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,243:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,347:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,451:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,556:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,661:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,765:instax_server:INFO:Processing message type: Pre Print
INFO:instax_server:Processing message type: Pre Print
2018-09-14 21:02:52,868:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:02:54,396:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:02:54,399:instax_server:INFO:Processing message type: Model Name
INFO:instax_server:Processing message type: Model Name
2018-09-14 21:02:54,506:instax_server:INFO:Processing message type: Version
INFO:instax_server:Processing message type: Version
2018-09-14 21:02:54,610:instax_server:INFO:Processing message type: Print Count
INFO:instax_server:Processing message type: Print Count
2018-09-14 21:02:54,712:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:02:56,340:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:02:56,344:instax_server:INFO:Processing message type: LockPrinter
INFO:instax_server:Processing message type: LockPrinter
2018-09-14 21:02:56,508:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:02:56,968:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:02:56,971:instax_server:INFO:Processing message type: Model Name
INFO:instax_server:Processing message type: Model Name
2018-09-14 21:02:57,074:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:02:57,592:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:02:57,595:instax_server:INFO:Processing message type: Print Count
INFO:instax_server:Processing message type: Print Count
2018-09-14 21:02:57,710:instax_server:INFO:Processing message type: Reset
INFO:instax_server:Processing message type: Reset
2018-09-14 21:02:57,808:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:02:58,555:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:02:58,557:instax_server:INFO:Processing message type: PrepImage
INFO:instax_server:Processing message type: PrepImage
2018-09-14 21:02:59,088:instax_server:INFO:Processing message type: Send Image
INFO:instax_server:Processing message type: Send Image
2018-09-14 21:02:59,609:instax_server:INFO:Processing message type: Send Image
INFO:instax_server:Processing message type: Send Image
2018-09-14 21:02:59,731:instax_server:INFO:Processing message type: Type 83
INFO:instax_server:Processing message type: Type 83
2018-09-14 21:02:59,733:instax_server:INFO:Decoding Image of 2 segments.
INFO:instax_server:Decoding Image of 2 segments.
2018-09-14 21:02:59,734:instax_server:INFO:Combined image is 120000 bytes long
INFO:instax_server:Combined image is 120000 bytes long
2018-09-14 21:02:59,736:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
Exception in thread Thread-8:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pi/instax_api/instax/testServer.py", line 107, in decodeImage
    instaxImage.decodeImage(combined)
  File "/home/pi/instax_api/instax/instaxImage.py", line 74, in decodeImage
    targetImg.append(imageBytes[blueTarget])
IndexError: bytearray index out of range

2018-09-14 21:03:00,260:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:00,265:instax_server:INFO:Processing message type: Model Name
INFO:instax_server:Processing message type: Model Name
2018-09-14 21:03:00,368:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:00,890:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:00,893:instax_server:INFO:Processing message type: Version
INFO:instax_server:Processing message type: Version
2018-09-14 21:03:01,010:instax_server:INFO:Processing message type: Version
INFO:instax_server:Processing message type: Version
2018-09-14 21:03:01,105:instax_server:INFO:Processing message type: Lock State
INFO:instax_server:Processing message type: Lock State
2018-09-14 21:03:01,210:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:02,235:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:02,237:instax_server:INFO:Processing message type: Type 195
INFO:instax_server:Processing message type: Type 195
2018-09-14 21:03:02,342:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:03,865:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:03,867:instax_server:INFO:Processing message type: Type 195
INFO:instax_server:Processing message type: Type 195
2018-09-14 21:03:03,970:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:05,580:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:05,583:instax_server:INFO:Processing message type: Type 195
INFO:instax_server:Processing message type: Type 195
2018-09-14 21:03:05,603:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:07,128:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:07,130:instax_server:INFO:Processing message type: Type 195
INFO:instax_server:Processing message type: Type 195
2018-09-14 21:03:07,233:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:08,753:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:08,756:instax_server:INFO:Processing message type: Type 195
INFO:instax_server:Processing message type: Type 195
2018-09-14 21:03:08,858:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:09,519:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:09,522:instax_server:INFO:Processing message type: Model Name
INFO:instax_server:Processing message type: Model Name
2018-09-14 21:03:09,626:instax_server:INFO:Processing message type: Version
INFO:instax_server:Processing message type: Version
2018-09-14 21:03:09,730:instax_server:INFO:Processing message type: Print Count
INFO:instax_server:Processing message type: Print Count
2018-09-14 21:03:09,911:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
2018-09-14 21:03:10,359:instax_server:INFO:New Client Connected
INFO:instax_server:New Client Connected
2018-09-14 21:03:10,363:instax_server:INFO:Processing message type: LockPrinter
INFO:instax_server:Processing message type: LockPrinter
2018-09-14 21:03:10,465:instax_server:INFO:Client Disconnected
INFO:instax_server:Client Disconnected
^CYou pressed Ctrl+C! Saving Log and shutting down.
2018-09-14 21:03:19,159:instax_server:INFO:Shutting down Server
INFO:instax_server:Shutting down Server
2018-09-14 21:03:19,160:instax_server:INFO:Saving Log to: instaxServer-20180914-210319.json
INFO:instax_server:Saving Log to: instaxServer-20180914-210319.json
2018-09-14 21:03:19,205:instax_server:INFO:Log file written, have a nice day!
INFO:instax_server:Log file written, have a nice day!

I believe the first traceback is an unknown packet type number 64; a previous version of testServer.py reported this:

pi@raspberrypi:~/instax_api $ python3 testServer.py 
---------- Instax SP-2 Test Server ---------- 
Server Listening on 0.0.0.0 port 8080
New Client Connected
Processing message type: Version
Processing message type: Model Name
Unknown Packet Type: 64
Packet Bytes: [2440 0014 d9d7 0e78 ffff 0000 0000 0000 fb53 0d0a]
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pi/instax_api/instax/testServer.py", line 73, in listenToClient
    response = self.processIncomingMessage(buffer)
  File "/home/pi/instax_api/instax/testServer.py", line 121, in processIncomingMessage
    decodedPacketObj = decodedPacket.getPacketObject()
AttributeError: 'NoneType' object has no attribute 'getPacketObject'

I've attached the JSON log as sp1json.zip

@vitorio
Copy link
Author

vitorio commented Sep 15, 2018

The SP-1 resolution is 480x640. Changing the image size (and numbers in instaxImage.py) doesn't allow the print to progress any further still.

@vitorio
Copy link
Author

vitorio commented Sep 16, 2018

Updating the image sending code to be more aligned with the lower resolution also doesn't help:

       self.sendPrepImageCommand(16, 0, 921600)
        for segment in range(16):

Neither does forcing it to keep sending:

    def sendSendImageCommand(self, sequenceNumber, payloadBytes):
        """Send an Image Segment Command."""
        cmdPacket = SendImageCommand(Packet.MESSAGE_MODE_COMMAND,
                                     sequenceNumber=sequenceNumber,
                                     payloadBytes=payloadBytes)
        try:
            response = self.sendCommand(cmdPacket)
        except:
            response = None
        return response

That just pushes the communication timeout to the T83 command after.

Suggestions welcome!

@vitorio
Copy link
Author

vitorio commented Nov 2, 2018

@jpwsutton any advice on next steps? I'll be trying to get this working at a hackathon weekend after next.

@vitorio
Copy link
Author

vitorio commented Nov 18, 2018

In my fork at https://github.com/vitorio/instax_api I have a working simulator, which can impersonate an SP-1 and receive the older format 640x480 JPEG data from the Instax Share mobile app; and a working client, which can successfully send an older format 640x480 JPEG to the simulator.

The client continues to fail to send to the real SP-1 printer, however. The error is the same as the one in the opening issue:

$ python3 instax-print -v 1 -d -l ../L0020012.JPG 
--- Instax Printer Python Client ---

Connecting to Printer.
Model: SP-1
Firmware: 03.22
Battery State: 4
Prints Remaining: 10
Total Lifetime Prints: 136

Printing Image: ../L0020012.JPG
[------------------------------------------------------------] 0.0% ...Connectin
[======------------------------------------------------------] 10.0% ...Connecte
[============------------------------------------------------] 20.0% ...Locking
[==================------------------------------------------] 30.0% ...Resettin
[========================------------------------------------] 40.0% ...About to
Traceback (most recent call last): 
  File "instax-print", line 118, in <module>
    myInstax.printPhoto(encodedImage, printProgress)
  File "/Users/vitorio/Documents/instax-print/instax_api/instax/sp1.py", line 244, in printPhoto
    resp = self.sendSendImageCommand(segment, bytes(segmentBytes))
  File "/Users/vitorio/Documents/instax-print/instax_api/instax/sp1.py", line 142, in sendSendImageCommand
    response = self.sendCommand(cmdPacket)
  File "/Users/vitorio/Documents/instax-print/instax_api/instax/sp1.py", line 79, in sendCommand
    reply = self.send_and_recieve(encodedPacket, 5)
  File "/Users/vitorio/Documents/instax-print/instax_api/instax/sp1.py", line 71, in send_and_recieve
    raise(CommandTimedOutException())
instax.exceptions.CommandTimedOutException

Not sure what's the next debugging step. Is sniffing with Wireshark my only option? Is there some sort of comparison I can do with the JSON logs on the server side?

vitorio referenced this issue in vitorio/instax_api Feb 3, 2019
@cool2man
Copy link

First draft SP1 support which works with my REAL device: master...cool2man:master

The trick was to capture the wifi traffic between the app on a smartphone and the printer. Images are sent as JPEG images, not as RGB data. Changing from RGB (mode 10) to JPEG (mode 2) was the most important fix to get my SP1 working.

@vitorio
Copy link
Author

vitorio commented Nov 16, 2019

I can finally confirm @cool2man's branch works with a real SP-1! Very exciting, I'm going sort out the differences and merge them into my branch.

@vitorio
Copy link
Author

vitorio commented Nov 18, 2019

In addition to @cool2man's comments about sending JPEG images directly, and changing the mode, other differences appear to be:

  • A 153,600 byte file size limit seems to be real
  • A 960 byte segment size per send image command seems to be real
  • The shading command packet doesn't need to be received by the printer

@jpwsutton jpwsutton self-assigned this Dec 31, 2020
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

3 participants