• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo

Raspberry Pi
2
80
6.6k
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.
  • A
    Antonio Francisco S.Santos
    last edited by Jan 22, 2023, 1:14 PM

    Re: Running a python script on a raspberry pi

    R 1 Reply Last reply Jan 22, 2023, 6:00 PM Reply Quote 0
    • R
      Russ @Antonio Francisco S.Santos
      last edited by Jan 22, 2023, 6:00 PM

      @Antonio-Francisco-S-Santos, I translated your title as "Trying to Run a python Script in the LX terminal with TriggerCMD but I'm not succeeding"

      Please try this. Run triggercmdagent --console in a terminal window first, then click the green Trigger button to run your command that runs the python script.

      dd3e85e2-14d3-4fec-b2bc-dd4b7dad0021-image.png

      Also, can you show me your ~/.TRIGGERcmdData/commands.json file?

      Russell VanderMey

      A 1 Reply Last reply Jan 22, 2023, 11:32 PM Reply Quote 0
      • A
        Antonio Francisco S.Santos @Russ
        last edited by Jan 22, 2023, 11:32 PM

        @Russ tenho um script que executa um comando que acessa a câmera do Raspberry pi, porem ele só funciona quando é executado no terminal LX. Coloquei o caminho na linha de comando do Trigger mas da erro quando vai abrir
        {"trigger":"ColorTrack.py","command":"/home/pi/TonyPi/Function/sudo ColorTrack.py","ground":"background","voice":"Robor","allowParams": "false"},
        File "/home/pi/TonyPi/Functions/ColorTrack.py", line 229, in <module>
        cv2.imshow('Frame', Frame)
        cv2.error: OpenCV(4.5.3) /tmp/pip-wheel-pd499c9i/opencv-python_3a15e83eee864e65b7311a199a94e9f1/opencv/modules/highgui/src/window_gtk.cpp:635: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem
        Aparece esse erro:

        R 1 Reply Last reply Jan 23, 2023, 11:22 PM Reply Quote 0
        • R
          Russ @Antonio Francisco S.Santos
          last edited by Jan 23, 2023, 11:22 PM

          @Antonio-Francisco-S-Santos said in Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo:

          Can't initialize GTK backend in function 'cvInitSystem

          I looked up that error. It looks like you have to run the script as root.

          If you've installed the background agent, and the command entry in your /root/.TRIGGERcmdData/commands.json file has ground = background, it should run as root, so you don't need sudo.

          You'll want to make your command log its output to a file though. Otherwise you won't see what it's doing.

          You could make your command something like this:

          python3 /root/ColorTrack.py >> /tmp/ColorTrack.log 2>&1
          

          That will redirect stdout and stderr to /tmp/ColorTrack.log and you can watch the log with a command like this:

          tail -f /tmp/ColorTrack.log
          

          Russell VanderMey

          A 1 Reply Last reply Jan 24, 2023, 1:47 AM Reply Quote 0
          • A
            Antonio Francisco S.Santos @Russ
            last edited by Jan 24, 2023, 1:47 AM

            @Russ Beleza Amigo vou tentar aqui e lhe dou um retorno de como ficou

            A 1 Reply Last reply Jan 25, 2023, 12:03 AM Reply Quote 0
            • A
              Antonio Francisco S.Santos @Antonio Francisco S.Santos
              last edited by Jan 25, 2023, 12:03 AM

              russo
              Então Amigo ainda não deu certo, pois o comando não responde. Fiz um teste com o script dessa forma:
              {"trigger":"ColorTrack.py","command":"/home/pi/TonyPi/Functions/ColorTrack.py","ground":"background","voice":"Robor","allowParams": "false"},
              ele responde ao clicar em trigger mas a tela que exibe as imagem não funciona.

              R 1 Reply Last reply Jan 25, 2023, 3:21 AM Reply Quote 0
              • R
                Russ @Antonio Francisco S.Santos
                last edited by Russ Jan 25, 2023, 3:22 AM Jan 25, 2023, 3:21 AM

                @Antonio-Francisco-S-Santos, can you try this instead?

                {"trigger":"ColorTrack.py","command":"python3 /home/pi/TonyPi/Functions/ColorTrack.py >> /tmp/ColorTrack.log","ground":"background","voice":"Robor","allowParams": "false"},
                

                After you trigger the command, run:

                cat /tmp/ColorTrack.log
                

                Please tell me if it adds anything to that log.

                Russell VanderMey

                A 1 Reply Last reply Jan 25, 2023, 2:04 PM Reply Quote 0
                • A
                  Antonio Francisco S.Santos @Russ
                  last edited by Jan 25, 2023, 2:04 PM

                  @Russ
                  Então Amigo, quando executo esse comando no LXterminal dentro da tela gráfica do raspberry pi ele funciona:
                  ( pi@TonyPiPro:~/TonyPi/Functions $ python3 ColorTrack.py )
                  aparece esse isso ai:
                  ColorTrack Init
                  ColorTrack Start
                  aparece também a tela com a imagem da câmera do raspberry.
                  Acho que por causa da resolução do video só funciona na tela gráfica do debian, teria que ser um script executando o LXtermina com o scriptteste.jpg dentro

                  R 1 Reply Last reply Jan 26, 2023, 12:36 AM Reply Quote 0
                  • R
                    Russ @Antonio Francisco S.Santos
                    last edited by Russ Jan 26, 2023, 12:39 AM Jan 26, 2023, 12:36 AM

                    @Antonio-Francisco-S-Santos, I see now. I didn't realize it was an X-Windows application.

                    If you want to run an X-Windows application as root in the background agent, and have it display on the pi user's X-Windows desktop, please try this:

                    Run this as your pi user (one time):

                    xhost +
                    

                    That allows other users (like root) to display something in your pi user's X-Windows.

                    I haven't tested this, but I think this script would work:

                    #!/bin/bash
                    export DISPLAY=:0.0
                    su - pi -c "python3 /home/pi/TonyPi/Functions/ColorTrack.py"
                    

                    Assuming you created that script as /root/colortrack.sh, your /root/.TRIGGERcmdData/commands.json entry would be like this:

                    {"trigger":"ColorTrack","command":"/root/colortrack.sh","ground":"background","voice":"Robor","allowParams": "false"},
                    

                    This issue originally came up in this post.

                    Russell VanderMey

                    A 1 Reply Last reply Jan 30, 2023, 7:03 PM Reply Quote 0
                    • A
                      Antonio Francisco S.Santos @Russ
                      last edited by Jan 30, 2023, 7:03 PM

                      @Russ Boa tarde Amigo, ainda não conseguir rodar o script que contem vídeos, mas os que não tem vídeos funcionam perfeitamente. Como esse aqui que rodou normal:
                      {"trigger":"Sonar_barrier2.py","command":"/home/pi/TonyPi/Example/Sonar_barrier2.py","ground":"background","voice":"Andar","allowParams": "false"}

                      Também gostaria de saber como faço pra colocar mais script se lá so acetita modificar os quatros script que vem nele como: Reiniciar, executar update.

                      1 Reply Last reply Reply Quote 0
                      • A
                        Antonio Francisco S.Santos
                        last edited by Jan 30, 2023, 8:59 PM

                        Quando tento rodar um script que contem vídeo veja o erro que aparece:
                        LXterminal.jpg

                        R 1 Reply Last reply Jan 30, 2023, 10:17 PM Reply Quote 0
                        • R
                          Russ @Antonio Francisco S.Santos
                          last edited by Russ Jan 30, 2023, 10:17 PM Jan 30, 2023, 10:17 PM

                          @Antonio-Francisco-S-Santos, have you tried setting the DISPLAY variable first?

                          export DISPLAY=:0.0
                          

                          That solved it for "n-gineer" here:
                          https://github.com/opencv/opencv/issues/18461

                          Russell VanderMey

                          1 Reply Last reply Reply Quote 0
                          • A
                            Antonio Francisco S.Santos
                            last edited by Jan 30, 2023, 11:06 PM

                            ai como ficaria o script todo montado? é esse aqui o script:
                            {"trigger":"ColorTrack.py","command":"/home/pi/TonyPi/Functions/ColorTrack.py","ground":"background","voice":"Seguir Cores","allowParams": "false"},
                            Também não estou conseguindo criar mais script alem dos que já existem.

                            1 Reply Last reply Reply Quote 0
                            • A
                              Antonio Francisco S.Santos
                              last edited by Jan 30, 2023, 11:15 PM

                              @Antonio-Francisco-S-Santos said in Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo:

                              {"trigger":" ColorTrack.py ","command":"/home/pi/TonyPi/Functions/ColorTrack.py","ground":"background","voice":"Seguir Cores","allowParams": "false"},

                              nesse caso poderia juntar esse comando no script?
                              export DISPLAY=:0.0
                              {"trigger":" ColorTrack.py ","command":"/home/pi/TonyPi/Functions/ColorTrack.py","ground":"background","voice":"Seguir Cores","allowParams": "false"},

                              R A 2 Replies Last reply Jan 31, 2023, 11:03 PM Reply Quote 0
                              • R
                                Russ @Antonio Francisco S.Santos
                                last edited by Jan 31, 2023, 11:03 PM

                                @Antonio-Francisco-S-Santos said in Tentando Executar um Script python no terminal LX com o TriggerCMD mas não estou conseguindo:

                                export DISPLAY=:0.0

                                No, your script is python, and this command is a bash command:

                                export DISPLAY=:0.0
                                

                                So you could create a ColorTrack.sh bash script like this, and have TRIGGERcmd run it:

                                #!/bin/bash
                                export DISPLAY=:0.0
                                python3 /home/pi/TonyPi/Functions/ColorTrack.py
                                

                                So your commands.json entry would be:

                                {"trigger":"ColorTrack","command":"/home/pi/TonyPi/Functions/ColorTrack.sh","ground":"background","voice":"Seguir Cores","allowParams": "false"},
                                

                                Russell VanderMey

                                1 Reply Last reply Reply Quote 0
                                • A
                                  Antonio Francisco S.Santos
                                  last edited by Feb 1, 2023, 2:13 AM

                                  Então professor o script funciona com o vídeo normal quando executado no LXterminal através PuTTY mas quando executo no Trigger ele começa funcionar e para em seguida. Já mudei a extensão do arquivo do código pra sh deixando assim:
                                  Codigo.jpg
                                  Você tem mais alguma ideia que possa me ajudar?

                                  R A 2 Replies Last reply Feb 1, 2023, 3:11 AM Reply Quote 0
                                  • R
                                    Russ @Antonio Francisco S.Santos
                                    last edited by Feb 1, 2023, 3:11 AM

                                    @Antonio-Francisco-S-Santos, it looks like you're mixing bash code with python code. You should have 2 files:

                                    Bash file: /home/pi/TonyPi/Functions/ColorTrack.sh:

                                    #!/bin/bash
                                    export DISPLAY=:0.0
                                    python3 /home/pi/TonyPi/Functions/ColorTrack.py
                                    

                                    Python file: /home/pi/TonyPi/Functions/ColorTrack.py:

                                    import sys
                                    import cv2
                                    import math
                                    ....
                                    

                                    Russell VanderMey

                                    1 Reply Last reply Reply Quote 0
                                    • A
                                      Antonio Francisco S.Santos @Antonio Francisco S.Santos
                                      last edited by Feb 1, 2023, 12:45 PM

                                      @Antonio-Francisco-S-Santos Professor me desculpe a ignorância mas não entendi bem o que devo fazer, poderia me da um exemplo de como posso deixa os códigos. Já está quase funcionando só falta executar o vídeo.

                                      1 Reply Last reply Reply Quote 0
                                      • A
                                        Antonio Francisco S.Santos @Antonio Francisco S.Santos
                                        last edited by Feb 1, 2023, 12:47 PM

                                        @Antonio-Francisco-S-Santos Outra coisa, se eu comprar a licença de uso por um ano quais as vantagem que terei e facilitará nas montagem dos Scripts?

                                        R 1 Reply Last reply Feb 1, 2023, 1:44 PM Reply Quote 0
                                        • R
                                          Russ @Antonio Francisco S.Santos
                                          last edited by Feb 1, 2023, 1:44 PM

                                          @Antonio-Francisco-S-Santos, google translated that as,

                                          Another thing, if I buy the use license for one year, what advantages will I have and will it make it easier to assemble the Scripts?

                                          The subscription allows you to have more than one computer connected to your account, and you can run more than one command per minute.

                                          It does not make it easier to assemble scripts.

                                          Russell VanderMey

                                          A 1 Reply Last reply Feb 4, 2023, 1:15 PM Reply Quote 0
                                          2 out of 80
                                          • First post
                                            2/80
                                            Last post