1
0
mirror of https://github.com/balkian/gists.git synced 2024-11-01 08:01:44 +00:00
gists/repos/f375e47338f554523e6380954cba0d87/octo.sh

33 lines
982 B
Bash
Raw Normal View History

2016-12-27 23:08:35 +00:00
#!/bin/bash
2016-12-28 01:36:51 +00:00
echo $(date) - "$@" >> /tmp/octo-log
2016-12-28 00:14:36 +00:00
CONF_FILE=$HOME/.octo.conf
if [ ! -f "$CONF_FILE" ];
2016-12-27 23:08:35 +00:00
then
2016-12-28 00:14:36 +00:00
echo OCTO_API_KEY=$(OctoPrint/venv/bin/octoprint config get api.key | tr -d "'") > $CONF_FILE
echo OCTO_PORT=$(OctoPrint/venv/bin/octoprint config get server.port | tr -d "'") >> $CONF_FILE
echo OCTO_HOST=$(OctoPrint/venv/bin/octoprint config get server.host | tr -d "'") >> $CONF_FILE
2016-12-27 23:08:35 +00:00
echo 'Retrieved API key'
fi
2016-12-28 00:14:36 +00:00
source $CONF_FILE
2016-12-27 23:08:35 +00:00
function send_octo() {
2016-12-28 00:14:36 +00:00
curl -H "X-Api-Key: $OCTO_API_KEY" -H 'Content-Type: application/json' --data "$1" http://$OCTO_HOST:$OCTO_PORT/api/printer/printhead
2016-12-27 23:08:35 +00:00
}
case $1 in
move)
shift
x=$1
y=$2
z=$3
echo $1 $2 $3
send_octo '{"command": "jog","x": '$x',"y": '$y',"z": '$z'}' http://localhost:5000/api/printer/printhead
sleep 2
;;
home)
send_octo '{ "command": "home", "axes": ["x", "y", "z"] }'
2016-12-28 01:36:51 +00:00
;;
nothing)
echo "nothing $(date)" >> /tmp/prueba
;;
2016-12-27 23:08:35 +00:00
esac