1

I would like to switch an On Air sign at my work-from-home office when my webcam is on.

Detecting whether the webcam is on can easily be done via

cat /sys/module/uvcvideo/refcnt 

if it outputs 0 no app is using the webcam, otherwise it is.

I already have a Wifi plug which can be switched using a HTTP GET request.

My only question is: Do I have to poll the output of the above command regularly, or can I get notified in some Bash, Python or PHP script from the kernel?

The idea would be to not generate unnessary system load by polling - or doesn't that matter?

I already tried inotifywait but it does not seem to notice changes on the above pseudo file.

Alex
  • 32,506
  • 16
  • 106
  • 171
  • 1
    The answer to https://stackoverflow.com/questions/26672414/inotify-add-watch-fails-on-sys-class-net-eth0-operstate claims that `inotify` won't work with `/sys` files - but it's 6 years old, so the answer may have changed. However, polling maybe twice per second will put no significant load on the system, and the latency would hardly be noticeable. – jasonharper Sep 10 '20 at 18:17
  • Thanks - yes, I tried inotify, but it is not working with /sys/module/uvcvideo/refcnt – Alex Sep 11 '20 at 08:49

1 Answers1

0

Based on jasonharpers answer I implemented it as a daemon that uses polling

https://github.com/amenk/OnAirDaemon

Alex
  • 32,506
  • 16
  • 106
  • 171