From 167411dd4cb7f68d39551850e6642f6819a6d299 Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Mon, 22 Jan 2018 23:12:54 +1300 Subject: [PATCH 1/3] examples/controller.sh: default to stop Make any input that is not registered default to stop. --- software/examples/controller.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/software/examples/controller.sh b/software/examples/controller.sh index a9a2617..1b11789 100755 --- a/software/examples/controller.sh +++ b/software/examples/controller.sh @@ -13,11 +13,11 @@ lolibot_control() { while read -rsn1 dir; do case "$dir" in - (x) lolibot_control stop;; (j) lolibot_control reverse;; (k) lolibot_control forward;; (h) lolibot_control left;; (l) lolibot_control right;; (q) break;; + (*) lolibot_control stop;; esac done From 069165430bc578d768dbc2ff627ad398669fcf57 Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Mon, 22 Jan 2018 23:12:57 +1300 Subject: [PATCH 2/3] examples/controller.sh: make sure we stop when exiting Add an exit trap so regardless of how the script is terminated the LoliBot will stop. --- software/examples/controller.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/software/examples/controller.sh b/software/examples/controller.sh index 1b11789..91b8665 100755 --- a/software/examples/controller.sh +++ b/software/examples/controller.sh @@ -11,6 +11,8 @@ lolibot_control() { mosquitto_pub -d -h iot.eclipse.org -t lolibot/${ID}/in -m "$@" } +trap "lolibot_control stop" EXIT + while read -rsn1 dir; do case "$dir" in (j) lolibot_control reverse;; From 9319e97bdaf8c53e3179e33d555dd6c7b437deb9 Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Mon, 22 Jan 2018 23:12:59 +1300 Subject: [PATCH 3/3] examples/controller.sh: lookup the MQTT host from the configuration Saves having to update the MQTT host in multiple places. --- software/examples/controller.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/software/examples/controller.sh b/software/examples/controller.sh index 91b8665..abdffef 100755 --- a/software/examples/controller.sh +++ b/software/examples/controller.sh @@ -7,8 +7,12 @@ set -eu ID="$1" +get_host() { + PYTHONPATH="$(dirname $0)/../configuration" python -c "from mqtt import settings;print(settings['host'])" +} + lolibot_control() { - mosquitto_pub -d -h iot.eclipse.org -t lolibot/${ID}/in -m "$@" + mosquitto_pub -d -h "$(get_host)" -t lolibot/${ID}/in -m "$@" } trap "lolibot_control stop" EXIT