Curl + KISS in RRF



  • Greetings all-

    I used to use a curl script as a post processor in KISS slicer to feed the gcode files to Octoprint. Now that I have seen the light and switched to RRF, I am trying to re-write my script.

    I looked at this thread- https://forum.duet3d.com/topic/867/duet-wifi-s3d/13 but the syntax for KISS is simpler. Its not working as i expected and could use some help to debug it.

    Here was the script call in KISS as a post processor -

    <KSPATH>\EV2.BAT "<FILE>" 
    

    the script call would take the filename and pass it on as an argument to the EV2.BAT file, which was simply -

    curl -k -H "X-Api-Key: 0719*****D93" -F "select=false" -F "print=false" -F file=@%1 "http://192.168.0.25/api/files/local"
    

    where it would copy the file to Octoprint folder structure. there is a bunch of stuff for the API key and the like which we dont need with the

    Now I tried doing same with RRF - simple manual file test and this worked.

    curl  -v -F "file=KS_Wizard.gcode" "http://192.168.0.29/rr_upload?name=gcodes/KS_Wizard.gcode"
    

    so now I added in the filename variable and am using the same script call but with new script contents- and this is my output. I tried using the verbose flag to get more info out-

    `curl -v -F "file=@%1" http://192.168.0.25/rr_upload?name=gcodes/@%1'

    F:\3D_Printer\Kiss_1.6.3>curl -v -F "file=@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard.gcode"" http://192.168.0.25/rr_upload?name=gcodes/@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard.gcode"
    *   Trying 192.168.0.25...
    * TCP_NODELAY set
    * Connected to 192.168.0.25 (192.168.0.25) port 80 (#0)
    > POST /rr_upload?name=gcodes/@F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard.gcode HTTP/1.1
    > Host: 192.168.0.25
    > User-Agent: curl/7.55.1
    > Accept: */*
    > Content-Length: 477021
    > Expect: 100-continue
    > Content-Type: multipart/form-data; boundary=------------------------2dc709799e1c8855
    >
    < HTTP/1.1 500 could not create file
    < Connection: close
    < Access-Control-Allow-Origin: *
    <
    <html>
    <head>
    </head>
    <body>
    <p style="font-size: 16pt; text-align: center; margin-top:50px">Your Duet rejected the HTTP request: could not create file</p>
    </body>
    * Closing connection 0
    
    F:\3D_Printer\Kiss_1.6.3>REM curl  -v -F "file=@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard.gcode"" "http://192.168.0.29/rr_upload?name=gcodes/"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard.gcode""
    
    F:\3D_Printer\Kiss_1.6.3>curl "http://192.168.0.25/rr_disconnect"
    {"err":0}
    F:\3D_Printer\Kiss_1.6.3>PAUSE
    Press any key to continue . . .
    

    I feel like I am missing something fundamental. I am pretty sure its not a quotes or spaces thing, I worked that out before and there is no space in anything i this current filename or path.

    I tried using -X POST options too but got similar results.

    Can anyone offer any suggestions as to why it might not be working?

    thanks



  • @sinned6915 sorry if I'm wrong, but according to https://forum.duet3d.com/topic/867/duet-wifi-s3d/40 the -F parameter seems to be a parameter to set the path (the destination path), not a file, so it cannot create this path.



  • i tried following the curl man page-

    https://curl.haxx.se/docs/manual.html

    under the section "POST (HTTP)"

    " -F accepts parameters like -F "name=contents". If you want the contents to be read from a file, use <@filename> as contents."

    which is what I thought we wanted to do. did I misunderstand it?



  • @sinned6915 I would try the syntax in the examples in the thread I mentioned. There the file= has the meaning to set the target path IMO, so f:\ ist not understandable by a system which uses / syntax for directories.



  • i am getting popup saying my post is being flagged as spam.....

    you mean the Duet is not understanding the f:\ ?

    that is the drive letter where the file is being up loaded from.

    its part of the output from Windows.



  • @sinned6915 yes I meant the f:\ , the destination path should be some LINUX similar path.

    spam maybe because we communicate too fast...



  • ok, so the filename coming through the post-process scrip call is the full path AND filename. here i tried to simply output whatever it was given-

    ECHO ON
    ECHO FILNAME=@%1

    output is -

    F:\3D_Printer\Kiss_1.6.3>ECHO ON
    
    F:\3D_Printer\Kiss_1.6.3>ECHO FILNAME=@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard(0).gcode"
    FILNAME=@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard(0).gcode"


  • @sinned6915 I mean somthing like:

    curl -v -F "file=@"/KS_Wizard.gcode"" http://192.168.0.25/rr_upload?name=gcodes/@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard.gcode"

    or if only the output path is expected:

    curl -v -F "file=@"/"" http://192.168.0.25/rr_upload?name=gcodes/@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard.gcode"

    (I am offline now. Good luck!)



  • @JoergS5 thanks for your help- i am making baby steps...

    curl -v -F "file=@%1" "http://192.168.0.25/rr_upload?name=gcodes/%~nx1"
    

    is parsing the filename out of the path but now i am getting timeouts from the Duet.

    F:\3D_Printer\Kiss_1.6.3>curl -v -F "file=@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard(8).gcode"" "http://192.168.0.25/rr_upload?name=gcodes/KS_Wizard(8).gcode"
    *   Trying 192.168.0.25...
    * TCP_NODELAY set
    * Connected to 192.168.0.25 (192.168.0.25) port 80 (#0)
    > POST /rr_upload?name=gcodes/KS_Wizard(8).gcode HTTP/1.1
    > Host: 192.168.0.25
    > User-Agent: curl/7.55.1
    > Accept: */*
    > Content-Length: 2017542
    > Expect: 100-continue
    > Content-Type: multipart/form-data; boundary=------------------------941032cdc9b01eb3
    >
    * Done waiting for 100-continue
    < HTTP/1.1 200 OK
    < Cache-Control: no-cache, no-store, must-revalidate
    < Pragma: no-cache
    < Expires: 0
    < Access-Control-Allow-Origin: *
    < Content-Type: application/json
    < Content-Length: 9
    < Connection: close
    <
    {"err":0}* Closing connection 0
    
    


  • @sinned6915 was your try in http://www.kisslicertalk.com/viewtopic.php?f=13&t=2263 succesful, so you can compare it to today's try? Possible reasons could then be changed curl version or OS.

    Another idea is, maybe it's possible to set debug mode on Duet side.



  • I was using that script to connect windows 10 to Octoprint- same one i started with and posted above.

    I was not able to get it to connect to duet. One of the posters was using a Mac and the script options are different.

    good idea on trying to enable the debugging! i know M111 P2 (?) sets debug in HTTP. I will try that. P1 is network and floods the terminal buffers

    Currently, I am either getting that 'continue' error or an authentication error. I do not have any password set but something tells me i should try to connect with no password regardless to start the connection.



  • @sinned6915 maybe your timeout is because Duet doesn't close the connection, dc42 has commented in https://forum.duet3d.com/topic/867/duet-wifi-s3d/42 to use additional:
    dc42:
    You may wish to add the following line at the end:
    curl "http://XXX.XXX.XXX.XXX/rr_disconnect"
    This will avoid RRF buffering up messages that S3D isn't going to fetch.

    Another idea:
    Your curl command seems to be ok, the connection reported 100 and 200, which means successful. It transmitted 9 bytes. Are you sure it is not a link which you want to upload (the (8) file), which is only 9 bytes long? And you could try -X POST in the command additionally.

    Edit: the content-length comment was wrong, the 9 bytes are the response. But the sending is about 2 MB, maybe there is a file limit somewhere. E.g. https://forum.duet3d.com/topic/4355/maximum-g-code-file-size/3 the SD card clustered.



  • @JoergS5 I saw the content lengths and thought it was odd, but assumed that it was HTTP not file system.

    I have an overnight print going so I will test it out after it gets done. I remember reading about the cluster size somewhere and it prompted me to seek out the official SD card formatter. I can not remember what I used when i formatted the card. Its worth checking out.

    I did try playing with the -X POST but I thought that it complained about being redundant with the -F option. I am not sure why the syntax changes color on this so much, but the first tan line says POST and I assumed that it was using POST. I will have to double check.

    What I can not figure out is if its waiting for a server response- 'multpart' form boundary.



  • @sinned6915 my last few ideas:
    to test whether your connection (with authentication) works correctly, you could start a print with curl of an existing file.
    I saw curl has an alternative to multipart, for post also. You could try this also. But as I understood, curl manages the multipart formatting.
    Kiss may produce specific gcode, you could try the curl with a little general gcode file.
    I saw a curl option like --data-binary, maybe this helps.



  • @sinned6915 I just discovered an intersting tool HTTPie: https://github.com/jakubroztocil/httpie#file-upload-forms which allows to run http commands interactively. This may help finding the problem.



  • @sinned6915 I checked the documentation https://github.com/chrishamm/DuetWebControl, the chapter rr_upload says, a response {"err":0} means, that the transfer was successful.

    So I suspect the target path makes problems.



  • So I am making some headway I think-
    You are right, the transfer is getting initiated, but the payload is empty.
    Here is the partial output of

    M111 S1 P2 - https://pastebin.com/UE2ytPLr

    all it shows is that the connections are initiated and accepted .

    The gcode file list shows the file is there but with 0 length.



  • @sinned6915 I would try using a more current curl version, current is 7.65.1. There were lots of bug fixes since 7.55.1 (list: https://curl.haxx.se/changes.html)



  • Sure about the quoting?
    -F "file=@"F:\3D_Printer\Kiss_1.6.3\EV2\Preload\KS_Wizard(8).gcode""
    Looks like you either need to escape or change the inner qoutes, or more likely remove the outer ones?



  • i updated curl to latest version. no luck

    i played with the quotes, it does not seem to matter.

    I am using DWC 1.22.6 and curl 7.65.1

    can i request that someone who uses curl to do this it add the flag for verbose messages and post the output?

    are you using username and passwd to connect to the DWC or it public?


Log in to reply