is it somehow possible to check whether the UI is open client side? I want to start resp. stop a script with this info.
Detect if pimatic UI is opened on a client
Seems that this is not possible right?
Nothing is impossible
You could also do this periodically if you want to know if the page is still open.
The question in general would be what is the actual use case…
Okay. I had the hope that there could be used a already existing mechanism.
My idea behind this was to start a service only then, when it is necessary, means when the UI is opened to save system resources.
One possibility would be to query the number of open http(s) connections on the server.
However, as far as I know this would also include connection for API calls. So maybe we can simply add an API-call to query the number of connections and you can define a suitable connection threshold to decide about when the script should be started (and terminated
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
The question to me still is what kind of service? why does it use so much resources, why can’t it run continiously?
It is the motioneye service which provides me a live view of my h.264 Foscam IP cameras for the iframe. After starting the service the cpu load it is really increasing. I want to stop it if nobody is logged in. Currently I start or stop the service by my pimatic detected home presence. When I’m not at home, I don’t need the live view picture of my cameras.
But I think this function could be interesting as well for other things.
@ortin using a button is not an option?
sudo netstat -anp | grep :80 | grep ESTABLISHED | wc -l
to detect if anyone(i dont mind how many) is connected. Not the best way though, like @mwittig mentioned… But in my case, it almost always displays 0 when not opened, and 6 or 7 when opened.
You could also look as to how high it gets when you dont have it open(in my case it is 6) and when i open it it becomes 7, and then do something.
To get the right number you can monitor it.
sudo watch -n 1 "netstat -anp | grep :80 | grep ESTABLISHED | wc -l"
The button itself isnt that what I like to have, but the command could help to make the magic happen. Thx for this!