From bb2abfdb1c549394bc69675d7273eabdc98a93ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Wed, 28 Dec 2016 00:08:35 +0100 Subject: [PATCH 1/3] --- octo.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 octo.sh diff --git a/octo.sh b/octo.sh new file mode 100644 index 0000000..80d34e4 --- /dev/null +++ b/octo.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Starting Octoprint's CLI takes **very long**. +# So long that it's useless for LIRC (remote) control. +# This script uses the CLI only once, to retrieve the API. +# It's a bit hacky, but it works for LIRC (infrared remote) +KEY_FILE=$HOME/.octokey +if [ ! -f "$KEY_FILE" ]; +then + OctoPrint/venv/bin/octoprint config get api.key | tr -d "'" > $KEY_FILE + echo 'Retrieved API key' +fi +OCTO_API_KEY=$(cat $KEY_FILE) + +function send_octo() { + curl -H "X-Api-Key: $OCTO_API_KEY" -H 'Content-Type: application/json' --data "$1" http://localhost:5000/api/printer/printhead +} + +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"] }' +;; +esac \ No newline at end of file From 9967ab2b24025a16345bd4ecffd8b96be4a816b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Wed, 28 Dec 2016 01:14:36 +0100 Subject: [PATCH 2/3] --- octo.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/octo.sh b/octo.sh index 80d34e4..b31c239 100644 --- a/octo.sh +++ b/octo.sh @@ -1,18 +1,16 @@ #!/bin/bash -# Starting Octoprint's CLI takes **very long**. -# So long that it's useless for LIRC (remote) control. -# This script uses the CLI only once, to retrieve the API. -# It's a bit hacky, but it works for LIRC (infrared remote) -KEY_FILE=$HOME/.octokey -if [ ! -f "$KEY_FILE" ]; +CONF_FILE=$HOME/.octo.conf +if [ ! -f "$CONF_FILE" ]; then - OctoPrint/venv/bin/octoprint config get api.key | tr -d "'" > $KEY_FILE + 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 echo 'Retrieved API key' fi -OCTO_API_KEY=$(cat $KEY_FILE) +source $CONF_FILE function send_octo() { - curl -H "X-Api-Key: $OCTO_API_KEY" -H 'Content-Type: application/json' --data "$1" http://localhost:5000/api/printer/printhead + curl -H "X-Api-Key: $OCTO_API_KEY" -H 'Content-Type: application/json' --data "$1" http://$OCTO_HOST:$OCTO_PORT/api/printer/printhead } case $1 in From 3755507158f0732094751682ffc9fdcfa7e3f61a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Wed, 28 Dec 2016 02:36:51 +0100 Subject: [PATCH 3/3] --- gistfile1.txt | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ octo.sh | 6 ++++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 gistfile1.txt diff --git a/gistfile1.txt b/gistfile1.txt new file mode 100644 index 0000000..168a4ce --- /dev/null +++ b/gistfile1.txt @@ -0,0 +1,63 @@ +begin + button = KEY_5 + prog = irexec + config = /home/balkian/octo.sh home + repeat = 0 + delay = 3 +end +begin + button = KEY_1 + prog = irexec + config = /home/balkian/octo.sh move -10 10 0 + repeat = 0 + delay = 3 +end +begin + button = KEY_2 + prog = irexec + config = /home/balkian/octo.sh move 0 10 0 + repeat = 0 + delay = 3 +end +begin + button = KEY_3 + prog = irexec + config = /home/balkian/octo.sh move 10 10 0 + repeat = 0 + delay = 3 +end +begin + button = KEY_4 + prog = irexec + config = /home/balkian/octo.sh move -10 0 0 + repeat = 0 + delay = 3 +end +begin + button = KEY_6 + prog = irexec + config = /home/balkian/octo.sh move 10 0 0 + repeat = 0 + delay = 3 +end +begin + button = KEY_7 + prog = irexec + config = /home/balkian/octo.sh move -10 -10 0 + repeat = 0 + delay = 3 +end +begin + button = KEY_8 + prog = irexec + config = /home/balkian/octo.sh move 0 -10 0 + repeat = 0 + delay = 3 +end +begin + button = KEY_9 + prog = irexec + config = /home/balkian/octo.sh move 10 -10 0 + repeat = 0 + delay = 3 +end \ No newline at end of file diff --git a/octo.sh b/octo.sh index b31c239..357faaa 100644 --- a/octo.sh +++ b/octo.sh @@ -1,4 +1,5 @@ #!/bin/bash +echo $(date) - "$@" >> /tmp/octo-log CONF_FILE=$HOME/.octo.conf if [ ! -f "$CONF_FILE" ]; then @@ -25,5 +26,8 @@ case $1 in ;; home) send_octo '{ "command": "home", "axes": ["x", "y", "z"] }' -;; + ;; + nothing) + echo "nothing $(date)" >> /tmp/prueba + ;; esac \ No newline at end of file