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

Logging

General Discussion
2
7
464
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.
  • L
    legtod2
    last edited by Feb 20, 2022, 5:52 PM

    Logging on raspberry pi.

    Building a few triggercmds on my raspberry pi.
    Simple commands like shutdown and reboot work fine.
    If I want to launch foreground apps like the calculator "galculator" needs to launch a xterm or gnome app. The default user is pi and triggeragent runs as root.
    For debugging purposes of cmds how do I log and view the results.
    For example here is my calulator example.
    {"trigger":"Gnome Calculator","command":"galculator","ground":"foreground","voice":"calculator","allowParams": "false"},
    My assumption is that the command needs references to pi user and xterminal references to launch. But I cant see debug results to fix commands as they become more complex.

    R 1 Reply Last reply Feb 21, 2022, 2:16 AM Reply Quote 0
    • R
      Russ @legtod2
      last edited by Russ Feb 21, 2022, 2:23 AM Feb 21, 2022, 2:16 AM

      @legtod2, to add logging I recommend running a script instead of the galculator command directly. You can add commands in your script that send the output to a log file, like this:

      echo Running galculator script >> /tmp/galculator.log
      

      As far as running GUI X windows apps as root that display in the Pi user's X windows environment, please look at this post.

      Basically you need these two things:

      In your bash script, add this command before it runs galculator:

      export DISPLAY=:0.0
      

      And in one of your bash shells running as the pi user, run:

      xhost +
      

      If you want the GUI app to run as pi instead of root, you can have your script run them with the su command like this:

      su pi -c galculator
      

      Russell VanderMey

      L 1 Reply Last reply Feb 21, 2022, 12:57 PM Reply Quote 0
      • L
        legtod2 @Russ
        last edited by Feb 21, 2022, 12:57 PM

        @russ that makes sense and easy to implement. Thanks for the advise.

        L 1 Reply Last reply Feb 21, 2022, 2:12 PM Reply Quote 0
        • L
          legtod2 @legtod2
          last edited by Feb 21, 2022, 2:12 PM

          @legtod2 That works pretty well
          #!/bin/bash
          su - pi -c 'export DISPLAY=:0.0; galculator'

          {"trigger":"Gnome Calculator","command":"/home/pi/galc.sh","ground":"foregroun
          d","voice":"calculator","allowParams": "false"},

          Now the next logical question is a close command.

          Should I have a 2nd script to perform a kill command or is there a slicker options of having a trigger command with option of open and close ?

          L 1 Reply Last reply Feb 21, 2022, 2:55 PM Reply Quote 0
          • L
            legtod2 @legtod2
            last edited by Feb 21, 2022, 2:55 PM

            @legtod2 Ok so here's my open and close galculator that works
            {"trigger":"Open Calculator","command":"/home/pi/open_galc.sh","ground":"foreground","voice":"open calculator","allowParams": "false"},
            {"trigger":"Close Calculator","command":"/home/pi/close_galc.sh","ground":"foreground","voice":"close calculator","allowParams": "false"},

            cat open_galc.sh
            #!/bin/bash
            su - pi -c 'export DISPLAY=:0.0; galculator'
            pi@raspberrypi:~ $ cat close_galc.sh
            #!/bin/bash
            su - pi -c 'export DISPLAY=:0.0; killall -9 galculator'

            L 1 Reply Last reply Feb 21, 2022, 3:07 PM Reply Quote 0
            • L
              legtod2 @legtod2
              last edited by Feb 21, 2022, 3:07 PM

              @legtod2 Opps minor tweak on commands.json

              {"trigger":"Open Calculator","command":"/home/pi/open_galc.sh","ground":"foreground","voice":"calculator","allowParams": "false"},
              {"trigger":"Close Calculator","command":"/home/pi/close_galc.sh","ground":"foreground","voice":"exit","allowParams": "false"},

              I guess I need to learn about a command with options

              R 1 Reply Last reply Feb 21, 2022, 10:18 PM Reply Quote 0
              • R
                Russ @legtod2
                last edited by Feb 21, 2022, 10:18 PM

                @legtod2, if you want to use the TRIGGERcmd Smart Home Alexa skill to turn on and turn off galculator, I'd recommend using the offCommand field like this:

                {"trigger":"Open Calculator","command":"/home/pi/open_galc.sh","offCommand": "/home/pi/close_galc.sh","ground":"foreground","voice":"calculator","allowParams": "true"},
                

                Notice I set "allowParams": "true" which is necessary to use offCommand, but because you're using offCommand, your /home/pi/open_galc.sh command won't receive the on parameter.

                Alternatively you could use one shell script that expects the on or off parameter like I did here.

                Russell VanderMey

                1 Reply Last reply Reply Quote 0
                2 out of 7
                • First post
                  2/7
                  Last post