Hi,
I am relatively new to this wonderful Raspberry Pi world and I am trying to use the "onUnbind" event on my VirtualHere USB Server config file.
Here is my configuration :
-VirtualHere USB Server for Raspberry Pi
-vhusbdarm64 v4.8.6
-Raspberry Pi 5 OS 12.11
-The clients have the "Client Service" installed
My goal is to call a python3 script with the "$NICKNAME$" as parameter. For the testing process, I removed the parameter and I am just trying to have a text file modified at any client unbind even.
My config file has this line :
onUnbind=/usr/bin/python3 pathToThePythonAppendScript.py
And the python append alone works well.
(I also check where was my python3 with "which python3")
I know that my config file is correct without this line because I already added other options like DeviceNicknames, onServerRename, or onChangeNickname=return 1.
Here are some of my question :
Syntax question : I'm using "onUnbind" but maybe I should use "onUnBind" ?
Can I call a python3 script or does it have to be bash ?
Can the script be anywhere in the Raspberry, like in my user Documents, or should it be close to the config file ?
Is there any more documentation I can use to get this to work ?
Thank you very much for your time and help !
Kind regards,
Tifanie
.
You can directly call python without bash first. I ran a quick test:
systemctl stop virtualherevi /usr/local/etc/virtualhere/config.iniAdd the line
onBind=/usr/bin/python /home/pi/test.py "$DEVPATH$":wqvi /home/pi/test.pyAdded this text to the file:
import sysimport syslogsyslog.openlog(ident="test_script", facility=syslog.LOG_LOCAL0)if __name__ == "__main__":if len(sys.argv) > 1:syslog.syslog(syslog.LOG_INFO, f"The script name is: {sys.argv[0]}")syslog.syslog(syslog.LOG_INFO, "The arguments are:")for i, arg in enumerate(sys.argv[1:], start=1):syslog.syslog(syslog.LOG_INFO, f"Argument {i}: {arg}")else:syslog.syslog(syslog.LOG_INFO, "No arguments provided.")6.
chmod +x /home/pi/test.py7.
systemctl start virtualhere8. (Used a device via virtualhere)
9. Looked in the syslog (
journalctl) and sawFeb 14 12:11:41 pi5 test_script[2084]: The script name is: /home/pi/test.pyFeb 14 12:11:41 pi5 test_script[2084]: The arguments are:Feb 14 12:11:41 pi5 test_script[2084]: Argument 1: /sys/devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb3/3-1Feb 14 12:11:41 pi5 vhusbdarm64[1967]: Executed "/usr/bin/python /home/pi/test.py "/sys/devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb3/3-1"" for onBind.
Hi Michael,
Thanks for your quick reply !
I tested that but with a simple "echo text >> file" because the log didn't work for some reason. It works well with the onBind but not with the onUnbind (or onUnBind) event.
The log of jounalctl shows that :
- with "onBind" : the script is executed, the Device in BOUND, the script worked because my text has been written on my file.
- with onUnbind : I only see the Device is UNBOUND line but nothing else.
Is there a reason why onBind would work but not onUnbind ?
Kind regards.
Tifanie
.
There is no reason. It works fine for all events so it must be something with your scripts. You should double check them.