Beginner Problems with Exec, Habdroid, my.openhab

hello community,

i’am new with Openhab and need some help, to the following points:
a) i have connected 2 cameras with Openhab. these are shown at to 2 different pages.
As long as i am connected locally to the system, I can switch beteween this 2 pages and everything is working fine.
But If I am connected by my.openhab remotely to the system, it takes a long time, until the picture is shwon.
Sometimes my.openhab and in worst case the complete system crashes.

b) The Cameras are connected to different Raspberry Pis. I want to switch the cameras on and off. I use following code, but it doesn’t work:
Switch System_Cam_Garage “Kamera Garage” (gSystem) { nh=“”, exec=“ON:pi@raspberry sudo service motion start”}

c) Also I tried to use following code: Switch System_OHRestart “Openhab Restart” (gSystem){exec=“ON:/etc/init.d/openhab restart”}
I want to Restart Openhab Service. The result was, that Openhab Service stops but it doesn’t restart.

I can’t help with a).

b) Your exec doesn’t make much sense to me. Is your intent really to do something like:

/usr/bin/ssh rich@garage 'sudo -S service motion start'

One major thing to note is if you indeed are trying to ssh there is a whole mess of things that can go wrong. Just a few:

  • If you installed OH using the preferred apt-get method, OH is running as the openhab user so you must configure the ssh with the proper public and private keys for the openhab user
  • OH has a script which runs at startup that modifies the permissions of all the files in the openhab user’s home directory. The ssh daemon running on the RasPi does not like the files in ~openhab/.ssh to have anything other than user read write permissions

I cannot recommend strongly enough that you use a rule and

val results = executeCommandLine(cmd, timeout)
logInfo("Exec", "Results from cmd: ]n" + results)

instead of the exec binding until you figure out something that works. You can always migrate back to the exec binding later once it works but this is the only way to see any errors that your script or command is producing.

Also, I helped someone earlier today trying to do the exact same thing and it might be currently broken when trying to combine nh and exec on the same item. I recommend moving the link to a rule instead:

rule "Camera RasPi Back Online"
    Item System_Cam_Garage changed from OFF to ON
    val results = executeCommandLine("/usr/bin/ssh rich@garage 'sudo -S service motion start', 5000)
    logInfo("Camera", "Turned on motion with results:\n" + results)

c) Try calling service openhab restart instead of the script directly. When OH runs an external script through executeCommandLine or the exec binding it starts up a new shell that is running under the OH process. When you call the init.d script directly instead of passing the command to the system’s startup daemon the shell that executed the restart gets killed along with OH so the script never gets a chance to restart OH.

If you are on a RasPi with jessie instead of weazy you can use sudo systemctl restart openhab instead of service, though service still works I think.