added scripts folder to gitea
This commit is contained in:
Binary file not shown.
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
curl -v -u lucka:h0gC3PMwSCXjJH8L "http://wattbox.mario/control.cgi?outlet=1&command=0"
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
curl -v -u lucka:h0gC3PMwSCXjJH8L "http://wattbox.mario/control.cgi?outlet=1&command=1"
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
sudo wakeUltrawide.sh
|
||||
curl -v -u lucka:h0gC3PMwSCXjJH8L "http://wattbox.mario/control.cgi?outlet=2&command=0"
|
||||
curl -v -u lucka:h0gC3PMwSCXjJH8L "http://wattbox.mario/control.cgi?outlet=3&command=0"
|
||||
sudo wakeUltrawide.sh
|
||||
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
curl -v -u lucka:h0gC3PMwSCXjJH8L "http://wattbox.mario/control.cgi?outlet=2&command=1"
|
||||
curl -v -u lucka:h0gC3PMwSCXjJH8L "http://wattbox.mario/control.cgi?outlet=3&command=1"
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
cd ~/sh/rmctrl
|
||||
./smartplug.sh hs100-wega.mario $1
|
||||
Executable
+157
@@ -0,0 +1,157 @@
|
||||
#!/bin/bash
|
||||
##
|
||||
# Controls TP-LINK HS100,HS110, HS200 wlan smart plugs
|
||||
# Tested with HS100 firmware 1.0.8
|
||||
#
|
||||
# Credits to Thomas Baust for the query/status/emeter commands
|
||||
#
|
||||
# Author George Georgovassilis, https://github.com/ggeorgovassilis/linuxscripts
|
||||
|
||||
echo args are $@
|
||||
ip=$1
|
||||
port=$2
|
||||
cmd=$3
|
||||
|
||||
# encoded (the reverse of decode) commands to send to the plug
|
||||
|
||||
# encoded {"system":{"set_relay_state":{"state":1}}}
|
||||
payload_on="AAAAKtDygfiL/5r31e+UtsWg1Iv5nPCR6LfEsNGlwOLYo4HyhueT9tTu36Lfog=="
|
||||
|
||||
# encoded {"system":{"set_relay_state":{"state":0}}}
|
||||
payload_off="AAAAKtDygfiL/5r31e+UtsWg1Iv5nPCR6LfEsNGlwOLYo4HyhueT9tTu3qPeow=="
|
||||
|
||||
# encoded { "system":{ "get_sysinfo":null } }
|
||||
payload_query="AAAAI9Dw0qHYq9+61/XPtJS20bTAn+yV5o/hh+jK8J7rh+vLtpbr"
|
||||
|
||||
# the encoded request { "emeter":{ "get_realtime":null } }
|
||||
payload_emeter="AAAAJNDw0rfav8uu3P7Ev5+92r/LlOaD4o76k/6buYPtmPSYuMXlmA=="
|
||||
|
||||
# tools
|
||||
|
||||
check_dependencies() {
|
||||
command -v nc >/dev/null 2>&1 || { echo >&2 "The nc programme for sending data over the network isn't in the path, communication with the plug will fail"; exit 2; }
|
||||
command -v base64 >/dev/null 2>&1 || { echo >&2 "The base64 programme for decoding base64 encoded strings isn't in the path, decoding of payloads will fail"; exit 2; }
|
||||
command -v od >/dev/null 2>&1 || { echo >&2 "The od programme for converting binary data to numbers isn't in the path, the status and emeter commands will fail";}
|
||||
command -v read >/dev/null 2>&1 || { echo >&2 "The read programme for splitting text into tokens isn't in the path, the status and emeter commands will fail";}
|
||||
command -v printf >/dev/null 2>&1 || { echo >&2 "The printf programme for converting numbers into binary isn't in the path, the status and emeter commands will fail";}
|
||||
}
|
||||
|
||||
show_usage() {
|
||||
echo Usage: $0 IP PORT COMMAND
|
||||
echo where COMMAND is one of on/off/check/status/emeter/toggle
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
check_arguments() {
|
||||
check_arg() {
|
||||
name="$1"
|
||||
value="$2"
|
||||
if [ -z "$value" ]; then
|
||||
echo "missing argument $name"
|
||||
show_usage
|
||||
fi
|
||||
}
|
||||
check_arg "ip" $ip
|
||||
check_arg "port" $port
|
||||
check_arg "command" $cmd
|
||||
}
|
||||
|
||||
send_to_plug() {
|
||||
ip="$1"
|
||||
port="$2"
|
||||
payload="$3"
|
||||
echo -n "$payload" | base64 --decode | nc -v $ip $port || echo couldn''t connect to $ip:$port, nc failed with exit code $?
|
||||
}
|
||||
|
||||
decode(){
|
||||
code=171
|
||||
offset=4
|
||||
input_num=`od -j $offset -An -t u1 -v | tr "\n" " "`
|
||||
IFS=' ' read -r -a array <<< "$input_num"
|
||||
args_for_printf=""
|
||||
for element in "${array[@]}"
|
||||
do
|
||||
output=$(( $element ^ $code ))
|
||||
args_for_printf="$args_for_printf\x$(printf %x $output)"
|
||||
code=$element
|
||||
done
|
||||
printf "$args_for_printf"
|
||||
}
|
||||
|
||||
query_plug(){
|
||||
payload=$1
|
||||
send_to_plug $ip $port "$payload" | decode
|
||||
}
|
||||
|
||||
# plug commands
|
||||
|
||||
cmd_print_plug_relay_state(){
|
||||
output=`send_to_plug $ip $port "$payload_query" | decode | egrep -oa 'relay_state":[0,1]' | egrep -o '[0,1]'`
|
||||
if [[ $output -eq 0 ]]; then
|
||||
echo OFF
|
||||
elif [[ $output -eq 1 ]]; then
|
||||
echo ON
|
||||
else
|
||||
echo Couldn''t understand plug response $output
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_print_plug_status(){
|
||||
query_plug "$payload_query"
|
||||
}
|
||||
|
||||
cmd_print_plug_consumption(){
|
||||
query_plug "$payload_emeter"
|
||||
}
|
||||
|
||||
cmd_switch_on(){
|
||||
send_to_plug $ip $port $payload_on > /dev/null
|
||||
}
|
||||
|
||||
cmd_switch_off(){
|
||||
send_to_plug $ip $port $payload_off > /dev/null
|
||||
}
|
||||
|
||||
cmd_switch_toggle() {
|
||||
output=`cmd_print_plug_relay_state`
|
||||
if [[ $output == OFF ]]; then
|
||||
cmd_switch_on
|
||||
elif [[ $output == ON ]]; then
|
||||
cmd_switch_off
|
||||
else
|
||||
echo $output
|
||||
fi
|
||||
}
|
||||
|
||||
##
|
||||
# Main programme
|
||||
##
|
||||
|
||||
|
||||
check_dependencies
|
||||
check_arguments
|
||||
|
||||
case "$cmd" in
|
||||
on)
|
||||
cmd_switch_on
|
||||
;;
|
||||
off)
|
||||
cmd_switch_off
|
||||
;;
|
||||
toggle)
|
||||
cmd_switch_toggle
|
||||
;;
|
||||
check)
|
||||
cmd_print_plug_relay_state
|
||||
;;
|
||||
status)
|
||||
cmd_print_plug_status
|
||||
;;
|
||||
emeter)
|
||||
cmd_print_plug_consumption
|
||||
;;
|
||||
*)
|
||||
show_usage
|
||||
;;
|
||||
esac
|
||||
Executable
+184
@@ -0,0 +1,184 @@
|
||||
# Released by rdb under the Unlicense (unlicense.org)
|
||||
# Based on information from:
|
||||
# https://www.kernel.org/doc/Documentation/input/joystick-api.txt
|
||||
|
||||
import os, struct, array, sys
|
||||
from fcntl import ioctl
|
||||
|
||||
# Iterate over the joystick devices.
|
||||
print('Available devices:')
|
||||
|
||||
for fn in os.listdir('/dev/input'):
|
||||
if fn.startswith('js'):
|
||||
print(' /dev/input/%s' % (fn))
|
||||
|
||||
# We'll store the states here.
|
||||
axis_states = {}
|
||||
button_states = {}
|
||||
|
||||
# These constants were borrowed from linux/input.h
|
||||
axis_names = {
|
||||
0x00 : 'x',
|
||||
0x01 : 'y',
|
||||
0x02 : 'z',
|
||||
0x03 : 'rx',
|
||||
0x04 : 'ry',
|
||||
0x05 : 'rz',
|
||||
0x06 : 'throttle',
|
||||
0x07 : 'rudder',
|
||||
0x08 : 'wheel',
|
||||
0x09 : 'gas',
|
||||
0x0a : 'brake',
|
||||
0x10 : 'hat0x',
|
||||
0x11 : 'hat0y',
|
||||
0x12 : 'hat1x',
|
||||
0x13 : 'hat1y',
|
||||
0x14 : 'hat2x',
|
||||
0x15 : 'hat2y',
|
||||
0x16 : 'hat3x',
|
||||
0x17 : 'hat3y',
|
||||
0x18 : 'pressure',
|
||||
0x19 : 'distance',
|
||||
0x1a : 'tilt_x',
|
||||
0x1b : 'tilt_y',
|
||||
0x1c : 'tool_width',
|
||||
0x20 : 'volume',
|
||||
0x28 : 'misc',
|
||||
}
|
||||
|
||||
button_names = {
|
||||
0x120 : 'trigger',
|
||||
0x121 : 'thumb',
|
||||
0x122 : 'thumb2',
|
||||
0x123 : 'top',
|
||||
0x124 : 'top2',
|
||||
0x125 : 'pinkie',
|
||||
0x126 : 'base',
|
||||
0x127 : 'base2',
|
||||
0x128 : 'base3',
|
||||
0x129 : 'base4',
|
||||
0x12a : 'base5',
|
||||
0x12b : 'base6',
|
||||
0x12f : 'dead',
|
||||
0x130 : 'a',
|
||||
0x131 : 'b',
|
||||
0x132 : 'c',
|
||||
0x133 : 'x',
|
||||
0x134 : 'y',
|
||||
0x135 : 'z',
|
||||
0x136 : 'tl',
|
||||
0x137 : 'tr',
|
||||
0x138 : 'tl2',
|
||||
0x139 : 'tr2',
|
||||
0x13a : 'select',
|
||||
0x13b : 'start',
|
||||
0x13c : 'mode',
|
||||
0x13d : 'thumbl',
|
||||
0x13e : 'thumbr',
|
||||
|
||||
0x220 : 'dpad_up',
|
||||
0x221 : 'dpad_down',
|
||||
0x222 : 'dpad_left',
|
||||
0x223 : 'dpad_right',
|
||||
|
||||
# XBox 360 controller uses these codes.
|
||||
0x2c0 : 'dpad_left',
|
||||
0x2c1 : 'dpad_right',
|
||||
0x2c2 : 'dpad_up',
|
||||
0x2c3 : 'dpad_down',
|
||||
}
|
||||
|
||||
axis_map = []
|
||||
button_map = []
|
||||
|
||||
# Open the joystick device.
|
||||
fn = f'/dev/input/{sys.argv[1]}'
|
||||
print('Opening %s...' % fn)
|
||||
jsdev = open(fn, 'rb')
|
||||
|
||||
# Get the device name.
|
||||
#buf = bytearray(63)
|
||||
buf = array.array('B', [0] * 64)
|
||||
ioctl(jsdev, 0x80006a13 + (0x10000 * len(buf)), buf) # JSIOCGNAME(len)
|
||||
js_name = buf.tobytes().rstrip(b'\x00').decode('utf-8')
|
||||
print('Device name: %s' % js_name)
|
||||
|
||||
# Get number of axes and buttons.
|
||||
buf = array.array('B', [0])
|
||||
ioctl(jsdev, 0x80016a11, buf) # JSIOCGAXES
|
||||
num_axes = buf[0]
|
||||
|
||||
buf = array.array('B', [0])
|
||||
ioctl(jsdev, 0x80016a12, buf) # JSIOCGBUTTONS
|
||||
num_buttons = buf[0]
|
||||
|
||||
# Get the axis map.
|
||||
buf = array.array('B', [0] * 0x40)
|
||||
ioctl(jsdev, 0x80406a32, buf) # JSIOCGAXMAP
|
||||
|
||||
for axis in buf[:num_axes]:
|
||||
axis_name = axis_names.get(axis, 'unknown(0x%02x)' % axis)
|
||||
axis_map.append(axis_name)
|
||||
axis_states[axis_name] = 0.0
|
||||
|
||||
# Get the button map.
|
||||
buf = array.array('H', [0] * 200)
|
||||
ioctl(jsdev, 0x80406a34, buf) # JSIOCGBTNMAP
|
||||
|
||||
for btn in buf[:num_buttons]:
|
||||
btn_name = button_names.get(btn, 'unknown(0x%03x)' % btn)
|
||||
button_map.append(btn_name)
|
||||
button_states[btn_name] = 0
|
||||
|
||||
print('%d axes found: %s' % (num_axes, ', '.join(axis_map)))
|
||||
print('%d buttons found: %s' % (num_buttons, ', '.join(button_map)))
|
||||
|
||||
# Main event loop
|
||||
while True:
|
||||
evbuf = jsdev.read(8)
|
||||
if evbuf:
|
||||
time, value, type, number = struct.unpack('IhBB', evbuf)
|
||||
|
||||
if type & 0x80:
|
||||
print("(initial)", end="")
|
||||
|
||||
if type & 0x01:
|
||||
button = button_map[number]
|
||||
if button:
|
||||
button_states[button] = value
|
||||
if value:
|
||||
print("%s pressed" % (button))
|
||||
|
||||
else:
|
||||
print("%s released" % (button))
|
||||
|
||||
if type & 0x02:
|
||||
axis = axis_map[number]
|
||||
if axis:
|
||||
fvalue = value / 32767.0
|
||||
axis_states[axis] = fvalue
|
||||
#print("%s: %.3f" % (axis, fvalue))
|
||||
print(axis, fvalue)
|
||||
|
||||
#IF STATEMENTS FOR DPAD
|
||||
|
||||
if axis == 'hat0y' and fvalue == 1.0: # DPAD DOWN
|
||||
os.system('echo dpad up')
|
||||
if axis == 'hat0y' and fvalue == -1.0: # DPAD UP
|
||||
os.system('echo dpad up')
|
||||
|
||||
#IF STATEMENTS FOR C BUTTONS
|
||||
|
||||
if axis == 'rz' and fvalue == 0.8453627124851222: # C LEFT
|
||||
#os.system('~/rmctrl/smartplug.sh hs100-lights.mario off')
|
||||
os.system('~/rmctrl/commands/lightoff &')
|
||||
if axis == 'rz' and fvalue == -0.8247932370983001: # C RIGHT
|
||||
#os.system('~/rmctrl/smartplug.sh hs100-lights.mario on')
|
||||
os.system('~/rmctrl/commands/lighton &')
|
||||
if axis == 'z' and fvalue == 0.8453627124851222: # C DOWN
|
||||
#os.system('~/rmctrl/smartplug.sh hs100-monitors.mario off')
|
||||
os.system('~/rmctrl/commands/monitoroff &')
|
||||
os.system('ssh -i ~/.ssh/screenoff-key/screenoff lucka@x201t.mario &')
|
||||
if axis == 'z' and fvalue == -0.8247932370983001: # C UP
|
||||
#os.system('~/rmctrl/smartplug.sh hs100-monitors.mario on')
|
||||
os.system('~/rmctrl/commands/monitoron &')
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
session_name: 3-pane-split
|
||||
windows:
|
||||
- window_name: dev window
|
||||
layout: tiled
|
||||
shell_command_before:
|
||||
- cd ~/rmctrl # run as a first command in all panes
|
||||
panes:
|
||||
- while true; do python3 inputtest.py js0; done # pane no. 1
|
||||
- while true; do python3 inputtest.py js1; done # pane no. 2
|
||||
- ./keepalive.sh # pane no. 3
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
while true
|
||||
do
|
||||
./smartplug.sh hs100-lights.mario check
|
||||
./smartplug.sh hs100-monitors.mario check
|
||||
sleep 2m
|
||||
done
|
||||
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
cd /home/lucka/sh/rmctrl
|
||||
./hs100.sh $1 9999 $2 &
|
||||
Reference in New Issue
Block a user