How to communicate between a Duet and Python?
-
Hello everyone
I'm trying to get some file automatically out of the duet of my printer and do some calculation/data analysis on python.
I already saw posts about some RRF PythonAPI or DSF-python but I'm totaly lost on what to use or not.I just want to, when I run my script on my PC, that the script get for example the heightmap.csv from my printer and after some calculations, a new GCode to be uploaded to my printer.
How would you do it simply and easily?
In addition would there be issues if the local network is secured (I guess yes, but which ones?)Thanks for all the help anyone can provide
-
-
@Jean-Baptiste Those APIs run directly from a SBC (i.e. - Raspberry Pi) attached to the Duet mainboard(only certain mainboards support it though - like the 6HC). Is that how your setup is configured?
-
If you don't have attached SBC, there is also https://github.com/Duet3D/RepRapFirmware/wiki/HTTP-requests. This is quite a straightforward interface, e.g. a GET of http://11.22.33.44/rr_gcode?gcode=G28 will execute G28 (i.e. home all) on the duet machine at 11.22.33.44. It has file operations (upload, download, list, delete etc.), execute arbitrary gcode, and let you get any part of the object model (which lets you check almost every element of the state or status of the machine).
The one gotcha I found was that you do want to issue the 'connect' with a password parameter, even if you have no password set on the duet machine (in which case just have
password=
in the URL but with no value).For example, at a command prompt in windows (192.168.53.53 is one of my duet printers):
C:\Users\xxx>curl http://192.168.53.53/rr_connect?password= {"err":0,"sessionTimeout":8000,"boardType":"duet5lcwifi","apiLevel":1} C:\Users\xxx>curl http://192.168.53.53/rr_download?name=0:/sys/heightmap.csv RepRapFirmware height map file v2 generated at 2023-02-25 17:19, min error -0.229, max error 0.077, mean -0.067, deviation 0.093 axis0,axis1,min0,max0,min1,max1,radius,spacing0,spacing1,num0,num1 X,Y,25.00,240.00,6.00,204.00,-1.00,43.00,49.50,6,5 -0.158, -0.156, -0.198, -0.180, -0.190, -0.229 0.001, -0.079, -0.188, -0.133, -0.032, -0.004 0.027, -0.098, -0.198, -0.160, -0.024, 0.077 0.048, -0.008, -0.136, -0.078, 0.033, 0.019 -0.024, -0.023, 0.024, 0.060, 0.066, -0.085
Or, once you've connected to the duet machine from a web browser you can drop
http://192.168.53.53/rr_download?name=0:/sys/heightmap.csv
into the address bar of the browser and it will download the height map. -
@oozeBot It is not on a SBC, the software I'm writing will run on computers as I need to gather intel from the duet, do some heavy calculations and produce a file from those calculations.
@achrn Should I download/install any package to use it in python? I think it's the perfect thing and it should be working for me
-
@Jean-Baptiste You'll need something in python that generates HTTP requests. I don't like python (though I use it when necessary) and haven't ever coded anything that interreacted with HTTP so can't help with exactly what and how will do that, but I feel confident there will be something.
(FWIW, when I've done similar I used perl, but that's because an old unix administrator and perl works for me - I wouldn't advocate it for someone that doesn't already know it.)
-
@Jean-Baptiste there are a couple of python projects out there that abstract making the requests to the HTTP API:
https://github.com/AndyEveritt/DuetWebAPI
https://github.com/Spiritdude/RepRapFirmwarePyAPI
The second one is discussed here:
https://forum.duet3d.com/topic/31198/reprapfirmware-python-api?_=1677748196306 -
@Jean-Baptiste In addition to the links above you can use OpenAPI definitions to generate a custom Python client library, see https://github.com/Duet3D/RepRapFirmware/blob/3.4-dev/Developer-documentation/OpenAPI.yaml and https://swagger.io/tools/swagger-codegen/
-
-
Thanks every one, I managed to do exactly what I wanted to get
-