0

This question was asked twice, my apologies. The solution was supplied by Ingo here:

How to make Raspian Buster shutdown when I unplug the ethernet cable

I would like to configure my RPI4 to perform an orderly shutdown if the Ethernet state becomes disconnected.

I would also like it to boot back on if the state becomes connected before power is cut from the device.

It would of course come back on its own when power is restored.

Is this possible?

To give some background, the RPI is being used to record video from several IP cameras on my motorcycle and store them on a USB 256gig M.2 drive. This is also the boot device.

The plan is as follows:

The system is powered by two timed relays, a 10 min and a 5 min relay. When the motorcycle is shut off the relays keep the system powered on at full recording video for 5 min, then the first relay shuts off killing the cameras and the network hub. This is when the RPI would detect the state change of the ETH port and perform an orderly shutdown. 5 min after this the second relay shuts everything off to achieve a fully non powered state.

When I fire the bike back up, everything gets power and the RPI boots up.

IF however I come back to the bike and start it up while its in the second 5 min state, where the RPI has shut down but is still powered on I would like the system to see the change in state of the ETH as coming back and boot up the RPI. This is important as without this part of the code there is a chance the RPI will just sit there in a shutdown but powered on state doing nothing.

I am not a programmer so this is a bit beyond my skills, I am hoping some kind soul can assist.

Thank you

1
1

Rather than trying to develop some esoteric script you can safely shutdown the Pi with a button (or relay contact) with dtoverlay=gpio-shutdown. You already seem to have a timer to do this.

NO code required!

See https://raspberrypi.stackexchange.com/a/77918/8697

You could write some code to detect Ethernet state and call sudo poweroff but you are unlikely to find anyone who has done this, and it is unlikely to be reliable.

1
  • I have found previous posts on how to do it with old versions of raspian like wheezy but the instructions do not translate over to buster due to the changes in networking.
    – JustSumDad
    Dec 19 '20 at 17:03
0

Pi 4 doesn't currently support wake on LAN, so the startup part will not be possible.

You can still do the shutdown part and make sure there is an electrical signal which will wake up the Pi when necessary. You then assert this signals at the same time as the network.

1
  • yes I suspect that the startup would not be possible, I will have to adjust the delay time to be as close as possible to the shutdown so as to minimize the chances of a failed startup.
    – JustSumDad
    Dec 21 '20 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.