Duet Web Control - Make REST Call
Hi, can DWC make a REST Call to an external server, say a smart PDU? I understand that there is no REST API for DWC itself. But I get a bit confused when I read about DWC using REST to communicate with the RepRap firmware:
"It is designed to communicate with RepRapFirmware using WebSockets and RESTful HTTP requests."
Please help clarify my confusion.
Ideally, I could define a macro that would make these external REST calls.
Danal last edited by
If you want the Duet firmware to "reach out" and call something somewhere else, the answer is generally no. Getting the firmware layer of an imbedded device into the business of pushing or pulling from other things is philosophically bad for several reasons. So RRF doesn't do it.
You need to poll it. If you only want status, there is an HTTP poll. If you want interaction (issue commands) you need websocket.
If you want to 'push' events on the Duet to something else, you need to poll for those events with an intermediary. Call it a broker if you wish. Could be a simple script.
This is all complicated somewhat when we get to Duet3 with Pi, in that the Pi is both part of the imbedded device, and it is a Pi!! So it can run various things.
So... having said all of that, please say a little more about what you are trying to achieve?
Thank you for the reply. Understood and agree on the firmware reaching out as a bad idea. I was looking for DWC (Not RRF) to make a REST API call to an external target. From the description of DWC it seems like it has the REST client capabilities as it's used to interact with RRF, but maybe this is my confusion.
My goal is to have a Macro that makes a REST POST to the REST-API of a smart PDU. That PDU will switch off the outlet for the printers PowerSupply. In my imagination, this is all DWC related, not RRF.
Danal last edited by Danal
So, yes, that is a valid path.
You could write a simple script that polls, looking for the conditions in which you are interested, and then post to the PDU.
You can avoid polling entirely by going a "hardware oriented" interface. Specifically, you can add a G-Code to the end of the print job that switches one of the Duet's general purpose IO pins, and have that hardware interface into a shutdown for the PDU.
Probably several ways I haven't thought of...
If you are interested in scripting, this is an example of a Python script that can fetch XYZ coordinates from a RepRap2 and/or RepRap3 (it auto-senses). It could be easily modified to watch for the status of "Idle" or "Printing" or similar. And, of course, re-written in any scripting language. The real reusable parts are the URLs, Endpoints, and the subscripts of the JSON objects.
@Danal Awesome! Thank you.