• Tags
  • Documentation
  • Order
  • Register
  • Login
Duet3D Logo Duet3D
  • Tags
  • Documentation
  • Order
  • Register
  • Login

[DSF Extension] Exec On MCode (was: Shutdown SBC)

Scheduled Pinned Locked Moved
DSF Development
22
117
9.5k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • undefined
    wilriker
    last edited by wilriker 1 Sept 2020, 20:39 4 Dec 2019, 20:16

    Shutdown SBC v1.0

    A small extension to listen for a user-defined M-Code (M7722 by default) to then initiate a clean shutdown of the SBC (it simply executes poweroff - and since it's usually run as root that will work).

    It can be found at GitHub Releases page.

    Usage

    $ shutdownsbc --help
    Usage of shutdownsbc:
      -shutdownMCode int
    	  Code that will initiate shutdown of the SBC (default 7722)
      -socketPath string
    	  Path to socket (default "/var/run/duet.sock")
    

    Installation

    • Download
    • Rename to just shutdownsbc
    • Make executable with chmod +x shutdownsbc
    • Put it into any path in your $PATH e.g. /usr/local/bin
    • Run it as root or with sudo
    • Optional: use the shutdownsbc.service systemd unit (included in the repo) to run it at startup

    Source Code

    You can find it at https://github.com/wilriker/dsfext-shutdownsbc

    Contribution

    As always I welcome any kind of contribution here or over at GitHub. Comments, suggestions, bug reports, Pull Requests, whatsoever. Everything is appreciated.

    Manuel
    Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
    with probably always latest firmware/DWC (incl. betas or self-compiled)
    My Tool Collection

    ? 1 Reply Last reply 8 Nov 2020, 14:47 Reply Quote 2
    • undefined
      wilriker
      last edited by 9 Dec 2019, 12:01

      Exec On MCode v2.0

      After a request on GitHub to also make the command to run configurable I have renamed the whole project to execonmcode and created a new release that will make the command configurable.

      It will also report the outcome of the command (success, error) back to DuetSoftwareFramework.

      As usual it can be found at GitHub Releases page.

      Usage

      $ ./execonmcode --help
      Usage of ./execonmcode:
        -command string
              Command to execute
        -mCode int
              Code that will initiate execution of the command (default 7722)
        -socketPath string
              Path to socket (default "/var/run/duet.sock")
      

      Manuel
      Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
      with probably always latest firmware/DWC (incl. betas or self-compiled)
      My Tool Collection

      undefined 1 Reply Last reply 13 Dec 2019, 09:37 Reply Quote 2
      • undefined
        too @wilriker
        last edited by 13 Dec 2019, 09:37

        @wilriker Great work, the plugin works just as it should! 👍
        We're using it to build a 'move backwards in gcode' function. However, it would be great if we could bring variables into the command string, maybe that could be solved by giving the M code S, P and Q parameters that would translate into $S, $P and $Q?

        Cartesian Duet3+Raspberry pi 4 with 5x 1XD using servo drives printing mortars and concrete

        undefined 1 Reply Last reply 13 Dec 2019, 10:10 Reply Quote 0
        • undefined
          wilriker @too
          last edited by 13 Dec 2019, 10:10

          @too Thanks! I saw your GitHub issue but was a bit busy the last days. Sorry for not getting back to you sooner. Also great to hear that it is actually used by someone other than myself. 🙂

          I'll think about how to do that best.

          Manuel
          Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
          with probably always latest firmware/DWC (incl. betas or self-compiled)
          My Tool Collection

          undefined 1 Reply Last reply 13 Dec 2019, 10:14 Reply Quote 0
          • undefined
            too @wilriker
            last edited by 13 Dec 2019, 10:14

            @wilriker Now RRF3 just needs to be working smooth with some of the more exotic features and the system would be near perfection 😁

            Cartesian Duet3+Raspberry pi 4 with 5x 1XD using servo drives printing mortars and concrete

            undefined 1 Reply Last reply 13 Dec 2019, 10:22 Reply Quote 0
            • undefined
              dc42 administrators @too
              last edited by 13 Dec 2019, 10:22

              @too said in [DSF Extension] Exec On MCode (was: Shutdown SBC):

              @wilriker Now RRF3 just needs to be working smooth with some of the more exotic features and the system would be near perfection 😁

              I expect to release RRF3 RC1 very soon.

              Duet WiFi hardware designer and firmware engineer
              Please do not ask me for Duet support via PM or email, use the forum
              http://www.escher3d.com, https://miscsolutions.wordpress.com

              undefined 1 Reply Last reply 13 Dec 2019, 10:46 Reply Quote 0
              • undefined
                too @dc42
                last edited by 13 Dec 2019, 10:46

                @dc42 looking forward!

                Cartesian Duet3+Raspberry pi 4 with 5x 1XD using servo drives printing mortars and concrete

                1 Reply Last reply Reply Quote 0
                • undefined
                  wilriker
                  last edited by wilriker 13 Dec 2019, 12:08

                  Release v2.1

                  This release provides parameter substitution. Please see the below for details on how to use it.

                  It can be found at the GitHub Releases page.

                  Parameters

                  execonmcode does provide a simple mechanism for parameter substitution. It is possible to pass string parameters to the
                  selected M-Code and have them inserted in the -command. In the command string they have to be single letters prefixed by
                  the percent-sign (%) and they must not be G, M or T.

                  All parameters that do not have a corresponding value in the M-Code will be forwarded as given.

                  Example

                  Run execonmcode as

                  $ ./execonmcode -command "mycommand %F %N %D"
                  

                  Then you can use the following M-Code syntax to replace these parameters

                  M7722 F"my first parameter" N"my second parameter"
                  

                  this will lead to an execution of

                  mycommand "my first parameter" "my second parameter" %D
                  

                  Note that %D was passed as is since it was not given in the M-Code.

                  Manuel
                  Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                  with probably always latest firmware/DWC (incl. betas or self-compiled)
                  My Tool Collection

                  oozeBotundefined 1 Reply Last reply 6 Oct 2020, 17:12 Reply Quote 1
                  • undefined
                    wilriker
                    last edited by wilriker 13 Dec 2019, 21:00

                    Release v2.1.1

                    This is just a bug fix release to address a bug where too many (empty) parameters where introduced in between the command and it's actual parameters. This could lead to various problems.

                    As usual it can be found at GitHub Releases page.

                    Thanks to @too for reporting this. 👍

                    Manuel
                    Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                    with probably always latest firmware/DWC (incl. betas or self-compiled)
                    My Tool Collection

                    1 Reply Last reply Reply Quote 1
                    • undefined
                      wilriker
                      last edited by 31 Dec 2019, 14:51

                      Just as a short teaser: the upcoming version will allow an arbitrary amount of M-code+command pairs.

                      Manuel
                      Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                      with probably always latest firmware/DWC (incl. betas or self-compiled)
                      My Tool Collection

                      1 Reply Last reply Reply Quote 0
                      • tobias_munichundefined
                        tobias_munich
                        last edited by 2 Jan 2020, 14:40

                        great Job !! many thanks.
                        exactly what I looked for

                        Tobias

                        Hypercube-Evolution, Dual-Z, Nimble v2, Orion Piezo
                        Duet3, DuetWifi, Raspberry Pi 4, 7 inch HDMI Display, Panel-Due
                        Firmware: RepRapFirmware for Duet 3 MB6HC 'always the latest release'

                        1 Reply Last reply Reply Quote 0
                        • undefined
                          wilriker
                          last edited by wilriker 1 Jun 2020, 12:31 6 Jan 2020, 12:29

                          Release v3.0

                          This release adds the possibility to provide an arbitrary amount of -mCode + -command tuples. This way it is possible to have a single instance of execonmcode handle all the custom commands.

                          Note that as part of this change there is no longer a default value for -mCode.

                          Get it at GitHub Releases page.

                          EDIT: This version is built agains goduetapiclient 1.2.0 and as such will only work with DSF 1.2.2.1 and later. In case you need a version that is working with DSF <= 1.2.2.0 please tell me here. It's not a problem to provide that as well.

                          Manuel
                          Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                          with probably always latest firmware/DWC (incl. betas or self-compiled)
                          My Tool Collection

                          gtj0undefined 1 Reply Last reply 7 Jan 2020, 00:39 Reply Quote 1
                          • gtj0undefined
                            gtj0 @wilriker
                            last edited by 7 Jan 2020, 00:39

                            @wilriker I can't believe I missed this whole thread! Gonna give it a try tomorrow.

                            I'm also working on something to allow the SBC to do a hardware reset and flash erase via GPIO pins for cases where the firmware is stuck and you can't get to the board. Could be a good companion to your utility.

                            undefined 1 Reply Last reply 7 Jan 2020, 07:59 Reply Quote 0
                            • undefined
                              wilriker @gtj0
                              last edited by 7 Jan 2020, 07:59

                              @gtj0 Glad to hear about any use-cases. 🙂

                              I myself use it to run poweroff as well as activating and deactivating my webcam (starting/stopping a systemd unit).

                              Manuel
                              Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                              with probably always latest firmware/DWC (incl. betas or self-compiled)
                              My Tool Collection

                              1 Reply Last reply Reply Quote 0
                              • ?
                                A Former User
                                last edited by 7 Jan 2020, 08:22

                                Tempting to try with a small I2C OLED on the Pi, but not top of the list just yet

                                1 Reply Last reply Reply Quote 0
                                • undefined
                                  chas2706
                                  last edited by 9 Jan 2020, 19:00

                                  @wilriker

                                  This sounds really good. I would like to use it to activate a bash script on my system but I have attempted to install it and I cant get it to work.
                                  I followed your instructions in your first post but using execonmode V3:

                                  I downloaded execonmode and placed it into /usr/local/bin.
                                  I tried to run it using sudo ./execonmode -help (just to see if it works) but I get the error message "cant open binary".

                                  Could you instruct me where i'm going wrong.

                                  BTW I am on the latest version of RRF3 and up to date with DSF etc.

                                  Thanks in advance.

                                  undefined 1 Reply Last reply 9 Jan 2020, 19:28 Reply Quote 0
                                  • undefined
                                    wilriker @chas2706
                                    last edited by 9 Jan 2020, 19:28

                                    @chas2706 If you run

                                    sudo ./execonmcode -help
                                    

                                    It will try to find the executable in the current directory you issue this command. To have your shell locate it in your $PATH remove the ./ in front of execonmcode. For -help you don't need sudo BTW.

                                    To make sure that it can find it also check if

                                    echo $PATH
                                    

                                    actually does contain /use/local/bin.

                                    Last thing: you spelled it execonmode instead of execonmcode (extra "c" after "m") above. Make sure that's only a typo here. I might rename the executable in the future to something less error-prone.

                                    Manuel
                                    Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                                    with probably always latest firmware/DWC (incl. betas or self-compiled)
                                    My Tool Collection

                                    1 Reply Last reply Reply Quote 0
                                    • undefined
                                      chas2706
                                      last edited by 9 Jan 2020, 19:33

                                      @wilriker
                                      Thanks for the info. I will give it another go.

                                      execonmode was just a typo error in my post lol.

                                      Thanks

                                      1 Reply Last reply Reply Quote 0
                                      • undefined
                                        chas2706
                                        last edited by 9 Jan 2020, 20:05

                                        @wilriker said in [DSF Extension] Exec On MCode (was: Shutdown SBC):

                                        ./execonmcode -help

                                        I have placed execonmcode in /usr/local/bin and typed the following in the terminal without success:

                                        pi@Duet3:~ $ cd /usr/local/bin
                                        pi@Duet3:/usr/local/bin $ ls
                                        execonmcode listen-for-shutdown.py
                                        pi@Duet3:/usr/local/bin $ ./execonmcode -help
                                        bash: ./execonmcode: Permission denied
                                        pi@Duet3:/usr/local/bin $ sudo ./execonmcode -help
                                        sudo: ./execonmcode: command not found
                                        pi@Duet3:/usr/local/bin $ execonmcode -help
                                        bash: /usr/local/bin/execonmcode: Permission denied
                                        pi@Duet3:/usr/local/bin $ sudo execonmcode -help
                                        sudo: execonmcode: command not found
                                        pi@Duet3:/usr/local/bin $

                                        undefined 1 Reply Last reply 9 Jan 2020, 20:12 Reply Quote 0
                                        • undefined
                                          wilriker @chas2706
                                          last edited by 9 Jan 2020, 20:12

                                          @chas2706 Have you made execonmcode executable via sudo chmod +x /usr/local/bin/execonmcode? I think that's missing from the installation instructions.

                                          Manuel
                                          Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                                          with probably always latest firmware/DWC (incl. betas or self-compiled)
                                          My Tool Collection

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post
                                          Unless otherwise noted, all forum content is licensed under CC-BY-SA