RRF3 / Duet3 with Pi: execute bash through M code



  • I was wondering, with the software framework running on the Pi, wouldn't it be nice to trigger the execution of a bash script from within a macro or even gcode?

    Also, is it possible to somehow send gcode commands to the duet from the attached Pi's terminal?


  • administrators

    This is on the list to be added, once we have decided how to manage the security implications.


  • Moderator

    @too You could write a client to the DuetAPI that listens on a user-defined M-Code and then executes whatever system command you like. There are implementations for .NET and Go available so far (the latter by mean unfortunately missing documentation but it's simply a port of the .NET).

    EDIT: I already have one that listens for M7722 and then executes poweroff.

    EDIT2: I will push this to GitHub tomorrow latest and it can be used as a template.

    EDIT3: Here you go: https://forum.duet3d.com/topic/13194/dsf-extension-shutdown-sbc

    And sending GCode commands from Pi's terminal can be done with CodeConsole that you will find in /opt/dsf/bin/CodeConsole. You need to run it as root though.



  • You can also send gcode to a telnet session on any Duet. Of course, it must be enabled.

    Therefore, I'd imagine you can send G-Code to a telnet 127.0.0.1 on the Pi in a Duet3 configuration (I have not tested this). And many scripting languages will let you open a telnet equivalent and send to it.


  • Moderator

    @Danal said in RRF3 / Duet3 with Pi: execute bash through M code:

    Therefore, I'd imagine you can send G-Code to a telnet 127.0.0.1 on the Pi in a Duet3 configuration (I have not tested this).

    Unfortunately, this won't work.



  • @wilriker thanks, I will look into that!
    I guess I will start learning go then 👍



  • Is 127.0.0.1 not working because telnet does not yet work from anywhere in D3?

    42bff36b-9667-481f-b14b-cf07e4afd3ce-image.png

    Or is that a long-term thing?


  • Moderator

    @too said in RRF3 / Duet3 with Pi: execute bash through M code:

    I guess I will start learning go then 👍

    Go is a great language! My preferred one by now. 👍


  • Moderator

    @Danal OK, maybe we have to distinguish here a bit. Duet 3 running in standalone-mode, i.e. without a SBC attached does have HTTP, FTP and Telnet (optionally) available and will respond to it when enabled. That's just like Duet 2 does. But once you use Duet 3 with a SBC all network traffic will be handled by the SBC - which is simply Linux. DuetSoftwareFramework does not (and IMHO should not) implement Telnet or FTP protocols. It only provides HTTP support via DuetWebServer (based on .NET Kestrel server). So if you are trying to connect to the SBC via FTP or Telnet there has to be a service to accept these connections - but then you will communicate with the SBC like if you would open such a connection to any other Linux machine.



  • @wilriker said in RRF3 / Duet3 with Pi: execute bash through M code:

    @Danal OK, maybe we have to distinguish here a bit. Duet 3 running in standalone-mode, i.e. without a SBC attached does have HTTP, FTP and Telnet (optionally) available and will respond to it when enabled. That's just like Duet 2 does. But once you use Duet 3 with a SBC all network traffic will be handled by the SBC - which is simply Linux. DuetSoftwareFramework does not (and IMHO should not) implement Telnet or FTP protocols. It only provides HTTP support via DuetWebServer (based on .NET Kestrel server). So if you are trying to connect to the SBC via FTP or Telnet there has to be a service to accept these connections - but then you will communicate with the SBC like if you would open such a connection to any other Linux machine.

    If I read this correctly, an SBC equipped D3 has no Telnet support equivalent to D2 telnet support. Ever.

    Interesting design choice. I do understand the logic/reasoning behind it, just as you've explained it. Nonetheless, setting all that reasoning aside, i.e. from "outside", an existing capability goes away. Specifically IP-of-printer:23 is a telnet that accepts G-Code.

    Hmmm... Normal Linux FTP server could be easily configured to 'appear' to be just like the D2 FTP, by way of simply pointing the default directory to the virtual SD... or set it to default to other places on the Pi. End-user choice, easy via configuration on the Pi.

    Is there any Linux standard way to do the same with Telnet? Somehow configure the Pi so that it 'appears' that telnet to port 23 reaches the Duet just like it always did?

    Of course, there are other configurations where telnet would reach the Pi, which we'd likely keep turned off in favor of ssh for reaching the Pi itself.


  • administrators

    It would be perfectly possible (and probably straightforward) to take a Telnet client and have it talk to the API provided by DSF. But Telnet is horribly insecure, so it would be much better to implement SSH or another secure alternative.



  • @dc42 said in RRF3 / Duet3 with Pi: execute bash through M code:

    It would be perfectly possible (and probably straightforward) to take a Telnet client and have it talk to the API provided by DSF. But Telnet is horribly insecure, so it would be much better to implement SSH or another secure alternative.

    Completely agreed. But there it is on D2. Hmm....


  • administrators

    @Danal said in RRF3 / Duet3 with Pi: execute bash through M code:

    @dc42 said in RRF3 / Duet3 with Pi: execute bash through M code:

    It would be perfectly possible (and probably straightforward) to take a Telnet client and have it talk to the API provided by DSF. But Telnet is horribly insecure, so it would be much better to implement SSH or another secure alternative.

    Completely agreed. But there it is on D2. Hmm....

    And it's disabled by default. And we tell users not to make a Duet accessible to the Internet without using a VPN.


Log in to reply