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.8k
    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.
    • wilrikerundefined
      wilriker @EMRosa
      last edited by wilriker

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

      I've tried single quotes, escape characters, and changing it to an argument passed through the m-code command;

      execonmcode --command "sudo pkill -fx %F" -mCode 7720 -execAsync
      

      I thought about this some more and actually the above should work. Though probably as you use -fx on pkill this has to match the full commandline, i.e. you also have to specify the path to python3, so you will probably need use the following command:

      M7720 F"/usr/bin/python3 script.py"
      

      EDIT: to find the full commandline while your script.py is running use

      $ pgrep -fa "python3 script.py"
      

      This should give you the PID as well as the full command-line of your process.

      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
      • EMRosaundefined
        EMRosa
        last edited by

        Thanks so much for the assist! I’ll try that, but I was using the exact process as listed from

        ps -aux | grep python3

        This lists the process as “python3 location/to/script/script.py”.

        In my case, I was able to put the command line call in another python script and just call it that way. I just wasn’t sure if it would be helpful (or necessary) for execonmcode to be able to send quoted arguments. (Or more likely, if I was doing it wrong. Haha)

        I’ll let you know if adding the path to python helps.

        wilrikerundefined 1 Reply Last reply Reply Quote 0
        • wilrikerundefined
          wilriker @EMRosa
          last edited by

          @EMRosa Since you are using pkill you need to use pgrep to find the required command line (it's the same binary that acts different based on which name it is called with but shares common features otherwise). ps is a different tool that uses (and prints) a different format usually dropping the path to the executable. I think there is a flag to ps to add it but I don't know that off-hand.

          Also quotes are not necessary for execonmcode. Quotes are a concept of shells (sh, bash, zsh, fish, etc.) to provide means to human users to provide command arguments containing spaces. If an application runs another application they usually can provide arguments containing spaces without the need for quotes.

          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
          • wilrikerundefined
            wilriker
            last edited by

            Release 5.2.0

            I am pleased to announce release of execonmcode 5.2.0.

            This release uses the latest version of godsfapi and makes use of the filters option in InterceptConnection, i.e. it will only receive those codes the user is interested in. This will significantly lower the the required resources e.g. while running a job.

            As usual the binaries can be found at GitHub Releases page.

            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 Reply Quote 2
            • oozeBotundefined
              oozeBot @wilriker
              last edited by

              @wilriker at what point in the bootup cycle is execonmcode ready? I created a custom mCode that I'd like to call at the beginning of config.g, but it says it's unsupported. If I call it separately, or at the very end of config.g, it works correctly.

              Any thoughts?

              wilrikerundefined 1 Reply Last reply Reply Quote 0
              • wilrikerundefined
                wilriker @oozeBot
                last edited by

                @oozebot I think that primarily this depends on when execonmcode is started relative to startup of DCS. Or maybe DCS will even delay accepting API clients until a certain amount of startup tasks have been processed. @chrishamm should be able to give more insights on that.

                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

                chrishammundefined 1 Reply Last reply Reply Quote 0
                • chrishammundefined
                  chrishamm administrators @wilriker
                  last edited by

                  @wilriker If ExecOnMCode is installed as a DSF plugin (will be officially supported in 3.3), it's started by DuetPluginService which is started by multi-user.target. Note that v3.3 will introduce /sys/dsf-config.g as well which is executed as soon as all the enabled plugins have been started.

                  Previously plugins were started by DCS, so by basic.target AFAIR.

                  @oozeBot Either move your custom codes to dsf-config.g if you're on pre-3.3 and/or add a delay to the end of your config file to make sure ExecOnMCode has been fully started before they're executed.

                  Duet software engineer

                  oozeBotundefined wilrikerundefined 2 Replies Last reply Reply Quote 0
                  • oozeBotundefined
                    oozeBot @chrishamm
                    last edited by

                    @chrishamm @wilriker - thank you both. We are just about to begin testing the 3.3 betas. This may need to be postponed until after it is released.

                    1 Reply Last reply Reply Quote 0
                    • wilrikerundefined
                      wilriker @chrishamm
                      last edited by

                      @chrishamm As of right now ExecOnMCode is a simple API client just connecting to the socket. It is not yet converted to an official plugin. It will be started by a user-provided systemd unit (or arbitrary other means) completely independent of DCS.

                      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
                      • CrazyCreatorundefined
                        CrazyCreator
                        last edited by CrazyCreator

                        @wilriker
                        I once wrote you a PM in German. because I don't know if you understand what I am writing via google translator 😉

                        @All
                        I would like to send an http command using the Mxxxx command.

                        Let's assume I've installed everything as shown in the video linked here.

                        What do I have to enter where and how around this line:

                        http://IP.Adrresse.Of.Shelly/relay/0?turn=off

                        to be able to send?

                        P.S or edit or next step
                        i installed the ExecOnMCode with help of the two videos. but the shutdown (poweroff) with M7722 don't work for me.
                        The Service is running:
                        Bildschirmfoto 2021-05-18 um 22.03.40.png

                        but in DWC i see this message:
                        M7722
                        Warning: M7722: Command is not supported

                        And the Raspi is still working/running.

                        On Terminal (connected with Raspi) i see:
                        pi@CCC:~ $
                        2021/05/18 22:24:53 Connection to DCS closed
                        2021/05/18 22:24:53 EOF
                        pi@CCC:~ $

                        http://www.crazycreatorcube.com

                        wilrikerundefined CrazyCreatorundefined 2 Replies Last reply Reply Quote 0
                        • wilrikerundefined
                          wilriker @CrazyCreator
                          last edited by

                          @crazycreator So, if you want to make a simple HTTP/GET call I'd say you need a cURL or wget command:

                          execonmcode -mCode 1234 -command 'wget -O /dev/null "http://IP.Adrresse.Of.Shelly/relay/0?turn=off"'
                          

                          If you want to put that into the ExecStart line of a systemd unit you have to deal with systemd's escaping syntax. That will be a bit ugly but doable. Otherwise you could move the wget call into a simple bash-script and call that - one for on and one for off.

                          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
                          • CrazyCreatorundefined
                            CrazyCreator
                            last edited by CrazyCreator

                            Ok .. sounds good.

                            But actually the script is not running correct ... the error popup on web-gui is the only reaction when I send M7722. The Raspi don't shut down or restart after this M7722 command.

                            the terminal show what you see on my terminal screen in my last posting

                            pi@CCC:/usr/local/bin $ sudo ./execonmcode -mCode 7722 -command "poweroff"
                            2021/05/19 20:47:59 Connection to DCS closed
                            2021/05/19 20:47:59 EOF

                            I think that's the problem. But i have no idea how to fix this.
                            I did the installation exactly as shown in the video.

                            http://www.crazycreatorcube.com

                            1 Reply Last reply Reply Quote 0
                            • CrazyCreatorundefined
                              CrazyCreator
                              last edited by CrazyCreator

                              nobody answer me? 😞

                              when i try the command in terminal, connected with the Pi, with additional parameter
                              i see this output

                              pi@CCC:~ $ sudo /usr/local/bin/execonmcode -mCode 7722 -command poweroff -debug -trace
                              2021/05/20 15:54:21 7722: poweroff 
                              2021/05/20 15:54:21 [DEBUG] <Recv> {"version":11,"id":20}
                              2021/05/20 15:54:21 [DEBUG] <Send> {"Mode":"Intercept","Version":7,"InterceptionMode":"Pre"}
                              2021/05/20 15:54:21 [DEBUG] <Recv> {"success":true}
                              2021/05/20 15:54:21 [DEBUG] <Connect> Connection established
                              

                              but the Pi don't reboot or shut down ... no reaction
                              on dwc the same ... no reaction

                              http://www.crazycreatorcube.com

                              wilrikerundefined 1 Reply Last reply Reply Quote 0
                              • wilrikerundefined
                                wilriker @CrazyCreator
                                last edited by

                                @crazycreator Can you check if the command poweroff does work on your system in the first place?

                                Also please check execonmcode version (parameter -version). It looks to me as if you are using an older version.

                                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

                                CrazyCreatorundefined 1 Reply Last reply Reply Quote 0
                                • CrazyCreatorundefined
                                  CrazyCreator @wilriker
                                  last edited by

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

                                  Can you check if the command poweroff does work on your system in the first place?

                                  How can i do this?

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

                                  Also please check execonmcode version (parameter -version). It looks to me as if you are using an older version.

                                  pi@CCC:~ $ sudo /usr/local/bin/execonmcode -version
                                  2021/05/20 16:20:43 0x24142bc
                                  pi@CCC:~ $ 
                                  

                                  http://www.crazycreatorcube.com

                                  wilrikerundefined 1 Reply Last reply Reply Quote 0
                                  • wilrikerundefined
                                    wilriker @CrazyCreator
                                    last edited by

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

                                    How can i do this?

                                    Run sudo poweroff and check what that does.

                                    pi@CCC:~ $ sudo /usr/local/bin/execonmcode -version
                                    2021/05/20 16:20:43 0x24142bc
                                    pi@CCC:~ $ 
                                    

                                    That looks like a bug in previous version and it may be that DCS is rejecting this client. Please get the version 5.2.0 of execonmcode from GitHub and try again.

                                    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

                                    CrazyCreatorundefined 1 Reply Last reply Reply Quote 0
                                    • CrazyCreatorundefined
                                      CrazyCreator @wilriker
                                      last edited by

                                      @wilriker I used 5.1 so that I could imitate the tutorial 100%. now I'm back on 5.2

                                      sudo poweroff

                                      pi@CCC:~ $ sudo poweroff
                                      Connection to ccc.local closed by remote host.
                                      Connection to ccc.local closed.
                                      

                                      Versionscheck

                                      pi@CCC:~ $ sudo /usr/local/bin/execonmcode --version
                                      5.2.0
                                      

                                      Debug and Trace

                                      pi@CCC:~ $ sudo /usr/local/bin/execonmcode -mCode 7722 -command -poweroff -debug -trace
                                      2021/05/20 16:35:27 7722: -poweroff 
                                      2021/05/20 16:35:27 [DEBUG] <Recv> {"version":11,"id":21}
                                      2021/05/20 16:35:27 [DEBUG] <Send> {"Mode":"Intercept","Version":10,"InterceptionMode":"Pre","Channels":["HTTP","Telnet","File","USB","Aux","Trigger","Queue","LCD","SBC","Daemon","Aux2","AutoPause","Unknown"],"Filters":["M7722"],"PriorityCodes":false}
                                      2021/05/20 16:35:27 [DEBUG] <Recv> {"success":true}
                                      2021/05/20 16:35:27 [DEBUG] <Connect> Connection established
                                      

                                      put the M7722 command in DWC Console ... show me this in terminal

                                      2021/05/20 16:35:58 Connection to DCS closed
                                      2021/05/20 16:35:58 [DEBUG] <Close> Closing connection
                                      2021/05/20 16:35:58 EOF
                                      

                                      http://www.crazycreatorcube.com

                                      wilrikerundefined 1 Reply Last reply Reply Quote 0
                                      • wilrikerundefined
                                        wilriker @CrazyCreator
                                        last edited by

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

                                        pi@CCC:~ $ sudo /usr/local/bin/execonmcode -mCode 7722 -command -poweroff -debug -trace
                                        

                                        At least this time you used -poweroff which most likely is not a valid command. 😉

                                        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

                                        CrazyCreatorundefined 1 Reply Last reply Reply Quote 0
                                        • CrazyCreatorundefined
                                          CrazyCreator @wilriker
                                          last edited by CrazyCreator

                                          @wilriker
                                          but in shutdownsbc.service is used and in the video tutorial too.

                                          What should I write / use that instead?

                                          What else can I try to get the script to work?

                                          http://www.crazycreatorcube.com

                                          wilrikerundefined 1 Reply Last reply Reply Quote 0
                                          • wilrikerundefined
                                            wilriker @CrazyCreator
                                            last edited by

                                            @crazycreator Just remove the dash from the start of poweroff then it should work.

                                            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

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