You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a simple web API to allow dynamic flow percentage changes. I'm able to connect and send a GCodeCommand successfully, even multiple times, but after a few minutes, it always errors out as shown below. The client:disconnect message is never received.
MQTT Connected
New print message: {
sequence_id: 3,
command: 'gcode_line',
param: 'M221 S96\n',
reason: 'success',
result: 'success'
}
Trying to disconnect
node:internal/process/promises:392
new UnhandledPromiseRejection(reason);
^
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error publishing to topic 'device/03919C440902089/request': client disconnecting".
at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
at processPromiseRejections (node:internal/process/promises:475:17)
at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v23.5.0
Here's my code. Any idea what my problem is?
import { BambuClient, GCodeLineCommand } from "bambu-node";
import express from "express";
import printers from "./printers.js";
const app = express();
const PORT = process.env.port || 3331;
app.get("/setFlowPct", async function (req, res) {
const device = req.query.device;
const flowPct = req.query.flowPct;
console.log("Device :", device);
console.log("FlowPct :", flowPct);
if (device == undefined) {
console.log("device not provided");
res.send("device not provided");
}
if (flowPct == undefined) {
console.log("flowPct not provided");
res.send("flowPct not provided");
}
const printer = printers[device];
if (printer == undefined) {
console.log("device not found");
res.send("device not found");
}
const gcode = "M221 S" + flowPct;
console.log("gcode :", gcode);
const client = new BambuClient({
host: printers[device].host,
accessToken: printers[device].accessToken,
serialNumber: printers[device].serialNumber
});
// Send gcode command on connect
client.on("client:connect", async () => {
console.log("MQTT Connected");
try {
await client.executeCommand(new GCodeLineCommand({ gcodes: [gcode] }));
}
catch (err) {
console.error(err);
res.send(err);
};
})
client.on("message", async (topic, key, data) => {
console.log(`New ${key} message:`, data)
// Result of GCodeLineCommand
if (key == "print" && data.param == gcode + "\n") {
try {
console.log("Trying to disconnect");
await client.disconnect();
}
catch (err) {
console.error(err);
res.send(err);
};
res.send("gcode: " + gcode + ", result: " + data.result);
}
});
client.on("client:disconnect", (isDisconnectOffline) => {
console.log("MQTT Disconnected");
})
try {
await client.connect();
}
catch (err) {
console.error(err);
res.send(err);
};
});
app.listen(PORT, function (err) {
if (err) console.error(err);
console.log("Server created Successfully on PORT", PORT);
});
The text was updated successfully, but these errors were encountered:
Hey! Unfortunately, I no longer have the bandwidth nor a printer to troubleshoot this anymore.
I suspect that Bambu has changed some things around regarding the MQTT channels, which is causing the bug.
I'm honestly not sure what to do with this library. PRs are accepted, but I am sadly no longer able to fulfill my role as a maintainer. I'll ask around in the Bambu discord if anyone wants to take this lib over...
First off, thanks for this!
I'm trying to create a simple web API to allow dynamic flow percentage changes. I'm able to connect and send a GCodeCommand successfully, even multiple times, but after a few minutes, it always errors out as shown below. The client:disconnect message is never received.
Here's my code. Any idea what my problem is?
The text was updated successfully, but these errors were encountered: