Bambu Lab X1 X1C MQTT

It looks like my P1P simply refuses MQTT connexions, I have tried using @WolfwithSword’s node-red flow, the HACS integration, and also an app called MQTT explorer. In each case, TLS is on, it’s in LAN mode, I’m using port 8883, username bblp and password is the printer access code.

Does anybody have a suggestion on how to fix this or investigate the cause ? I have tried capturing packets from BambuSlicer with wireshark, but since it uses TLS the payloads are encrypted so it does not help me much. Any suggestion ? Thanks.

Everything you describe sounds like it should work. You’re in lan mode so you have the latest firmware. Is it on the same subnet as your PC and/home assistant? I don’t think that should matter as I think I could connect before I moved it to my real network (was on my IOT network) to see if that made ftps work reliably (spoiler - it didn’t).

Yes they are on the same subnet, it’s quite confusing, and the fact that BambuSlicer / OrcaSlicer can connect to it without issues makes it even more so. To me, it looks like the P1P first accepts the connexion, then discards it for some reason, like if it was waiting for a specific payload and didn’t get it.
In any case, I can see that something is happening because it gets a bit chatty in wireshark before the connexion drops, and that does not happen when I use another ip address.
The only doubt I have left regarding configuration is the printer “serial” that looks like a mac address, should I format it some way ? I’ve tried with and without the “:” separators, but that does not seem to help in any way. Thanks.

When I get some spare time (work is insane right now), I’ll be adding cloud MQTT support for P1P to the HACS integration. Which won’t help you if you are desiring to stay in lan mode but I can’t see why that wouldn’t work. But then I can’t see why your current config wouldn’t work either…

No the serial is pasted in as-is. Just one thing I can think off - a new access code is generated when you turn lan mode on/off - I assume you’re using the latest one in your testing?

Thanks Adrian. I’ve tried regenerating the access code several times and it does not help. I also tried using another MQTT app called EasyMQTT (iPhone), and once in a while it does appear to stay connected to the P1P’s broker, but it doesn’t receive anything even when auto-registering to the right address. If I try to register manually once it is connected, it breaks the connexion right away.

Also, yesterday Orca slicer had big issues connecting to it, it asked me several times to check if the access code was right (it was), so I dunno maybe something strange is going on with my wifi network, but both the computer and the printer are connected to the same AP, using IPs in the same range given by the same DHCP server, no finicky wifi extenders or stuff like that.

Can anybody enlighten me on the specifics of connecting to the cloud broker ? Is it the same process just with a different ip/domain or is it more involved ? I’d like to do some testing. Thanks.

The bambu mqtt server will close the connection if you try and subscribe to another other that /device//report. mqtt explorer by default adds a couple of global channels to subscribe to. You have to open advanced settings for the connection, delete those and add the /device one.

Yep that’s exactly what I did but that did not fix the issue. I tried with all the free MQTT clients I could get my hands on, but all of them lead to the same issue, the connexion drops after a short interval, wether I register to the device channel or not.

However, the FTP server seems to work okay, it’s a little finicky but I was able to connect with filezilla and transfer files. So at least I got the credentials right.

Here’s my MQTT explorer config, maybe I’m still missing something obvious but I really can’t see what :

Name : BBL P1P
Validate Certificate : no
TLS Encryption : yes
Protocol : mqtt://
Host : 192.168.1.xxx
Port : 8883
Username : bblp
Password : xxxxxxxx
Subscription : device/00:85:18:44:XX:XX/report
Client ID : 0123456789

The topic is incorrect. There shouldn’t be colons in it. Should be:
device/00851844XXXX/report
Although that also (from memory) looks like the wrong number of characters for the device serial?

Adrian is correct, you put the MAC address by mistake and not the device SerialNumber. If you fix that topic it should work just fine.

Thanks guys, indeed I was using the MAC address from the printer’s menu, I was pretty sure I read somewhere that the S/N was the MAC address but obviously that was totally wrong.

Using the right serial got the HACS integration working for me, and although I still was not able to connect using MQTT explorer, I got what I needed in the first place so thanks for the patience.

Adrian, I see that you are one of the contributors on the HACS integration, is there an easy way to add custom gcode commands to it, or should I just fork the repo and try to do my thing ?

What are you looking to add?

I have cloud mqtt integration working in the HACS integration now. And as a bonus I added the ability to reconfigure the integration so you can switch between lan/cloud mode and/or just update your printer IP if needed when in lan mode or re-auth with bambu cloud (auth token seemingly expires after 360 days so shouldn’t have to do it often :)).

1 Like

But the answer is probably going to be no. The integration doesn’t send any gcode to the printer - that’s the slicer. You can make printer configuration changes in Bambu slicer to add custom gcode for all prints.

1 Like

There is a way it could send some gcode commands, but I would highly recommend keeping it to preset options (logo/nozzle light on/off, fan control, preheat bed etc) for safety stuff, same approach I do in the NR flow. Opening it to a blank slate for custom commands sent to printer is asking for a nightmare :laughing:

Glad to see the p1p cloud mqtt method worked there, planning to add it to the nodered stuff as well when I have free time next week. 360 days sounds good - a simple bootup script to do it once should eliminate any chance of it expiring really.

I just added the ability to re-configure/re-auth since I don’t know the API end point to refresh the token automatically. If we’re still needing to use this as 360 days nears I’ll do some more testing and make it handle the failed auth state a little better than I expect it’ll current do.

And reconfigure also lets you flip between cloud/lan mode without having to delete/re-add the integration.

1 Like

Is that different to sending the mqtt commands? You can do the same with gcode? How do you send the gcode to the printer?

In the same mqtt request topic there is a payload you can send which arbitrarily lets you run any gcode line.

{
    "print": {
        "sequence_id": "2026",
        "command": "gcode_line",
        "param": "GCODE_HERE\n"
    },
    "user_id": "1234567890"
}

In the param, you can set a gcode command or multiple separate by \n, but even a single command needs to end in \n to function properly. (User_id may not be needed btw I just keep it in there because of habit).

So for example you can use some of the bambu specific gcode to turn on/off logo light, nozzle light, control the three fans, preheat bed/nozzle etc.

1 Like

Does that work when there’s an active print going? And not interfere with it?

Yep! that’s likely the reason for the newline \n. So it just appends into the active (or inactive) stream of gcode lines/commands. It’s how the fan-speed controls are actually done through bambu-studio too.

1 Like

Ah, I know Greg had start to work on fan control. I see now from his feature branch that’s how he was going to do it.