Getting Started with Python DSF
-
Hello all, I am attempting to create a web front-end for the company I work for to use the Duet 3 6HC to control a laser welder I have designed. I have used the 6HC & DWC before in its standard form and it worked great for what we need but the users will be in various locations around the world and need a simple front-end to send pre-set g-code commands from buttons or pre-set jobs which we can load in like the normal DWC does. Having looked into the DWC set-up with the experience I have, namely no JS/Vue experience, it seems the easiest route is to use Python and the dsf-python package alongside Django to do so.
I set the 6HC up yesterday and got the DWC running, today I have set up a Django app which runs, installed dsf-python, placed the send_simple_code() into a util file to be called but cannot see figure out from the documentation on the DSF/DWC how to set-up the connection between the 2. I have no experience of using sockets so it may be down to now understanding this process and missing. Everything which has been done has been done on the PC so far, other than setting up the 6HC and placing the DWC files on the SD card into the device yesterday. I do see in the examples (specifically the endstop sensor) plugin, it requires adding to the DWC and using "npm install" (something which I have not used yet either) but am not sure if this is along the lines of what I need to do as I don't want to add to the DWC I want to just send commands from a front end to control the board.
Any advice even just on directions, examples or even just suggestions of what I am going to need to research and understand would be greatly appreciated!
-
@coolzie1 are you running standalone or with an SBC?
I'm pretty sure python DSF requires an SBC setup -
@coolzie1 @jay_s_uk is right, dsf-python is a client library for the local Duet software running on a potential SBC, so you cannot use it to control remote Duets.
If you wish to use Python with a remote Duet board in standalone mode, have a look at the OpenAPI spec here: https://github.com/Duet3D/RepRapFirmware/blob/v3-chrishamm/Developer-documentation/OpenAPI.yaml You can use the Swagger editor to generate a client library easily: https://editor.swagger.io/
-
Thank you @chrishamm and @jay_s_uk!
I think this is where I am getting a bit lost, I have the device set up on an the network with the DWC in it on the SD card and that's it currently for access as that's all I ever did before. I do have a Pi 4 B at hand which could be used but the idea was to hopefully have global access via web subdomains.
Is there any how to which would cover what I need to know on using the OpenAPI for someone who has never used an API before?
-
@coolzie1 The OpenAPI document is just an abstraction of the different HTTP requests we support. That makes the whole HTTP API portable to different environments/programming languages. You can find another overview of the supported HTTP requests here: https://github.com/Duet3D/RepRapFirmware/wiki/HTTP-requests
If you need to customize the UI, I strongly recommend learning more about NodeJS and Vue(x). The basic architecture is pretty flexible and it should be quite straight-foward to implement what you're trying to achieve (adding a few code buttons here and there). You might not need to program anything at all if you just take a look at the BtnCmd plugin, it lets you customize parts of the UI as well.
Btw it is a bad idea to put 3D printers on the global web if that is something you're planning, especially a Duet in standalone mode would be an easy target for (D)DOS attacks rendering it useless for remote control.
-
@chrishamm It was the idea but that does sound like something we want to avoid... A localhost site would do to be honest as it just needs to be the machine interface to allow the user to control the machine via the 6HC board.
I have no experience with NodeJS and Vue, or JS for that matter, however I did watch one of the Code Academy tutorials on youtube for it last night and although I think with a bit of time I could integrate it to my Django apps, or even build from scratch using Vue like the tutorial depicted, when I navigated the DWC to see where the variables come from, how the page is laid out and how the device is communicated with, I struggled to wrap my head around it.
I did look at the BtnCmd Plugin also but had presumed (somewhat incorrectly) that it would have been better to stick to what I know in python/django and build from there to integrate the API/Socket side of things.
I will have a bit of a recap on what the plan is, what has been suggested and see how I should move forward.
-
@chrishamm I set up the BtnCmd and have confirmed using this would be acceptable to start our project and get things running but we would like to get a custom page long term.
Going down the route of node and vue, I have installed node and installed the DWC but don't see anything I would immediately identify as adjustable to the web pages, I know it states on the git page HTML-5 based interface, but I have been unable to see anything html based other than the vue components?
I appreciate this is now moving away from the DSF aspect of this thread, and thus I want to do some research and try and find at least the avenue to continue down to develop a new Node.Js/Vue interface for our application (and now my own personal development), are you able to advise at all any direct examples of what to do?
-
@coolzie1 https://vuetifyjs.com/ will give you more insight into the custom <v-xxxx> elements and how to use the properties etc.
If you are looking to build a plugin then I suggest you look at the source for one of the existing plugins to give you an idea eg https://github.com/Duet3D/DSF-Plugins/tree/master/EndstopsMonitorPlugin is a simple one to use as a template.
If you are just looking just to send arbitary commands to the control board then the rest api might be an alternative route. You can standup your own descrete website/page with buttons that trigger pre-defind rest api calls. https://github.com/Duet3D/DuetSoftwareFramework/wiki/REST-API
However I would not recommend this approach in isolation, as sending arbitary commands to the board without the user knowing the machine state, could end up being extremely bad.... At a minimum you would need to understand the current machine state and enable/disable your buttons appropriately, to prevent errors. Creating your own skew of DWC, or a DWC plugin would be much safer, as DWC already has the necessary controls in place to understand and manage the machine state, and will generally prevent a user from making a mistake.