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

Fix padding in mqttapi::make_mqtt_pkt #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mtoner23
Copy link
Contributor

@mtoner23 mtoner23 commented Dec 7, 2023

I tried sending gcode over mqtt and this errored out. even with this fix the printer doesnt respond to the gcode but maybe thats my user error. since we have no clue what this field does i think its fine to do what we were doing before the previous fix; send all zeros.

@billyjbryant
Copy link
Contributor

@mtoner23 so are you saying that even with this code you are unable to send prints to the printer from Prusa when having ankerctl configured as an Octoprint provider?

@mtoner23
Copy link
Contributor Author

Sorry bad phrasing. With this code I can send prints via prusaslicer to the webserver. I was trying to send manual gcode for something else which exposed this issue in the constructor.

@dtwilliamson
Copy link

Here is an example traceback without this change:

user@system$ ./ankerctl.py mqtt send ZZ_MQTT_CMD_FIRMWARE_VERSION
[*] Connecting printer AnkerMake M5 (XXXXXXX-000000-XXXXX) through make-mqtt.ankermake.com
[*] Connected to mqtt
Traceback (most recent call last):
  File "/Users/user/Projects/ankermake-m5-protocol/./ankerctl.py", line 494, in <module>
    main()
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Projects/ankermake-m5-protocol/./ankerctl.py", line 160, in mqtt_send
    cli.mqtt.mqtt_command(client, cmd)
  File "/Users/user/Projects/ankermake-m5-protocol/cli/mqtt.py", line 37, in mqtt_command
    client.command(msg)
  File "/Users/user/Projects/ankermake-m5-protocol/libflagship/mqttapi.py", line 131, in command
    return self.send(f"/device/maker/{self.sn}/command", msg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Projects/ankermake-m5-protocol/libflagship/mqttapi.py", line 123, in send
    payload = self.make_mqtt_pkt(self._guid, json.dumps(msg).encode())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Projects/ankermake-m5-protocol/libflagship/mqttapi.py", line 107, in make_mqtt_pkt
    return MqttMsg(
           ^^^^^^^^
TypeError: _MqttMsg.__init__() missing 1 required positional argument: 'padding'

This is an example result with the change in place:

user@system$ ./ankerctl.py mqtt send ZZ_MQTT_CMD_FIRMWARE_VERSION
[*] Connecting printer AnkerMake M5 (XXXXXXX-000000-XXXXX) through make-mqtt.ankermake.com
[*] Connected to mqtt
{
    "currVer": "Vx.y.z_a.b.c",
    "commandType": 1002,
    "reply": 0
}

@treitmayr
Copy link

This is also fixed in PR #145 in a way which supports both Ankermake M5 and M5C printers, see d9af577 . You can try the fork at https://github.com/anselor/ankermake-m5-protocol/tree/exiles which integrates this PR and a number of other pending ones.

@anselor anselor mentioned this pull request May 25, 2024
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

Successfully merging this pull request may close these issues.

4 participants