Hibernate computers with a POST request
This app uses two cloud functions:
-
setHibernateFlag
Save the current time to the Cloud Firestore database for a given computer ID. -
readHibernateFlag
Returntrue
if the database time for a given computer ID is within the last 5 minutes,false
otherwise.
The PC can fetch the readHibernateFlag
function every 1 minute, and hibernate if it returns true
.
Version 2.0.0 supports multiple computers that can be independently controlled. It uses Cloud Functions and Cloud Firestore directly rather than being set up through the Firebase platform.
Version 1.0.0 supports a single computer and uses Cloud Functions and Cloud Firestore through the Firebase platform.
-
Create an auth token and set it in
config.json
(seeconfig_sample.json
for reference). -
Deploy the cloud functions:
npm install npm run deploy
Set up a scheduled task to fetch the flag every 1 minute, and send the hibernate command if it returns true
Powershell example:
$Params = @{
Method = "Post"
Uri = "https://YOUR_REGION-YOUR_PROJECT_ID.cloudfunctions.net/readHibernateFlag"
Body = "computerId=computer1"
ContentType = "application/x-www-form-urlencoded"
}
$r = Invoke-RestMethod @Params
if ($r -eq 'true') {
shutdown.exe /h
}
curl -X POST "https://YOUR_REGION-YOUR_PROJECT_ID.cloudfunctions.net/setHibernateFlag" -H "Content-Type:application/json" --data '{"token":"YOUR_TOKEN", "computerId":"computer1"}'