Shutdown Pi Zero W on client disconnect.

Hi!

I'm in a process of building myself a wireless version of X52 Pro H.O.T.A.S. As it's going to be a single relatively low bandwidth USB device going only over the local network I landed on using Raspberry Pi Zero W for the server side with CloudHub firmware installed and my initial testing is very positive. I ordered myself new fresh Pi Zero W and a UPS hat with built in charging circuity for a LiPo cell I have lying around and I hope to fit it all inside the throttle housing. So I'm looking for a way to gracefully shutdown the Pi once I'm finished using it.

Since it's going to be used by a single client after reading the documentation I figured that onClientDisconnect should do the trick. But because I only want it to shutdown on a graceful disconnection I came out with this:

onClientDisconnect=/root/shutdown_if.sh "$REASON$"

and I can check for the reason in my shutdown_if.sh batch. But since I don't yet have a license (still waiting for my final hardware) I can't test it so I was wondering if there is a list of possible values for $REASON$ so I can setup and manually test the script in the meantime.

Sorry for the long winded post.

#2

Yes the value in quotes is what will be sent

timeout or server shutdown

Also im not sure the pi0w can actually be physically powered off - without removing the power supply. I assume you have a GPIO or something that can do that?

#3

So no 'reason' value for graceful disconnect of the client? :( I know that its visible in logs.

The UPS HAT I ordered (DFRobot DFR0528) should cut off 5V supply once the load is too low (according to information on their forums) and once you call poweroff on the Pi Zero W it basically goes down to 0 (I've tested it with my power bank and the power bank will cut off its 5V output once Pi is shutdown). If that fails you can turn 5V supply to the PI on and off manually by holding the button on the HAT. So powering on and off shouldn't be a problem - the only issue I have is that I would like to shutdown the Pi once I'm done using the setup.

#4

Graceful disconnect is timeout

Thats interesting about that HAT, it could be quite useful.

#5

I was hoping to distinguish between timeout and graceful but I can live without this distinction. Thanks.

If you want I can post my results here once I get the hardware and do some testing.

#6

Actually all graceful disconnects do timeout