Guide: Automatic Start via Drag/Drop

This is the “wireless” portion to round out my full Lightburn control guide, found here:

Since my main snapmaker (pretty much stays setup with the 10W + Enclosure) is far away from my PC, using a cable + Lightburn isn’t an option. I usually just used Luban to start files. However, as many of you know, their software is slow and iffy, so why not bypass it?

Note: Be sure to read all the edits at the end of the post for more info.

There’s a few pre-requisites and I’m setting this up on a windows machine. However, it shouldn’t be too hard to format for a linux machine (mostly changing the bat into an sh and what that entails).

First and foremost; you MUST follow the full Lightburn guide. This method tells the machine to run the gcode file as-is, with no asking about material thickness, origin, etc. You have to have all that setup in the header section of your gcode.

Second, make sure you have curl, Windows 10/11 should have it built in, if not an installer can be found here: curl for Windows
Open a command prompt and just run curl and it should spit back curl: try 'curl --help' for more information if curl is installed.

Third; you will need to find your auth token, this is set when you connect Luban to the snapmaker (and tap the accept connection button on the touchscreen). The snapmaker saves one token and Luban remembers it for sending commands. So you will have to connect with Luban at least once.

To find this, the fastest way is to open a run box with Windows key + R and input %appdata%\snapmaker-luban, this will open the luban data folder. You will be looking for a file named machine.json, open this in any text editor and use the search function ctrl-f to find “token”. It will be the second one you find, and will be in a “server” block. You will also need the IP address, which is conveniently right there too.

        "server": {
            "address": "xxx.xxx.xxx.xxx", < Copy the IP here as well.
            "token": "1c297775-3dcc-44d0-83f4-b9efad0c81d9", < THIS IS YOUR TOKEN
            "isAuto": false,
            "name": "snapmaker"
        },

After you have your IP and Token, make a new text file named something like “prepare_print.bat”. I’ve also attached one you can edit to this post, unzip it, right click > edit, and change the [IP HERE] and [TOKEN HERE] with your own. Remember to delete the brackets as well.
prepare_print.zip (335 Bytes)

@echo on
curl -X POST "http://[IP HERE]:8080/api/v1/connect?token=[TOKEN HERE]"
curl -X GET "http://[IP HERE]:8080/api/v1/status?token=[TOKEN HERE]&1674308796842"
curl -X POST -F file=@%~1 "http://[IP HERE]:8080/api/v1/prepare_print?token=[TOKEN HERE]&type=Laser"
curl -X POST "http://[IP HERE]:8080/api/v1/connect?token=[TOKEN HERE]"
curl -X GET "http://[IP HERE]:8080/api/v1/status?token=[TOKEN HERE]&1674308796842"
curl -X POST "http://[IP HERE]:8080/api/v1/start_print?token=[TOKEN HERE]"

After saving with your own IP/Token, you’re ready to go. In Lightburn just click Save GCode and drag & drop your saved .nc file onto prepare_print.bat. It will connect to the snapmaker, send the file to the controller, then tell it to start. There’s another connect and some status commands as well, just incase it times out after uploading the file, it reconnects to send the start print command.

EDIT: The touchscreen will show a disconnected from Luban message with a button called stop… Do NOT tap stop on the touchepad. The entire file is sent to the machine before it starts, even if you actually use Luban. It only shows status after starting, you can close Luban entirely and it’ll keep going. Never touch this button.

EDIT2: Speaking of, a fun fact you can do after starting a project is to connect Luban AFTER using the drag/drop. You can see a realtime location and a progress meter incase you wanted to see how much is left just as if you had started via Luban.

EDIT3: It seems with larger files (say >15MB) it disconnects before completing the upload. This is because the snapmaker keeps the connection alive by receiving a status request every few seconds. I don’t know what the ttl is for this, so the solution is to connect Luban and let it keep the connection, or do a status spam until it begins. I’ll see what I can do to mitigate this.

EDIT4: Nevermind, made a keep alive script and attached it below. Start the keep alive, then the project, once the project window disappears (and the project begins) Ctrl-C on the keep alive.

@echo on
curl -X POST "http://[IP HERE]:8080/api/v1/connect?token=[TOKEN HERE]"
:x
curl -X GET "http://[IP HERE]:8080/api/v1/status?token=[TOKEN HERE]&1674308796842"
echo Tap Ctrl+C to stop after the project begins.
timeout /t 2 /nobreak
goto x

KeepAlive.zip (304 Bytes)

4 Likes

Another fun addon to this I found during my tests. You can actually recover the file you previously sent (given you haven’t ran another project since then). This even works AFTER SHUTDOWN, the file stays wherever it’s loaded to and can be retrieved even after powercycling. So if you ran a project, deleted the file, but needed another for some reason, as long as you didn’t do any other things, you can get that file back.

@echo on
curl -X POST "http://[IP HERE]:8080/api/v1/connect?token=[TOKEN HERE]&1674308796842"
curl -X GET "http://[IP HERE]:8080/api/v1/print_file?token=[TOKEN HERE]" >> PulledFile.nc

GetFile.zip (290 Bytes)

After putting in your IP/Token and saving, simply run it and it’ll dump a file named “PulledFile.nc”, which should be the last gcode thing you uploaded.

Ha! Just got an XTool D1 Pro a couple days ago, and already had lightburn setup for it and was trying to come up with a way to use it without being tethered and the answer was right infront of me. I literally just used the same method for the snapmaker. :upside_down_face: Using wireshark I got the POST URL and plunked it into a bat file. No need for the constant ping either.

