API Question/Gcode-upload

edited December 2019 in General
I am trying to upload Gcode to the server with a python script/websocket but I can't seem to get it to work.
I have sucessfully logged into the server via websocket and I can ping the server, move the printer etc. Uploading the file through the GUI also works.

The Websocket command that I am using is:

{"action":"importURL","data":{"folder":"visitenkarten","files":{"name":"newfiletoprint","url":'+Folderstring+',"job":true} },"printer":"testdrucker","callback_id":548}

where Folderstring is the Folderpath. I have tried to use / instead of \\ but wasn't sucessful.

Folderstring='"folder://I:\\Uni\\Hochschule\\PA_Visitenkarten\\CFFFP_Visitenkarte_duenn.gcode"'
 
The server gives the following response:
{"callback_id":548,"data":{"msgId":"5f02f5e8-c801-4b1a-ad99-16831c1dc45c","ok":true},"session":"86!i%U6509!CIDPeLF44w!wI1o4Lmj7e"}
and then sends
{"callback_id":-1,"data":[{"data":{"finished":true,"msgId":"5f02f5e8-c801-4b1a-ad99-16831c1dc45c","ok":false,"progress":0.0},"event":"progressUpdate"}],"eventList":true}

Can anyone help with this?

Comments

  • I got a bit further now. I was missing [] around the files. Now it seems like the upload is sucessfull but I can't find it anywhere on the server.
    I am a bit confused what goes into the "folder" argument of the "importURL" command.
    I created a project, a directory and a Gcode group in the printer settings all with the same name but the "getFolders" command can't seem to find any of them.
    {"callback_id":540,"data":{"folders":[],"ok":true},"session":"CWs4Ztw#8iZutajc8ux$BA!!UoW5143S"}
  • I think you are using the wrong command.It is named importURL as it downloads from web a file and imports that directly. With the folder syntax you can also import files available in your servers harddisk. It is not able to access files on the posting pc except if it is the same one.

    After sending you get progressUpdate with msgId from first response about the progress. The response you got means it failed importing. If you check the logs/server.log file you should also see the reason why it failed. So either something I do not see or different computers.

    For real uploading using a webform post you need the non websocket solution described in API or that you see in the simplify upload example in the docs section on our homepage. 
  • Thanks for the reply.
    The server is running on the posting pc. I got a different response from the server, which I think means that the upload was successful (?) but I can't see where it has uploaded the files. The server logs do not contain any useful information, just Baudrate errors since the printer isn't connected.
    Command that I used is the same as in my initial post exept the added [].
    Server response:
    {"callback_id":-1,"data":[{"data":{"finished":false,"msgId":"9b8287d9-784a-4802-8d01-19b833ce79ce","ok":true,"progress":50.0},"event":"progressUpdate"},{"data":{"finished":true,"msgId":"9b8287d9-784a-4802-8d01-19b833ce79ce","ok":true,"progress":100.0},"event":"progressUpdate"}],"eventList":true}

    I have seen the simplify upload example and will try that if everything fails.
  • Yes, that looks like successfull upload. If you see in the folder printer/testdrucker/models there should be a new file at the end with highest number.
    After looking into your command you send I see an error for files. You send it as object but is must be an array of objects since you can import several files at once. Maybe that is preventing the import.
  • I looked into the folder, If I upload files manually using the GUI they appear there, if I try to use the websocket nothing changes. Maybe it is a Windows related issue? 
    The full command that I am sending is (I tried making it somehat better readable, I send it without the whitespace) :
    {"action":"importURL",
    "data": {"folder":"models",
                "files":[{ "name":"newfiletoprint",
                             "url":"folder://I:/Uni/Hochschule/PA_Visitenkarten/CFFFP_Visitenkarte_duenn.gcode",
                             "job":false
                         }]
                },
    "printer":"testdrucker",
    "callback_id":548}

    My only other guess would be that somehow in line 2 ' "folder":"models" ' is wrong. Is the folder argument related to the Gcode groups?
  • "job":false means it goes to print queue not into models! So it would end in jobs folder. folder is ignored in this case.
    "folder" is the assigned group in case "job":true and must exist before uploading. Set it to "#" to use the default folder.

  • Thanks. There still seems to be an issue with the url/windows paths:
    If I set "folder" as
    "folder://I:/Uni/Hochschule/PA_Visitenkarten/CFFFP_Visitenkarte_duenn.g
    and look into the Errors logs I get 
    File not found: folder://i/Uni/Hochschule/PA_Visitenkarten/CFFFP_Visitenkarte_duenn.g
    If I set folder as "folder://I:\Uni\Hochschule\PA_Visitenkarten\CFFFP_Visitenkarte_duenn.g
    I get 
    Bad URI syntax: bad or invalid port number: niochschuleA_VisitenkartenFFFP_Visitenkarte_duenn.g
    I think this should not be an issue on my Raspberry Pi where I inted to run the whole script but is there a workaround for windows?

  • Got it to work. Took just a few hours together with a friend :)  Would greatly appreciate if you could improve the description of your Server API a bit. Apart from serveral copy paste errors the descriptions could be a bit more specific. The working command is as follows:
    {"action": "importURL", "data": {"folder": "visitenkarten", "files": [{"name": "", "url": "folder://2/Uni/Hochschule/PA_Visitenkarten/CFFFP_Visitenkarte_duenn.gcode", "job": false}]}, "printer": "testdrucker", "callback_id": 548}

    The problems were:
    In the files argument, "name" has to be left empty.
    In the files argument, folder in "url" needs to be manually added and referenced by id ( number 2 above).
  • Had a look into docs and improved it a bit. But the part with the folder id was already contained.

    name can be left empty but also works with name. Important part should be that the file must have one of the supported extensions (added to docs). If left empty the name from url is used instead.
Sign In or Register to comment.