Donkie / Spoolman

Keep track of your inventory of 3D-printer filament spools.
MIT License
1.02k stars 93 forks source link

Bambu Lab Integration #217

Open Littlemanjr2 opened 11 months ago

Littlemanjr2 commented 11 months ago

I know its probably easier to integrate into the other app/platforms that you've already done but I know with the proliferation of Bambu printers this would be appreciated. I have no clue on how all that works but correct me if I'm wrong but since they have their API setup, could Spoolman just pull from that and update the spools in Spoolman? Either way it looks great and appreciate the work.

Littlemanjr2 commented 11 months ago

Sorry didn't go through the closed issues, I see this has been asked and closed. Maybe leave it open so others can see it, maybe provide ideas.

Bazeone commented 11 months ago

maybe using home assistant.

Donkie commented 11 months ago

Found a Github repository with someone who seems to know the Bambulab API well, so I opened up a discussion there. https://github.com/markhaehnel/bambulab/discussions/15 . Let's see if it leads anywhere :)

platini76 commented 6 months ago

hello there are news on this feature?

platini76 commented 6 months ago

please give us faith in this request...

Vakrehus commented 5 months ago

any news or plugins to work with bambu lab printers?

jbperrin88 commented 3 months ago

Hello, i'm also really interested by this feature ;p Some one already found some way to found the informations needed: https://www.wolfwithsword.com/bambulab-advanced-setup-with-homeassistant-grafana-and-postgres/

kens96 commented 3 months ago

I am sure this would be an extremely popular integration, and would drive adoption of Spoolman massively. I would love to implement Spoolman for my Klipper and Bambu printers but without the Bambu integration there is little value.

Gamerou commented 3 months ago

I'm considering buying a Bambulab printer as a second printer. If I do, I could try / help to integrate it with Spoolman for filament tracking.

kens96 commented 3 months ago

I'm considering buying a Bambulab printer as a second printer. If I do, I could try / help to integrate it with Spoolman for filament tracking.

Happy to help too with testing or anything else :) I have both a couple of Bambu P1Ss

dresende commented 3 months ago

I just did a script in 30 minutes to do this. The only issue is I rely on the RFID tag, so I added the field tag as an extra spool property in Spoolman and fill it in with the tag.

Note: I'm using default ports and this is just a proof of concept. My X1C updates the local MQTT information every second and that does not seem like a good frequency to bother spoolman.

I don't have time to make a proper integration for now (but will probably do in the future). If someone want to start an integration I might help on my spare time.

import mqtt from "mqtt"
import got from "got"

const PRINTER_ID   = "00M...........5"; // printer serial number (check on printer screen)
const PRINTER_CODE = "9......e";        // printer access code
const PRINTER_IP   = "192.168.x.x";     // printer local IP address
const SPOOLMAN_IP  = "192.168.x.x";     // spoolman IP address

const client = await mqtt.connectAsync(`tls://bblp:${PRINTER_CODE}@${PRINTER_IP}:8883`, {
    rejectUnauthorized : false,
});

const response = await got(`http://${SPOOLMAN_IP}:7912/api/v1/spool`);
const spools   = JSON.parse(response.body);

// console.log(spools);
console.log("connected");

client.on("message", async (topic, message) => {
    try {
        const data = JSON.parse(message);

        if (data.print.ams?.ams) {
            for (const ams of data.print.ams.ams) {
                // console.log(ams);
                console.log("AMS [%s] (hum: %s, temp: %sºC)", num2letter(ams.id), ams.humidity, ams.temp);
                for (const slot of ams.tray) {
                    // console.log(slot);
                    console.log("    - [%s%s] %s %s (%s%%) [[ %s ]]", num2letter(ams.id), slot.id, slot.tray_sub_brands, slot.tray_color, ("" + slot.remain).padStart(3), slot.tag_uid);

                    let found = false;

                    for (const spool of spools) {
                        if (!spool.extra.tag) continue;

                        const tag = JSON.parse(spool.extra.tag);

                        if (tag != slot.tag_uid) continue;

                        found = true;

                        await got.patch(`http://${SPOOLMAN_IP}:7912/api/v1/spool/${spool.id}`, {
                            json : {
                                remaining_weight : slot.remain / 100 * slot.tray_weight,
                            },
                        });
                    }

                    if (!found) {
                        console.log("      - Not found. Update spool tag!");
                    }
                }
            }
        }
    } catch (e) {
        console.log(e);
    }
});

client.subscribe(`device/${PRINTER_ID}/report`);

function num2letter(num) {
    return String.fromCharCode("A".charCodeAt(0) + +num);
}

P.S.: I forgot to mention I only use Bambu spools, so the AMS will tell me the remaining %

DjBac commented 2 months ago

Any new or roadmap on the Bambu Integration?

Donkie commented 2 months ago

Not from me, sorry.