@echo on
curl -X POST -F file=@%~1 "http://XXX.XXX.XXX.XXX:8080/cnc/data?filetype=1"
pause

Replace the XXX.XXX.XXX.XXX with your XTool D1 IP, save as a .bat, and just drag/drop your lightburn files onto it.
While not a snapmaker, figured I’d share since it was a spinoff of this solution. :slight_smile:

A few more I made.

If you’re doing batch production and just want to keep repeating the same thing, you can simply send the start print code again via a bat file. I saved it as RestartPrint.bat

@echo off
curl -X POST "http://[IP HERE]:8080/api/v1/connect?token=[TOKEN HERE]"
curl -X POST "http://[IP HERE]:8080/api/v1/start_print?token=[TOKEN HERE]"

Same if you want to stop it if something goes wrong and you’re not close to the machine, named unironically StopPrint.bat

@echo off
curl -X POST "http://[IP HERE]:8080/api/v1/connect?token=[TOKEN HERE]"
curl -X POST "http://[IP HERE]:8080/api/v1/stop_print?token=[TOKEN HERE]"

A fun one, if you want to send lines of code yourself (basically the console in Luban). I named mine SendCode.bat It will continue to ask for the next command until you close the window.

@echo off
:a
set /p code=gcode to send:
curl -X POST "http://[IP HERE]:8080/api/v1/connect?token=[TOKEN HERE]"
curl -X POST "http://[IP HERE]:8080/api/v1/execute_code?token=[TOKEN HERE]&code=%code%"
goto :a

Keep in mind the letters in the gcode have to be capitals. i.e. G28 and not g28 and either send it with no spaces G0Y100 or with underscores G0_Y00. This works with the snapmaker specific MXXXX codes as well, such as M2000 for system inquiry. This is how the console in Luban works, anything you input is sent as a web API using the above URL. Just more on my endeavor to not use Luban at all. :upside_down_face:

1 Like

Maybe you need this: Release v1.5 · macdylan/sm2uploader · GitHub

$ sm2uploader model.nc slice.gcode
$ sm2uploader -host CNC-350 model.nc

It allows you send files directly to any SM printers. FDBK is welcome :slight_smile:

I’m a bit confused as to why you suggested I need this, in a thread that’s a guide. Though I appreciate the work that’s been done by any member of the community.

Personally, to me, the workflow of just dropping one file onto another, in which it automatically uploads and starts is a bit cleaner than using command line. It’s not fancy, and first setup is a little technical. But once you have the info you need, it’s quick and easy to use.

No offense, but I personally think this guide is complicated and needs to be filled with a lot of information precisely, any mistake will not work correctly.

To each his own :upside_down_face:. I find copying two lines once for a send and forget easier than having to memorize and type bash commands everytime.

First off, these lightburn / wireless setup guides have been great. Iverson been able to follow them all the way up to the very last part! I’m having just one issue though.

When I run the Start_print.bat I’ve made, it will show as connected on my Snapmaker, and disconnect shortly thereafter.

Running the KeepAlive and then running the Start_print results in the SnapMaker machine eternally being connected to the computer, though it still doesn’t start the file. No movement or anything coming from the Snapmaker. The established connection will stay there until I Ctrl+C KeepAlive. Any idea what might be causing this or where I should look?

A quick check would be to make sure to at least home the snapmaker from the touchscreen first. Then make sure there’s no spaces in the name of your laser gcode file.

Seeing the disconnect screen is normal, the file is uploaded to the controller so it will finish if it starts. Do NOT tap the stop button on the touchscreen. Also if it’s a particularly large file (say a raster image) it may take a minute to actually start as the machine processes the file.

Okay, have not homed from the touchscreen. I’ll do that. Was reading through the threads and realized I may not have had the correct version of base firmware installed on my machine, as I just updated to the most recent official version by Snapmaker before installing the custom Firmware. Thanks for the quick response, having such a quick way to start laser files is going to be astounding!

Hope the solution is simple. :slight_smile: I will say, being able to just toss something on the machine and walk away and drag/drop/forget is something you get spoiled to. :upside_down_face:

Got that firmware flashed back on and homed, it works! Can drag drop with ease now! Couple bugs that I have to iron out.

I’ve noticed after completing a job, it is unable to drag/drop without me interacting with the machine. Opening Luban revealed that it had an unknown job going with no estimated time. Could not stop it from Luban. Walking to my machine revealed that it was just on the control screen, just where I had left it. Had to cycle machine power to get it to work again.

Gonna take a minute to get used to it, but this is great!

Hi guys,
I got a problem with the sending via Wifi. When i create a gcode file and try to send it to my machine, the Z axis is in the wrong position.
If i run that same gcode file through lightburn connected via USB it works just fine.
Can anyone help me please.

Make sure you’re using absolute coords for positioning, and that you’ve input the proper material height. Would you mind uploading the gcode file you’re trying to run?

Thanks for the quick response.
here is the gcode file.
i can’t upload it, beacuse I’ a new user… so here is a link to it:

Upload it to something like zippyshare, or copy/paste onto pastebin please. Your link requires signin.

Hope this works :sweat_smile:

Hm, everything looks right, focal length of 25mm and lasering something 4mm thick? You’re using the printfile code right? Where it auto-starts after it uploads?

EDIT: Also put a G90 after the M28 in the header, before the G53.

Sorry for the delayed response.
Yes exactly. focal length 25mm and material is 4mm thick. Yes I use your printfile. As said it starts just fine, but the Z height isn’t correct.