-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoctoprint-remote.sh
executable file
·81 lines (75 loc) · 1.8 KB
/
octoprint-remote.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# by Andre Ruiz <andre.ruiz@gmail.com> 2018
# You may redistribute and do whatever you want, just give credits.
# DANGER WILL ROBINSON
# this is a hack. you have been warned. don't complain about programming best practices
# please, fix it instead. thanks.
host="tp002.lab.token:80"
. ~/.octoprint.apikey # youu should put your key here, one line, apikey="blabla"
api_call() {
local "$@"
url="http://${host}/api"
curlcmd="curl -o - -H 'X-Api-Key: ${apikey}'"
[ -n "$json" ] && \
curlcmd="$curlcmd -X POST -d '$json' -H 'Content-Type: application/json'"
curlcmd="$curlcmd '$url/$resource'"
#echo -en "\n>>> COMMAND LINE: $curlcmd\n\n"
eval $curlcmd
}
case "$1" in
"--connection")
api_call \
resource="connection"
;;
"--move-x")
api_call \
resource="printer/printhead" \
json='{ "command": "jog", "x": '$2' }'
;;
"--move-y")
api_call \
resource="printer/printhead" \
json='{ "command": "jog", "y": '$2' }'
;;
"--move-z")
api_call \
resource="printer/printhead" \
json='{ "command": "jog", "z": '$2' }'
;;
"--home")
api_call \
resource="printer/printhead" \
json='{ "command": "home", "axes": [ "x", "y", "z" ] }'
;;
"--extrude")
amount=$2
api_call \
resource="printer/tool" \
json='{ "command": "extrude", "amount": '$amount' }'
;;
"--get-hotend-temp")
api_call \
resource="printer/tool" \
;;
"--set-hotend-temp")
api_call \
resource="printer/tool" \
json='{ "command": "target", "targets": { "tool0": '$2' } }'
;;
"--get-bed-temp")
api_call \
resource="printer/bed" \
;;
"--set-bed-temp")
api_call \
resource="printer/bed" \
json='{ "command": "target", "target": '$2' }'
;;
"--command")
api_call \
resource="printer/command" \
json='{ "command": "'"$2"'" }'
;;
*)
echo "ERROR: invalid option."
esac