Skip to content

Instantly share code, notes, and snippets.

@fritzw
Last active October 15, 2024 07:41
Show Gist options
  • Save fritzw/7d981046b509a27e204d01c9bd73f37b to your computer and use it in GitHub Desktop.
Save fritzw/7d981046b509a27e204d01c9bd73f37b to your computer and use it in GitHub Desktop.
PowerShell script to make BambuStudio discover a specific printer by IP address, even if it is not on the same subnet (see BambuStudio Issue #702)
# Send the IP address of your BambuLab printer to port 2021/udp, which BambuStudio is listens on.
#
# Ensure your PC has firewall pot 2021/udp open. This is required as the proper response would usually go to the ephemeral source port that the M-SEARCH ssdp:discover message.
# But we are are blindly sending a response directly to the BambuStudio listening service port (2021/udp).
#
# Temporary solution to BambuStudio not allowing you to manually specify the Printer IP.
#
# Author(s): gashton <https://github.com/gashton>, Fritz webering <https://github.com/fritzw>
#
param (
[string]$PRINTER_IP = "10.80.2.50" # IP address of your BambuLab Printer
)
$TARGET_IP="127.0.0.1" # IP address of your PC running BambuStudio.
$PRINTER_USN="000000000000000" # Enter your own Printer Serial Number here
$PRINTER_DEV_MODEL="3DPrinter-X1-Carbon" # Set this to your model
# PRINTER_DEV_MODEL: https://github.com/bambulab/BambuStudio/tree/master/resources/printers
# X1C : "3DPrinter-X1-Carbon"
# X1 : "3DPrinter-X1"
# X1E : "C13"
# P1P : "C11"
# P1S : "C12"
# A1 mini: "N1"
# A1 : "N2S"
$PRINTER_DEV_NAME="MY-X1C" # Here you can choose any name you want for your printer, which is shown in the slicer.
$PRINTER_DEV_SIGNAL="-44" # Good Signal (Artificial), WiFi icon in BambuStudio will appear green with full-bars.
$PRINTER_DEV_CONNECT="lan" # LAN Mode
$PRINTER_DEV_BIND="free" # Not bound to a Cloud user-account.
$remoteudpport=2021 # port to send to
$sourceudpport = 0 # SourcePort, maybe empty uses and available port
$message = "HTTP/1.1 200 OK`r`nServer: Buildroot/2018.02-rc3 UPnP/1.0 ssdpd/1.8`r`nDate: $(date)`r`nLocation: ${PRINTER_IP}`r`nST: urn:bambulab-com:device:3dprinter:1`r`nEXT:`r`nUSN: ${PRINTER_USN}`r`nCache-Control: max-age=1800`r`nDevModel.bambu.com: ${PRINTER_DEV_MODEL}`r`nDevName.bambu.com: ${PRINTER_DEV_NAME}`r`nDevSignal.bambu.com: ${PRINTER_DEV_SIGNAL}`r`nDevConnect.bambu.com: ${PRINTER_DEV_CONNECT}`r`nDevBind.bambu.com: ${PRINTER_DEV_BIND}`r`n`r`n"
$udpClient = new-Object system.Net.Sockets.Udpclient($sourceudpport)
$byteBuffer = [System.Text.Encoding]::ASCII.GetBytes($message)
$sendbytes = $udpClient.Send($byteBuffer, $byteBuffer.length, $remoteip, $remoteudpport)
if ($sendbytes -ne $byteBuffer.length) {
write-host "Mismatch bytes"
}
@fritzw
Copy link
Author

fritzw commented Jan 10, 2024

@rbclark Actually, for PRINTER_DEV_NAME you can set an arbitrary string. This will then be shown in BambuStudio / OrcaSlicer in the devices Dropdown menu as the name of the printer. Maybe I should add a comment to that effect. Not sure about the importance of the other strings though.

@rbclark
Copy link

rbclark commented Jan 10, 2024

That was not my experience. When the name was wrong Bambu Studio refused to print with a “the selected printer is incompatible with the chosen printer presets” error. This resolved when I properly set the name.

@fritzw
Copy link
Author

fritzw commented Jan 10, 2024

@rbclark Interesting. You are sure that it was NAME and not MODEL? Because for our two X1 Carbons we have customized the NAME field as shown in the gist above. That is our custom value, the default name was actually something else. But maybe it's different for the A1 but it seems to counterintuitive that Bambu Lab would use the printer name to check if it is compatible.

@rbclark
Copy link

rbclark commented Jan 10, 2024

@fritzw You are 100% right, that's what I get for responding late at night. The MODEL for the A1 is N2S not the NAME. I went ahead and corrected my original comment as well to hopefully not confuse anyone.

@0x414c49
Copy link

For people want to know the printer model, feel free to check bambulab repo here:

https://github.com/bambulab/BambuStudio/tree/10e53651b3188d02a3c112e30111743823f56e91/resources/printers

For example:
A1: N2S
A1 Mini: N1

@RagingRoosevelt
Copy link

# printer_type: https://github.com/bambulab/BambuStudio/tree/master/resources/printers
# X1C    : "3DPrinter-X1-Carbon"
# X1     : "3DPrinter-X1"
# X1E    : "C13"
# P1P    : "C11"
# P1S    : "C12"
# A1 mini: "N1"
# A1     : "N2S"

@rkarlsba
Copy link

Thanks a bunch for this. An elderly friend of mine, bought an A1 combo recently, and he wasn't able to connect to it by any means. I helped him out with a remote session to his PC and found that no, neither Bambu Studio nor OrcaSlicer were able to find the printer, probably because it's a common wifi network with probably a few blocks for multicast etc. I tried this script and it worked well after a couple of hours of struggling. Big thanks!

@ozgurgulsuna
Copy link

I can surely confirm this method works on even complex networks, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment