MQTT for A1

Cool is just that I’m looking for before buy one A1 Combo. :heart_eyes:

Unfortunately latest beta firmware update for P1 series seams to disamle the controll mqtt channel. Read it today on xTouch discord. Means using mqtt you can now only READ status information like temperature and progress. Controll seams to not work anymore. Same will surely come to A1 series.

Update: Seams like local MQTT will still work in LAN only mode.

"Prevent conflicts with Bambu Cloud service by prohibiting printer control through the local MQTT Broker while the printer is logged into Bambu Cloud service.
Before this update, when the printer was in cloud mode (bound to a Bambu account), control through local MQTT broker remained viable. This meant there were two conflicting channels available for controlling the printer simultaneously. Recently, we have received feedback about frequent system crashes or printer damage. Analysis of logs revealed that these issues were related to users simultaneously using both cloud and local control for the printer. Additionally, due to the limited system resources of the printer, handling commands from both channels simultaneously strained the system resources to the point of instability.
To optimize resource allocation for newer features and prevent conflicts, we will restrict printer control through local MQTT broker while the printer is connected with Bambu Cloud service. However, the printer will still push status information through the local MQTT broker.
Please note, this restriction will affect the use of software and hardware such as Home Assistant and BiQu Panda Touch. If you still need to control the printer using these software or hardware, we recommend:

Users can continue using the local MQTT to control the printer by enabling LAN Only mode.
Users can also choose to keep their Bambu Lab printers on older firmware versions to use both local MQTT broker and Bambu cloud services simultaneously."

4 Likes

Would you mind sharing how you did it? I’m also looking for this type os solution.

Sending file by mqtt is not possible. You can only start a *.3mf (but not *.gcode) file which is already located on the printers SD.

The MQTT topic is:
device/xxx/request

xxx stands for device serial number (15 digits). You can find it in your printers settings.

Message structure (JSON format):

{
“print”: {
“command”: “project_file”,
“url”: “file:///sdcard/some_file.gcode.3mf”,
“param”: “Metadata/plate_1.gcode”,
“subtask_id”: “0”,
“use_ams”: false,
“timelapse”: false,
“flow_cali”: false,
“bed_leveling”: true,
“layer_inspect”: true,
“vibration_cali”: false
}
}

You can change the parameters (for instance set AMS to true) if needed.

I’m using MQTTX client to communicate with the printer but there are also other MQTT clients software .

2 Likes

Just in case someone is curious how to establish the connection using an MQTT client, here are some screenshots from MQTTX client:

So it’s quite easy. After the coming firmware update it will probably require you to set printer to “Lan only” mode to make this work.

Possible commands are following…

Start printing 3mf file (which is already on the SD):

{
  "print": {
    "command": "project_file",
    "url": "file:///sdcard/your_file_name.gcode.3mf",
    "param": "Metadata/plate_1.gcode",
    "subtask_id": "0",
    "use_ams": false,
    "timelapse": false,
    "flow_cali": false,
    "bed_leveling": true,
    "layer_inspect": true,
    "vibration_cali": false
  }
}

Run GCODE lines:

"print": {
    "command": "gcode_line",
    "param": " 
    G0 X10 ; \n
    ...
    G0 X20 ; \n
     ",
    "sequence_id": "0"
  }
  }

Stop print

{
  "print": {
    "command": "stop",
    "param": "",
    "sequence_id": "20917",
    "reason": "success",
    "result": "success"
  }
}

Pause print

{
  "print": {
    "command": "pause",
    "sequence_id": "0"
  }
}

Resume printing:

{
  "print": {
    "command": "resume",
    "sequence_id": "0"
  }
}

set speed:

{
"print":{
"sequence_id":"2004",
"command":"print_speed",
"param":"1"
},
"user_id":"1234567890"
}

Turn light ON/OFF

{
"system": {
"sequence_id": "0",
"command": "ledctrl",
"led_node": "chamber_light",
"led_mode": "on",
"led_on_time": 500,
"led_off_time": 500,
"loop_times": 0,
"interval_time": 0
}
}
{
"system": {
"command": "ledctrl",
"led_node": "chamber_light",
"led_mode": "on"
}
}

@Dill
Thanks for the mqtt info.

Anyway, what now? I was hoping to be able to monitor the mqtt messages being sent by my p1s printer when it is printing, but nothing is appearing on the mqttx console. I’m in Lan mode, as always. There is a hello message which I can apparently send, but nothing comes back. I know nothing about Mqtt, maybe I misunderstand what it is about.

MQTT is a protocol, like http or ftp. MQTTX is a client software for MQTT protocol, just like your browser (Chrome/Firefox/Safari…) is a client software for http protocol.

