Doodle3D / doodle3d-firmware

The API of the Doodle3D WiFi box. This can for example talk to print3d, save settings, update the firmware etc.
www.doodle3d.com
GNU General Public License v2.0
13 stars 9 forks source link

"/d3dapi/printer/stop" API gives an odd error if no "gcode" parameter is given. #21

Closed daid closed 10 years ago

daid commented 10 years ago

When calling the printer/stop API without a GCode parameter (but as POST request) I get the response:

Unable to launch the requested Lua program:
  /usr/share/lua/wifibox/main.lua: No such file or directory

Instead of a normal JSON response. On Version 0.9.9

(Also, the code on the doodle-box does not match the code in the repository?)

woutgg commented 10 years ago

Could not reproduce (with an Arduino connected). I get back {"data":[],"status":"success"}. main.lua is the main entry point for all code so it seems there is another problem. Could you check if the file actually doesn't exist? And maybe run other API calls (both get and post)?

On code differences: branches haven't been merged back to master yet, perhaps that's why you're seeing differences.

daid commented 10 years ago

I'll check on Monday.

I made a python script to call the API calls, I'll put together a test that gave me this result.

daid commented 10 years ago

https://gist.github.com/daid/81134b50e1f27b672481

This python code triggers the error for me if I run it on my 0.9.9 Doodle3D box when there is a print running already. (So my test code tries to stop the print) The Doodle3D box is running in AP mode, the printer is an Ultimaker.

peteruithoven commented 10 years ago

@David, could you explain shortly how to run the script? Also, what happens when you do add a gcode parameter?

daid commented 10 years ago

If I add the gcode parameter I it works as it should.

The script can be run with python from the commandline. (It requires no parameters)

peteruithoven commented 10 years ago

(Can't reproduce this using Advanced Rest Client addon in Chrome) Will try python later.

peteruithoven commented 10 years ago

So finally tried it. Next time I want some more information, like how to use the script. Connecting to the box in access point mode and starting a print from the web interface I could reproduce the problem. The code contained the following section. It doesn't specify a content type when there is no postData.

if postData is not None:
                self._http.request(method, path, urllib.urlencode(postData), {"Content-type": "application/x-www-form-urlencoded"})
            else:
                self._http.request(method, path);

When I change this to the following, I get a regular response back.

if postData is not None:
                self._http.request(method, path, urllib.urlencode(postData), {"Content-type": "application/x-www-form-urlencoded"})
            else:
                self._http.request(method, path,"",{"Content-type": "application/x-www-form-urlencoded"})

Maybe specifying a content-type is required when doing a post request. That's one for the API documentation.

daid commented 10 years ago

Odd.

Note, you're also sending (empty) post data with that change. I'll give it a shot with: self._http.request(method, path, headers={"Content-type": "application/x-www-form-urlencoded"}) As then you do send the content-type but no empty post data.

I still think it is an odd error to get back, but nothing critical.