greghesp / ha-bambulab

A Home Assistant Integration for Bambu Lab Printers
810 stars 67 forks source link

[Feature] Support triggering firmware upgrade through mqtt (in LAN mode) #566

Open pimlie opened 1 month ago

pimlie commented 1 month ago

Describe the feature

It turns out it is possible to trigger a firmware upgrade through mqtt, credits for this go to the user halwin on cafe.naver.com. It works by posting a json with the latest firmware description over mqtt (see prev link for details). The printer can then download the firmware directly from the CDN, without having to be signed in to the cloud.

❗ The printer still needs an internet connection to download the actual firmware files from bbl's cdn, so it doesn't work for air-gapped printers. This is because the ota upgrade json is signed with a gpg key (as are the firmware files), so I guess somebody would probably need to dissect the bambulab firmware and overwrite bbl's public gpg key with a custom key before you can fully trigger a firmware upload on an air-gapped printer.

The json with the latest firmware update can only be downloaded when you are signed in, this repo keeps track of the latest available firmwares. Note that that repo is relying on users with a cloud account to update those ota upgrade json's.

What device is this for?

X1/P1/A1

Other Information

See :

WolfwithSword commented 1 month ago

Just to add some info, this does not work with X1 series due to changes done to the firmware updating procedure on-device. Been a major blocker for those looking into this for the past year and some.

P1 series I'm surprised that they say they got it working, last I checked with some of the contributors, the P1 series could only do it on much older firmware before a similar change to the X1 series was introduced in the firmware update procedure not allowing it to be successfully triggered via MQTT. Unsure if this has been changed back to being "possible".

A1 series had always worked, but there is no guarantee for how long, especially since there are known MQTT security changes coming for all current series of printers. (Though proper A1 I have heard of this sometimes not working, A1 Mini seems OK though, so may be hit or miss still).

If this were implemented, users with access to the cloud API can just get the json sig files from an API request for what is available for them to download, in an "officially allowed to upgrade/downgrade to" route. For sig files not in this list, it is possible bambu might take them down if vulnerabilities or errors were in the release, so there is no guarantee it is still hosted, hence why using only what their API list supplies for each printer is a safer route than relying on hardcoded versions/URLs.

pimlie commented 1 month ago

but there is no guarantee for how long

Yeah, but isn't that the case with any third-party software? API's can change, barriers can go up, cloud features could get paywalled. In the end you just never know ;)

users with access to the cloud API can just get the json sig files from an API request for what is available for them to download

Assuming you can trust the repository owner to keep the list up to date, there doesn't seem to be a reason why that same list couldn't be mirrored in a git repo. So it would probably be best if ha-bambulab would maintain it's own list

especially since there are known MQTT security changes coming for all current series of printers

Ah ok, I wasn't aware about this. That might be a good reason to wait with implementing this indeed

WolfwithSword commented 1 month ago

There is some precedent currently that the MQTT data/access for at least reporting will remain even after the changes, and certain requests as well, but I believe some are currently locked down on latest P1 firmware as the first "stage" of this already (very recent, so I wouldn't be surprised if this FW update method stopped working for P1 series from latest firmware and on).

And the secondary reason to only use the cloud API list is such that we know it's also only compatible firmwares that can be upgraded/downgraded between for the specific printer and its current FW. What some people didn't realize with the failures they got on the A1 series initially with this method, is that not all firmwares can be upgraded to directly and some need intermediary FWs. For the X1 series for example, you cannot upgrade from the oldest firmware straight to the newest right now, and it requires one of the intermediary FW versions in the 01.06 or 01.07 stream first (I forget which). And likewise for downgrading (hence why many of the older ones are generally unavailable unless you're already on an older FW, that plus security reasons).

Not to mention for X1Plus to downgrade to Firmware R, you need to downgrade to the oldest 01.07 build before FWR can be downgraded to.

Not saying it's a bad request to implement, just clarifying the original feature request that it won't work for X1 series at all, which was mentioned in the FR, spotty for P1 (we won't know for sure until its next FW version release). And that it's likely best to limit it to expected/available firmware versions due to the compatibility reasons (also saves the trouble from having to maintain or trust a list).

I myself looked into this quite a bit over a year ago but concluded that there was not much gain considering all of the edge cases, and this was before the known changes to come lol

lunDreame commented 1 month ago

Oh, my post is being talked about interestingly. It's 'halwin' and 'lunDreame'. So far, I've confirmed that the A1/A1 mini/P1 series can be updated normally. I'm only using the P1 series, so for the other series, I need data and analysis from other users' information.

For the @WolfwithSword X1 series, someone else provided the information before, but the update failed. Do you know any information about this? It would be great if there was a real device, but it's hard to analyze.

WolfwithSword commented 1 month ago

For the @WolfwithSword X1 series, someone else provided the information before, but the update failed. Do you know any information about this? It would be great if there was a real device, but it's hard to analyze.

The update process requires a sequence of commands that aren't fully triggered via MQTT anymore for firmware updates, been this way for at least a year or more I'd say, hence the lack of progress. I forget the exact stuff since I haven't looked into it since December/January. X1Plus team had tried it out as well before FirmwareR was agreed upon just in case we needed to go to an old exploitable FW version, but we concluded that the process has extra non-MQTT initiated steps which were confirmed after the fact to not be doable on OEM X1 firmware anymore.

I am curious however if this might change and be possible with the announcement of offline firmware updates being a thing soon for X1E, X1/X1C, and P1/A1 series in a future firmware update. That might loosen the restrictions a bit (since the FW will need to be on an SD card, bypassing at least one of the sequences). So, potentially next round of FW updates may be very exciting for X1 series!