Have you set MQTTX like shown above? Have you established connection? You are connected when red “power” icon is shown in the upper right corner (see second screenshot in my “how to” post).

  • If yes, you need to subscribe to a “report” topic of your printer. Follow the third screenshot in my post. When this step succeed you MQTTX client will receive a report from the printer and show it as text (JSON).

  • If no, you probably need to figure out which setting is set wrong. Probably you will need to close BambuStudio, Orca slices and Handy App, because sometimes printer reject new connections if to many clients are connected simultaneously.

My log shows the following (numbers obfuscated)

[2024-05-28 19:57:49] [INFO] MQTTX Desktop App init

[2024-05-28 19:58:12] [INFO] Assigned ID 3b745898-df05-456e-8138-989434376a2f to MQTTX client

[2024-05-28 19:58:12] [INFO] Client bblp connected using MQTT/SSL connection at mqtts://192.999.99.1999:8883

[2024-05-28 19:58:13] [INFO] Successful connection for bblp, MQTT.js onConnect trigger

[2024-05-28 20:02:33] [INFO] Message with payload “{\n "msg": "hello"\n}” was successfully published to topic “device/printerserialno/request” by bblp

which looks OK, afaik. Maybe it’s 'cos I’m printing at the moment, connected to orca, as you said. I’ll check when print is finished. I can use the xtouch, while I’m printing/ connected to orca.

looks good. Now you just need to do steps shown here. You can connect and subscribe to report during printing.

@Dill
Thanks for your help. I now have the printer on line, but not printing. (should it be printing for this to be set-up? I have new subscription (similar to your last image) - I enter the serial number etc, but when I hit confirm, it comes back with error connection closed, even though I am completing it within the keep alive time. For some reason my previous list of connections is blank - but I was not able to find how to get to the edit subscription window, even when a connection was showing. If any message is sent, will there be a reply or acknowledgement?

To subscribe to a topic you needs to be connected to a printer. Do you see the red icon in upper right corner?

Screenshot - 30.05.2024 , 11_11_27

I just noticed that IP in your log looks strange.

[2024-05-28 19:58:12] [INFO] Client bblp connected using MQTT/SSL connection at mqtts://192.999.99.1999:8883

You have just anonymized it for the post, right?

Thanks, the ip and other numbers were anonymized.
I think I will remove mttx, and reinstall, and re-enter the data. Now I can’t add a new subscription - when I select confirm, the window ‘just sits there’, with the little green star thing rotatating - I guess that indicates that it is trying… It is showing connected in the background window. This is the same result now, if studio connected to printer, or if studio not running.

sounds really like something don’t work properly :S Unfortunately I have also no further ideas which could help.

@Dill
I uninstalled, and reinstalled. It seems to be working better. If I set a subscription to the serial number parameter, I can send

{
"system": {
"command": "ledctrl",
"led_node": "chamber_light",
"led_mode": "off"
}
}

but the led stays on. and I get no reports. Are the p1s commands different?

However if set a subscription as testtopic/# I receive a stream of reports, such as below, occasionally with an ‘unexpected token json error’ .If I send the ledctrl message I normally get a ‘key1’ and a ‘hello world’ report, followed by others, but the lamp still stays on. It seems that if I set the device (printer serial number) in the subscription, it is not recognised.

Subscription for a report and sending commands are two different channels and need to be set on different places in MQTTX. Maybe you should start with the report subscription. If you get this work, you can be sure that you have established a working connection to the printer.
You need to click on [new subscription] and set “device/0309DA382XXXXXX/report” as topic. Pressing “Confirm” should not cause any error messages. If you than didn’t get a report from your printer, which is looking like this, then something else in your systems setup prevents this.

@Dill
Thanks for your patience. I deleted all the subscriptions, and entered the details again. This was the same as I did before, and got the same results. I looked into my connection settings. The printer IP was not there, instead something like ’ broker#?’ which I had never entered. I think it may have got overwritten with the attempts I made with the subscription tests. I re-entered the ip, and Ii now receive messages from the printer.
I can change the led status (chamber_lamp) with x touch, and I get a report. However, I can’t change it by sending the message from mqttx. I will try changing the temperature/whatever via mqttx. As you said, it now proves a connection has been established, I just have to get the sending side sorted.

(report from printer when lamp status changed via xtouch)

@Dill
I can now turn chamber light on and off.('i’d left a ‘0’ out of the serial number in the request). Now what to do with it.
What is the json code to get a status report on, say, the temperatures or chamber lamp status.
Of course, as soon as I get the hang of this, bbl will scrap it for their api.
Thanks again.

Yep, api will surely do. :sweat_smile:
As I know there is no special request to get a specific parameter. Printer just send a long report string from time to time and you have to parse it out.

I’ll be hammering co-pilot to write some python scripts, I guess. I’ll need to find a simple gui.

Co-pilot didn’t cut it, but chatgpt managed, after a lot of encouragement, to write a python script which dies exactly what I wanted. I then got it to write another script to produce text to .mp3 files, for generating the speech. Now, my pc tells me when the print is finished, temperature falling, etc. Something that I was able to do with Klipper, a few years ago.