Raspberry Pi setup
-
@erin-leiker, I think the problem is you're running the triggercmd agent as a background daemon, and your command is running with "ground": "background", so you can't see the result of your command.
So to make it work, you'll need to:
- Run the agent in the foreground by running the "triggercmdagent" command in a terminal window in X Windows.
- Trigger your command in the foreground with "ground": "foreground" in your commands.json file.
-
@russ thank you for the tips! i did some googling on x windows, and it sounds like it's a way to access or view the pi remotely. do i still need x windows if i have the pi booting to the desktop and i have a screen on it so i can access it directly?
i updated the trigger to "foreground" and tried running triggercmdagent from the cli, but still i just see the log of the command having been run instead of the results of the command (opening that html file).
-
@erin-leiker, that's interesting. You might need to specify the full path of chromium-browser, so your command would be something like:
/path/to/chromium-browser file:///home/pi/myFile.html
To find the path, type this:
which chromium-browser
If you're booting to the GUI, that's X Windows. I'll boot up one of my Pi's and see if I can reproduce the problem you're having.
EDIT: I tried it on my Pi. I found that it worked with or without the full path. I tried /usr/bin/chromium-browser and just chromium-browser and both worked for me, so I don't know what's wrong in your case.
Can you try a simpler command, like echo Testing >> /tmp/test.txt ?
When I did that, it created a /tmp/test.txt file when I remotely ran the command. -
@russ whew, i think i figured it out! if i'm right, it all comes down to users.
the instructions for installing on a raspberry pi are based on running all the commands/installations as a root user. the "chromuim-browser" command does not work when executed as the root user, only the default "pi" user. so i switched the command from "chromium-browser" to "xdg-open", which does essentially the same thing for my purposes, and it worked! well, almost.
i'm trying to launch an html file, and the mime type is "text/html" which opens with chromium by default for the pi user (yay!), but with the geany text editor for root (boo). i solved this by tweaking the command to run under the pi user, and it works as expected!
{"trigger":"myTriggerName","command":"su - pi -c 'xdg-open /home/pi/myFile.html'","ground":"foreground","voice":"myTriggerName","allowParams":"false"}
the only downside is that there is a noticeable delay in triggering this command. and i also have to open a terminal window, switch to the root user, and then run "triggercmdagent" before i can successfully trigger it. with this info, do you happen to know if/how i can:
-
auto run triggercmdagent on boot? the install instructions seem to state that it will launch in the background on boot, so i changed the command to "background" but no dice. still have to run triggercmdagent from terminal as root.
-
run/install triggercmdagent under the pi user instead of root? i think that would help speed up the execution of the command significantly.
thank you so much!
-
-
@erin-leiker, please give this a try:
- Run this as your pi user to allow root to send stuff to your pi user's Xwindows:
xhost si:localuser:root
- Install the background service as root with:
/usr/share/triggercmdagent/app/src/installdaemon.sh
- Make sure this variable is set when your command runs as root in the context of your triggercmdagent:
export DISPLAY=:0.0
Your agent will be running in background mode, so the commands need "ground": "background" to run that way.
I suggest testing with galculator. It's an xwindows calculator app.
-
I created a script to make it easier to install the Raspbian OS and the agent on a new Pi:
-
@Russ said in Raspberry Pi setup:
/usr/share/triggercmdagent/app/src/installdaemon.sh
I followed the steps here, but the list of commands is empty right after install. The command output is:
pi@raspberrypi:~ $ sudo triggercmdagent
Run installdaemon.sh to install the triggercmdagent daemon so it runs during boot
Daemon install: false
No token exists. Login to request one.
prompt: token: ey.........
Token saved for next time.
Tokenfile: /root/.TRIGGERcmdData/token.tkn
ComputerIDfile: /root/.TRIGGERcmdData/computerid.cfg
Logging in with saved token to run foreground tasks.
Computer ID 5eb384a2ee82630019c61bac saved for next time.
Write backup completed.
Initiated command removals
Initiated command adds|> Now connected to https://www.triggercmd.com.
___/ For help, see: http://bit.ly/2q0QDpf
(using sails.io.js node SDK @v1.1.13)
Connected at: Wed May 06 2020 20:46:43 GMT-0700 (PDT){ message: 'Subscribed to 5eb384a2ee82630019c61bac!' }
{ message: 'Subscribed to 5eb384a2ee82630019c61bac!' }
Added Gnome Editor
^C
pi@raspberrypi:~ $ sudo /usr/share/triggercmdagent/app/src/installdaemon.sh
Daemon install: true
Logging in with saved token.
Checking if the 5eb384a2ee82630019c61bac computer exists.
This computer exists in your account.
● triggercmdagent.service - TRIGGERcmd Agent
Loaded: loaded (/etc/systemd/system/triggercmdagent.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-05-06 20:35:25 PDT; 12min ago
Main PID: 864 (node)
CGroup: /system.slice/triggercmdagent.service
└─864 node /usr/share/triggercmdagent/app/src/daemon.js --run /root/.TRIGGERcmdDataMay 06 20:35:33 raspberrypi env[864]: (using sails.io.js node SDK @v1.1.13)
May 06 20:35:33 raspberrypi env[864]: Connected at: Wed May 06 2020 20:35:33 GMT-0700 (PDT)
May 06 20:35:33 raspberrypi env[864]: Initiated command removals
May 06 20:35:33 raspberrypi env[864]: { message: 'Subscribed to null!' }
May 06 20:35:33 raspberrypi env[864]: { message: 'Subscribed to null!' }
May 06 20:35:33 raspberrypi env[864]: Initiated command adds
May 06 20:35:33 raspberrypi env[864]: Failed while trying add a trigger.
May 06 20:35:33 raspberrypi env[864]: Failed while trying add a trigger.
May 06 20:35:33 raspberrypi env[864]: Failed while trying add a trigger.
May 06 20:35:33 raspberrypi env[864]: Failed while trying add a trigger.I have not edited any standard files.
-
@avs2020, it looks like you figured it out because I see commands associated with your raspberrypi computer now. Please confirm.
-
It looks like offCommand is never called using this PI/Debian distribution, do you have an update? Did you forget to include this functionality for Linux, it works fine on Windows.
-
@George-Hatzisymeon, sorry I never responded to this. I just noticed it because someone upvoted it.
I just verified that the offCommand commands.json value is supported in the current version of the Raspberry Pi agent. If you were using that version and it didn't work, then maybe you were missing this part:
"allowParams":"true"
Here's an example entry I just tested. It turns my led strip off if the parameter was off, and if the parameter was on, it turns the strip on and makes the leds green.
{ "trigger":"Green", "command":"\/root\/killrun.sh leds.py green", "offCommand": "\/root\/killrun.sh leds.py off", "ground":"background", "voice":"green", "allowParams":"true" },
-
Russ
-
tuicemen
-
tuicemen
-
Russ
-
Dean McNaughton
-
Dean McNaughton
-
Dean McNaughton