Curl As Gcode Sender

I have no idea why I went down this rabbit hole and came up with this absolute monstrosity of a way to run projects. I do not recommend this, but I’m sharing it anyway to maybe get other people thinking…

Started out with a simple thought; what’s the way Luban sends commands to the snapmaker and how can I implement them? It’s been a bit well known that Luban uses HTTP POST and GET for most everything. So after messing around a bit, a new question arose in my mind…

“Can I make sending gcode seamless and run my lightburn full control gcode without the cable?”

And thus this project was born… And what chaos it is… It’s also not even any easier! If anything it’s harder and can ruin your projects! :upside_down_face: However, if you want to tinker with it, save the following as a .bat file, editing in your snapmaker’s IP and token (remove brackets as well). Finding your token is outside of the scope of this… guide? No… it’s not a guide it’s an abomination! You will also need curl for windows found here:
https://curl.se/windows/

@echo on 
    setlocal enableextensions disabledelayedexpansion

    set "search= "
    set "replace="

    set "textFile=%~1"

    for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
        set "line=%%i"
        setlocal enabledelayedexpansion
        >>"%textFile%" echo(!line:%search%=%replace%!
        endlocal
    )
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (%~1) do (
echo curl -X POST "http://[SNAPMAKER IP]:8080/api/v1/execute_code?token=[SNAPMAKER TOKEN]&code=%%a" >>%textFile%.bat
)

Is this code pretty? no… Is it a hack job? very much so. Basically after inserting your IP and Token into the last line, save as a .bat file. Then, generate your project in Lightburn as usual (for full control, you’ll need the Z height). Drag and drop your .nc file onto the .bat file and it’ll begin a fairly slow process of removing all spaces and commented lines, then converting every gcode line into an HTTP POST line for curl. After it finishes, you’ll have a new file named the same as your .nc but is a .bat. This is a file of tons of curl commands. Connect to your snapmaker with Luban (I gave up before implementing a proper connect command :slight_smile: just to make it more ridiculous), and run the generated .bat file. It should come up with a command prompt box and you’ll see it literally DDoSing your snapmaker with GCode URLs and your snapmaker will begin to run the project, line by line!

If you decide to try this, comment on how well (or not) it went. Unlike my other guides, I won’t really be answering any questions on how to do it, as it’s mostly just a fun set of tests that ultimately ends up being about the absolute worst way to run a project on the snapmaker.

3 Likes

sunglasses

… that’s certainly a way to do it.

1 Like