Initial commit
commit
9bedcf58c5
|
@ -0,0 +1,44 @@
|
|||
Installation
|
||||
============
|
||||
|
||||
1. Install curl and jq.
|
||||
2. Go to http://iot.waw.hackerspace.pl, login with "Trusted Network", then go
|
||||
to "admin" (in lower left), scroll to the very bottom and in the section
|
||||
"Long-Lived Access Tokens" click "Create token". Go through token creation
|
||||
flow and copy thit token to TOKEN= in `fan` script.
|
||||
3. Copy (or symlink) everything apart from this README to /usr/local/bin or any
|
||||
directory in $PATH
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
fan [query]
|
||||
fan-query
|
||||
Check fan status. Will output "on" or "off".
|
||||
|
||||
fan on
|
||||
fan-on
|
||||
fan off
|
||||
fan-off
|
||||
Toggle fan
|
||||
|
||||
laser [query]
|
||||
laser-query
|
||||
Check who uses the laser. Will not output anything if laser is not taken.
|
||||
|
||||
laser take [<username>]
|
||||
laser-take [<username>]
|
||||
Take the laser for 60 min. Works if no-one else uses laser. If you don't
|
||||
specify username, will use $USER environment variable.
|
||||
|
||||
laser release
|
||||
laser-release
|
||||
Release the laser from usage. Works only if taken by you.
|
||||
|
||||
laser force
|
||||
laser-force
|
||||
Force release the laser. Works whether you took the laser or someone else.
|
||||
This is for use only if you took the laser, then disconnected and got
|
||||
another IP address from DHCP.
|
||||
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
TOKEN=...
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 {on|off}" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
api() {
|
||||
endpoint=$1
|
||||
shift
|
||||
curl -s http://iot.waw.hackerspace.pl/api"$endpoint" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
"$@"
|
||||
}
|
||||
|
||||
on() { api /services/fan/turn_on -d '{"entity_id": "fan.exhaust"}'; }
|
||||
off() { api /services/fan/turn_off -d '{"entity_id": "fan.exhaust"}'; }
|
||||
query() { api /states/fan.exhaust | jq -r .state; }
|
||||
api_test() { api /; }
|
||||
|
||||
if test $# -eq 0
|
||||
then
|
||||
case "$0" in
|
||||
*-on) on;;
|
||||
*-off) off;;
|
||||
*) query;;
|
||||
esac
|
||||
elif test $# -eq 1
|
||||
then
|
||||
case "$1" in
|
||||
on|off|query) "$1";;
|
||||
test) api_test;;
|
||||
*) usage;;
|
||||
esac
|
||||
else
|
||||
usage
|
||||
fi
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# SPDX-FileCopyrightText: 2023 Wojtek Porczyk <woju@hackerspace.pl>
|
||||
|
||||
set -e
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 {take [user]|release|force}" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
api() {
|
||||
endpoint=$1
|
||||
shift
|
||||
curl -s -X POST http://laser.waw.hackerspace.pl"$endpoint" "$@"
|
||||
}
|
||||
|
||||
take() { api /take -d "who=$1"; }
|
||||
release() { api /release; }
|
||||
force() { api /force; }
|
||||
query() {
|
||||
api / \
|
||||
| sed -ne "s:^.*\(Currently in use .*\)$:\1:p"
|
||||
}
|
||||
|
||||
if test $# -eq 0
|
||||
then
|
||||
case "$0" in
|
||||
*-take) take "$USER";;
|
||||
*-release) release;;
|
||||
*-force) force;;
|
||||
*-query) query;;
|
||||
*) query;;
|
||||
esac
|
||||
elif test $# -eq 1
|
||||
then
|
||||
case "$1" in
|
||||
take) take "$USER";;
|
||||
force|release|query) "$1";;
|
||||
*) usage;;
|
||||
esac
|
||||
elif test $# -eq 2 -a "$1" = take
|
||||
then
|
||||
"$1" "$2"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
|
||||
# vim: tw=80
|
|
@ -0,0 +1 @@
|
|||
laser
|
|
@ -0,0 +1 @@
|
|||
laser
|
|
@ -0,0 +1 @@
|
|||
laser
|
|
@ -0,0 +1 @@
|
|||
laser
|
Loading…
Reference in New Issue