imWACCo
Posts: 9
Joined: Sun May 13, 2018 7:46 pm

WoL and remote shutdown

Fri Nov 15, 2019 5:19 pm

I have a project that I'm working on: SmartHome but for a car, or called a CarPuter.

The first thing I need is a master on/off Pi.

On boot, send WoL signals to the networked systems (3 to 5 systems). Before shut down, send kill signals* to the systems.

Hardware on hand: Every Pi except 4 (want to use Zero W), Raspberry Pi Automatic ON/OFF V2.1, 4 or 5 different NUC, low power DD-WRT router, and lots of spare time.








* ssh -t [email protected]_ADDRESS 'sudo shutdown -h 0' or shutdown -s -f -m \\"IP of remote machine" -t xx ??? I've never tried this before.

hippy
Posts: 6299
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: WoL and remote shutdown

Fri Nov 15, 2019 7:51 pm

You can easily send WoL packets from a Pi to wake-up any PC which has WoL enabled but you will likely need some sort of server running on each of those to allow the Pi to send 'Power Down over LAN' commands.

I'd probably do it by using my own variant of the WoL packet to force Power Down but any means will work as long as something can send it, and what is meant to receive it gets it.

imWACCo
Posts: 9
Joined: Sun May 13, 2018 7:46 pm

Re: WoL and remote shutdown

Sat Nov 16, 2019 6:45 pm

hippy wrote:
Fri Nov 15, 2019 7:51 pm
... some sort of server running ... can send it, and what is meant to receive it gets it.
Ok, do you have anything that has worked for you?

This can't be the first time that someone has tried this. Desk jockeys leaving there systems running, Admin goes thru a few months of SSH into each system to turn off... "There's a script for that!"

hippy
Posts: 6299
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: WoL and remote shutdown

Sat Nov 16, 2019 8:06 pm

On my Pi I have a simple Python 2 HTTP server running in the background, so all I need to do is specify "http://192.168.0.100:8089/shutdown", from a browser or 'wget' etc, and down it goes. You might want to add a little more security ...

Code: Select all

#!/usr/bin/python2

import BaseHTTPServer
import os

class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def do_GET(self):
    self.send_response(200)
    self.send_header("Content-type", "text/html")
    self.end_headers()
    if self.path == "/shutdown":
      self.wfile.write("Shutting Down")
      os.popen("sudo shutdown -h now")
    else:
      self.wfile.write("Ignored")

BaseHTTPServer.HTTPServer(("", 8089), HttpHandler).serve_forever()

FunBundle
Posts: 1
Joined: Thu Nov 28, 2019 8:58 am

Re: WoL and remote shutdown

Thu Nov 28, 2019 9:31 am

I have similar projects.

One simple project I want to try is to auto shutdown the raspberry pi when I leave my house and then restart it when I come home again. No real need to but would like to see if this can work!

For this exercise I have a raspberry pi being used as a tv streamer. No point having it on If I'm out, right?

The first part is to use some mechanism to shut down the raspberry pi - use the above script?

Second I put the raspberry pi power supply on a smart switch.

Third I have a Synology NAS which is always on, wherever I am to be the 'brains' of this exercise.

Now for the interesting bit.

For my trigger (I've gone out, I've come back) I'll use my Tado smart heating geo-fencing function. I use IFTTT rules that Tado can trigger to send the releveant signal to my NAS.

On the I've gone out signal script on the NAS (PHP web page, possibly?) sends a signal to the pi to run the shut down script and, after a period of time to allow the shutdown script to work trigger another IFTTT signal to tell the smart switch to turn off.

On the I've come home signal the IFTTT signal is sent to the smart switch to turn on thus rebooting the Raspberry Pi! Nice, huh?

This is probably a silly example but does raise a rather interesting appraoch to using say Alexa or some other trigger to control a raspberry pi.

What are your thoughts and be gentle with your criticisms!

hippy
Posts: 6299
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: WoL and remote shutdown

Thu Nov 28, 2019 12:29 pm

FunBundle wrote:
Thu Nov 28, 2019 9:31 am
This is probably a silly example but does raise a rather interesting appraoch to using say Alexa or some other trigger to control a raspberry pi.

What are your thoughts and be gentle with your criticisms!
Sounds a great idea to me. I like the idea of using geo-fencing you already have to detect occupancy, arrival and departure. The only issue would be when not living alone where you might need something which can keep track of who's in and who's out.

Not having such wizardry myself a burglar alarm PIR provides occupied signalling for me and some 'not really AI' processing to determine when occupancy has ceased.

As long as you have the triggers and a processor to determine what to do with those triggers the possibilities are endless.

If you worry your system is silly; mine says "Good Morning" when I've got up, occasionally "Happy Birthday" and "Merry Christmas", and reminds me which bins need putting out that evening.

Before the advent of TiVo, PVR's and series links, it used to tell me what it thought I might like to watch on TV that evening. One day I'll move that from the Windows 98 PC it's been running on for years to a Pi Zero W.

imWACCo
Posts: 9
Joined: Sun May 13, 2018 7:46 pm

Re: WoL and remote shutdown

Fri Nov 29, 2019 4:27 am

One of the things that I found out the other day, R-Pi will not do WoL/magic package.

I guess I'll have to do some sort of 5v Power Over LAN, with a solid state switch of some type hooked to the master Pi

hippy
Posts: 6299
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: WoL and remote shutdown

Fri Nov 29, 2019 11:19 am

imWACCo wrote:
Fri Nov 29, 2019 4:27 am
One of the things that I found out the other day, R-Pi will not do WoL/magic package.
That is correct. A Pi can send WoL packets to other computers to wake them up, but does not include any on-board hardware which allows itself to be woken on receipt of a WoL packet. That functionality has to be provided externally.
imWACCo wrote:
Fri Nov 29, 2019 4:27 am
I guess I'll have to do some sort of 5v Power Over LAN, with a solid state switch of some type hooked to the master Pi
You can use a SmartSwitch as FunBundle suggested.

The Pi 3A+, 3B+ and 4B all have the ability to be put into low power mode by an external interface so it should be fairly easy to design external WoL hardware for a Pi. An additional Pi, even the Zero W, can be used to to provide WoL capability for other Pi's but that makes more sense when it is controlling a number of Pi's rather than just one.

Return to “Other projects”