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,28 +31,45 @@ const SSDP_PORT = 1900;
|
|||
// Create a UDP socket
|
||||
const socket = dgram.createSocket("udp4");
|
||||
|
||||
// SSDP discovery message
|
||||
const ssdpMessage = `
|
||||
NOTIFY * HTTP/1.1
|
||||
HOST: ${SSDP_ADDRESS}:${SSDP_PORT}
|
||||
Server: UPnP/1.0
|
||||
Location: ${host}
|
||||
NT: urn:bambulab-com:device:3dprinter:1
|
||||
USN: ${serial}
|
||||
Cache-Control: max-age=1800
|
||||
DevModel.bambu.com: C11
|
||||
DevName.bambu.com: ${name}
|
||||
DevSignal.bambu.com: -66
|
||||
DevConnect.bambu.com: lan
|
||||
DevBind.bambu.com: free
|
||||
Devseclink.bambu.com: secure
|
||||
DevVersion.bambu.com: 01.07.00.00
|
||||
DevCap.bambu.com: 1`
|
||||
.trim().split('\n').join("\r\n") + "\r\n\r\n";
|
||||
socket.on("error", error => console.log({ error }));
|
||||
|
||||
function send(socket, addr, port) {
|
||||
// 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
|
||||
HOST: ${SSDP_ADDRESS}:${SSDP_PORT}
|
||||
Server: UPnP/1.0
|
||||
Location: ${host}
|
||||
NT: urn:bambulab-com:device:3dprinter:1
|
||||
USN: ${serial}
|
||||
Cache-Control: max-age=1800
|
||||
DevModel.bambu.com: C11
|
||||
DevName.bambu.com: ${name}
|
||||
DevSignal.bambu.com: -66
|
||||
DevConnect.bambu.com: lan
|
||||
DevBind.bambu.com: free
|
||||
Devseclink.bambu.com: secure
|
||||
DevVersion.bambu.com: 01.07.00.00
|
||||
DevCap.bambu.com: 1`
|
||||
.trim().split('\n').join("\r\n") + "\r\n\r\n";
|
||||
|
||||
// Send the SSDP broadcast
|
||||
function send(socket, addr, port) {
|
||||
socket.send(
|
||||
ssdpMessage,
|
||||
0,
|
||||
|
|
@ -74,22 +84,7 @@ 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