update ssdp helper to allow for multiple printers
This commit is contained in:
parent
561911ee8e
commit
c3ab08dcc1
1 changed files with 52 additions and 57 deletions
|
|
@ -9,9 +9,9 @@
|
|||
* under the slicer Devices tab when "+" is selected.
|
||||
*/
|
||||
|
||||
const [ name, host, serial ] = process.argv.slice(2);
|
||||
let args = process.argv.slice(2);
|
||||
|
||||
if (!(name && host && serial)) {
|
||||
if (args.length % 3 !== 0) {
|
||||
console.log([
|
||||
'usage: ssdp [name] [host] [serial-no]',
|
||||
'where:',
|
||||
|
|
@ -22,13 +22,6 @@ if (!(name && host && serial)) {
|
|||
return process.exit(0);
|
||||
}
|
||||
|
||||
console.log([
|
||||
`Broadcasting Bambu Printer`,
|
||||
`Name: ${name}`,
|
||||
`Host: ${host}`,
|
||||
`Serial: ${serial}`,
|
||||
].join('\n'));
|
||||
|
||||
const dgram = require("dgram");
|
||||
|
||||
// SSDP parameters
|
||||
|
|
@ -38,6 +31,24 @@ const SSDP_PORT = 1900;
|
|||
// Create a UDP socket
|
||||
const socket = dgram.createSocket("udp4");
|
||||
|
||||
socket.on("error", error => console.log({ error }));
|
||||
|
||||
// Bind the socket and join the multicast group
|
||||
socket.bind(1900, () => {
|
||||
socket.addMembership(SSDP_ADDRESS); // Join the SSDP multicast group
|
||||
});
|
||||
|
||||
while (args.length) {
|
||||
const [name, host, serial] = args;
|
||||
args = args.slice(3);
|
||||
|
||||
console.log([
|
||||
`Broadcasting Bambu Printer`,
|
||||
`Name: ${name}`,
|
||||
`Host: ${host}`,
|
||||
`Serial: ${serial}`,
|
||||
].join('\n'));
|
||||
|
||||
// SSDP discovery message
|
||||
const ssdpMessage = `
|
||||
NOTIFY * HTTP/1.1
|
||||
|
|
@ -57,9 +68,8 @@ DevVersion.bambu.com: 01.07.00.00
|
|||
DevCap.bambu.com: 1`
|
||||
.trim().split('\n').join("\r\n") + "\r\n\r\n";
|
||||
|
||||
function send(socket, addr, port) {
|
||||
|
||||
// Send the SSDP broadcast
|
||||
function send(socket, addr, port) {
|
||||
socket.send(
|
||||
ssdpMessage,
|
||||
0,
|
||||
|
|
@ -76,20 +86,5 @@ function send(socket, addr, port) {
|
|||
);
|
||||
}
|
||||
|
||||
socket.on("error", error => console.log({ error }));
|
||||
|
||||
// Handle responses from devices
|
||||
socket.on("message", (msg, rinfo) => {
|
||||
// console.log(`<<<<<<<<<<<<<<<<< ${rinfo.address} : ${rinfo.port}`);
|
||||
// console.log(msg.toString().trim());
|
||||
// console.log('<<<<<<<<<<<<<<<<<');
|
||||
});
|
||||
|
||||
// Bind the socket and join the multicast group
|
||||
socket.bind(1900, () => {
|
||||
socket.addMembership(SSDP_ADDRESS); // Join the SSDP multicast group
|
||||
setInterval(() => send(socket, '239.255.255.250', 2021), 1000);
|
||||
// setInterval(() => send(socket, '239.255.255.250', 1990), 2000);
|
||||
// setInterval(() => send(socket, '255.255.255.255', 2021), 2000);
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue