From b96c9227698a1c6ca2b96739c4dc0c01081505ef Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Tue, 30 Apr 2019 19:45:17 -0600 Subject: [PATCH 01/50] 0.2.188 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Remove subshell spawning for --- monitor.sh | 6 +++--- support/mqtt | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/monitor.sh b/monitor.sh index da7fa01a..8e0f8bbc 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.187 +export version=0.2.188 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' @@ -1103,7 +1103,7 @@ while true; do "type=KNOWN_MAC" done - elif [[ $mqtt_topic_branch =~ .*NEW\ STATIC\ DEVICE.* ]] || [[ $mqtt_topic_branch =~ .*DELETE\ STATIC\ DEVICE.* ]]; then + elif [[ $mqtt_topic_branch =~ .*ADD\ STATIC\ DEVICE.* ]] || [[ $mqtt_topic_branch =~ .*DELETE\ STATIC\ DEVICE.* ]]; then if [[ "${data_of_instruction^^}" =~ ([A-F0-9]{2}:){5}[A-F0-9]{2} ]]; then #GET MAC ADDRESSES @@ -1111,7 +1111,7 @@ while true; do if [ ! ${known_public_device_name[$mac]+true} ]; then #HERE, WE KNOW THAT WE HAVE A MAC ADDRESS AND A VALID INSTRUCTION - if [[ $mqtt_topic_branch =~ .*NEW\ STATIC\ DEVICE.* ]]; then + if [[ $mqtt_topic_branch =~ .*ADD\ STATIC\ DEVICE.* ]]; then #WAS THERE A NAME HERE? name=$(echo "$data_of_instruction" | tr "\\t" " " | sed 's/ */ /gi;s/#.\{0,\}//gi' | sed "s/$mac //gi;s/ */ /gi" ) diff --git a/support/mqtt b/support/mqtt index ba7e063e..b9701212 100644 --- a/support/mqtt +++ b/support/mqtt @@ -171,12 +171,12 @@ publish_rssi_message () { $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" #POST TO MQTT - ($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) + -m "$message" 2>&1 fi } @@ -254,13 +254,13 @@ publish_presence_message () { $PREF_VERBOSE_LOGGING && printf "%s\n" "${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH $device_tracker_message${NC}" #POST TO MQTT - ($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ - -m "$device_tracker_message" 2>&1) + -m "$device_tracker_message" 2>&1 fi fi @@ -269,14 +269,14 @@ publish_presence_message () { $PREF_VERBOSE_LOGGING && printf "%s\n" "${YELLOW}$(json_unformat "$message")${NC}" #POST TO MQTT - ($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) + -m "$message" 2>&1 fi } @@ -287,33 +287,33 @@ publish_cooperative_scan_message () { if [ -n "$1" ] && [ -z "$2" ]; then #POST TO MQTT - ($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/scan/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 elif [ -n "$1" ] && [ -n "$2" ]; then #POST TO MQTT - ($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/$2/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 else - ($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ -q 2 \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/scan" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 fi } From 2c3f19269c6ebcc9d185f41d41fedf79c7e9aadc Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 10:12:40 -0600 Subject: [PATCH 02/50] 0.2.189 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • improved logging clarity for mqtt messaging --- monitor.sh | 2 +- support/mqtt | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/monitor.sh b/monitor.sh index 8e0f8bbc..ba3084af 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.188 +export version=0.2.189 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' diff --git a/support/mqtt b/support/mqtt index b9701212..c324db2d 100644 --- a/support/mqtt +++ b/support/mqtt @@ -194,6 +194,7 @@ publish_presence_message () { local message local existing_alias local mqtt_topic_branch + local confidence_printable local device_tracker_message #SET ISOLATED ADDRESS @@ -250,8 +251,17 @@ publish_presence_message () { #A COMPLETE CONFIDENCE MESSAGE if [ -n "$device_tracker_message" ]; then #PRINT FOR DEVICE TRACKER - log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH${NC}" - $PREF_VERBOSE_LOGGING && printf "%s\n" "${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH $device_tracker_message${NC}" + if [ $PREF_VERBOSE_LOGGING == true ]; then + log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH $device_tracker_message${NC}" + + elif [[ "${message,,}" =~ \"confidence\":\"([0-9]{1,3})\" ]]; then + + #GET CONFIDENCE VALUE + confidence_printable="${BASH_REMATCH[1]}" + + #EXTRACT CONFIDENCE VALUE TO POST + log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH { ... confidence : $confidence_printable ... } ${NC}" + fi #POST TO MQTT $mosquitto_pub_path \ From 1ee165152337a380fed8f3f4476dd24ab6321ca4 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 10:17:33 -0600 Subject: [PATCH 03/50] 0.2.189 --- support/mqtt | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/support/mqtt b/support/mqtt index c324db2d..122009c7 100644 --- a/support/mqtt +++ b/support/mqtt @@ -274,9 +274,27 @@ publish_presence_message () { fi fi - #DEBUGGING WITH SIMPLE - log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" - $PREF_VERBOSE_LOGGING && printf "%s\n" "${YELLOW}$(json_unformat "$message")${NC}" + #MESSAGE PRINTING + if [ $PREF_VERBOSE_LOGGING == true ]; then + + + log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" + #REDACTIONS? + if [ "$PREF_REDACT" == true ]; then + printf "%s\n" "${YELLOW}$(json_unformat "$message" | sed "s/\([0-9A-Fa-f]\{2\}:\)\{5\}/ [REDACTED]:/gi;s/\([0-9A-Fa-f-]\{36\}\)/ [REDACTED]/gi" )${NC}" + else + printf "%s\n" "${YELLOW}$(json_unformat "$message")${NC}" + + fi + + elif [[ "${message,,}" =~ \"confidence\":\"([0-9]{1,3})\" ]]; then + + #GET CONFIDENCE VALUE + confidence_printable="${BASH_REMATCH[1]}" + + #EXTRACT CONFIDENCE VALUE TO POST + log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic { ... confidence : $confidence_printable ... } ${NC}" + fi #POST TO MQTT $mosquitto_pub_path \ From eb1b264169d365ca4995628e54163915354344a8 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:33:46 -0600 Subject: [PATCH 04/50] 0.2.190 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • mqtt error handling testing --- support/mqtt | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/support/mqtt b/support/mqtt index 122009c7..64b11a15 100644 --- a/support/mqtt +++ b/support/mqtt @@ -44,13 +44,17 @@ function json_format (){ # MQTT ANNOUNCE ONLINE # ---------------------------------------------------------------------------------------- mqtt_announce_online(){ + local mqtt_error + #ANNOUCEE HEALTH - $mosquitto_pub_path \ + mqtt_error=$($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1 + -m "online" -q "2" 2>&1) + + log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" } # ---------------------------------------------------------------------------------------- @@ -113,6 +117,8 @@ mqtt_broker_clean (){ mqtt_listener (){ #ANNOUNCE ONLINE PRESENCE mqtt_announce_online + + #DEFINE LOCALS local topic_data local topic_path @@ -156,11 +162,11 @@ publish_rssi_message () { local address local message local mqtt_topic_branch + local mqtt_error #SET ISOLATED ADDRESS address="$1" message="$2" - mqtt_topic_branch="$address" #ALIASES? @@ -171,12 +177,14 @@ publish_rssi_message () { $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" #POST TO MQTT - $mosquitto_pub_path \ + mqtt_error=$($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1 + -m "$message" 2>&1) + + log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" fi } @@ -196,6 +204,7 @@ publish_presence_message () { local mqtt_topic_branch local confidence_printable local device_tracker_message + local mqtt_error #SET ISOLATED ADDRESS isolated_address="${1##*=}" @@ -264,13 +273,16 @@ publish_presence_message () { fi #POST TO MQTT - $mosquitto_pub_path \ + mqtt_error=$($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ - -m "$device_tracker_message" 2>&1 + -m "$device_tracker_message" 2>&1) + + log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" + fi fi @@ -297,52 +309,59 @@ publish_presence_message () { fi #POST TO MQTT - $mosquitto_pub_path \ + mqtt_error=$($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1 + -m "$message" 2>&1) + + log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" + fi } publish_cooperative_scan_message () { + local mqtt_error #ANNOUNCE ONLINE mqtt_announce_online if [ -n "$1" ] && [ -z "$2" ]; then #POST TO MQTT - $mosquitto_pub_path \ + mqtt_error=$($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/scan/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) elif [ -n "$1" ] && [ -n "$2" ]; then #POST TO MQTT - $mosquitto_pub_path \ + mqtt_error=$($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/$2/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) else - $mosquitto_pub_path \ + mqtt_error=$($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ -q 2 \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/scan" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) fi + + + log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" } #SHOULD CLEAN? From 140cae60f101b08c25296886721cdd93a0ff6283 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:34:51 -0600 Subject: [PATCH 05/50] 0.2.190 --- monitor.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.sh b/monitor.sh index ba3084af..40ffbca7 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.189 +export version=0.2.190 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' From eecd24941f8cf1f37c0d5e4833687fa57730247a Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:48:57 -0600 Subject: [PATCH 06/50] 0.2.191 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • mqtt error handling buildout & testing --- monitor.sh | 2 +- support/mqtt | 74 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/monitor.sh b/monitor.sh index 40ffbca7..f51f6716 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.190 +export version=0.2.191 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' diff --git a/support/mqtt b/support/mqtt index 64b11a15..e8b1a583 100644 --- a/support/mqtt +++ b/support/mqtt @@ -44,17 +44,17 @@ function json_format (){ # MQTT ANNOUNCE ONLINE # ---------------------------------------------------------------------------------------- mqtt_announce_online(){ - local mqtt_error + #ANNOUCEE HEALTH - mqtt_error=$($mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1) + -m "online" -q "2" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" - log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" + } # ---------------------------------------------------------------------------------------- @@ -62,13 +62,13 @@ mqtt_announce_online(){ # ---------------------------------------------------------------------------------------- mqtt_echo(){ #ANNOUCEE HEALTH - $mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/echo" \ -m "ok" \ - -q "2" 2>&1 + -q "2" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" } @@ -144,13 +144,33 @@ mqtt_listener (){ --will-payload "offline" 2>&1 ) #LOG ERROR - log "[CMD-ERRO] ${RED}mqtt broker went offline, or a password/username combination was rejected.${NC}" + log "${RED}[CMD-ERRO]${NC} ${RED}mqtt broker is offline, or a password/username combination was rejected.${NC}" sleep 10 done } +# ---------------------------------------------------------------------------------------- +# MQTT ERROR HANDLER +# ---------------------------------------------------------------------------------------- +mqtt_error_handler () { + local return_value + return_value=false + + if [ -n "$1" ]; then + local print_message + + #ERRORS + [[ ${1^^} =~ .*REFUSED.* ]] && return_value=true && print_message="mqtt broker refused connection - check username, password, and host address" + [[ ${1^^} =~ .*NETWORK.* ]] && return_value=true && print_message="network is down. enqueuing command to try again after a delay." + + $return_value && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" + fi + + return $return_value +} + # ---------------------------------------------------------------------------------------- # PUBLISH RSSI MESSAGE # ---------------------------------------------------------------------------------------- @@ -162,8 +182,7 @@ publish_rssi_message () { local address local message local mqtt_topic_branch - local mqtt_error - + #SET ISOLATED ADDRESS address="$1" message="$2" @@ -177,14 +196,12 @@ publish_rssi_message () { $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" #POST TO MQTT - mqtt_error=$($mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) - - log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" + -m "$message" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" fi } @@ -204,7 +221,7 @@ publish_presence_message () { local mqtt_topic_branch local confidence_printable local device_tracker_message - local mqtt_error + #SET ISOLATED ADDRESS isolated_address="${1##*=}" @@ -273,15 +290,13 @@ publish_presence_message () { fi #POST TO MQTT - mqtt_error=$($mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ - -m "$device_tracker_message" 2>&1) - - log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" + -m "$device_tracker_message" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" fi fi @@ -309,59 +324,56 @@ publish_presence_message () { fi #POST TO MQTT - mqtt_error=$($mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) + -m "$message" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" - log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" + fi } publish_cooperative_scan_message () { - local mqtt_error + #ANNOUNCE ONLINE mqtt_announce_online if [ -n "$1" ] && [ -z "$2" ]; then #POST TO MQTT - mqtt_error=$($mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/scan/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" elif [ -n "$1" ] && [ -n "$2" ]; then #POST TO MQTT - mqtt_error=$($mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/$2/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" else - mqtt_error=$($mosquitto_pub_path \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ -q 2 \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/scan" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" fi - - - log "${RED}[CMD-POST]${NC} ${YELLOW}mqtt response: [$mqtt_error] ${NC} $LINENO" } #SHOULD CLEAN? From 6cd88d570aa9fef15d45f22738b6b31e6784fca1 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:49:58 -0600 Subject: [PATCH 07/50] 0.2.191 --- support/mqtt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/support/mqtt b/support/mqtt index e8b1a583..fce64f34 100644 --- a/support/mqtt +++ b/support/mqtt @@ -44,7 +44,6 @@ function json_format (){ # MQTT ANNOUNCE ONLINE # ---------------------------------------------------------------------------------------- mqtt_announce_online(){ - #ANNOUCEE HEALTH mqtt_error_handler $($mosquitto_pub_path \ @@ -168,7 +167,7 @@ mqtt_error_handler () { $return_value && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" fi - return $return_value + echo $return_value } # ---------------------------------------------------------------------------------------- From b377430d69d663c4a3db6a7cfd29e9d37a3062aa Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:51:08 -0600 Subject: [PATCH 08/50] 0.2.191 --- support/mqtt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/support/mqtt b/support/mqtt index fce64f34..3798c101 100644 --- a/support/mqtt +++ b/support/mqtt @@ -155,19 +155,19 @@ mqtt_listener (){ # ---------------------------------------------------------------------------------------- mqtt_error_handler () { local return_value - return_value=false + return_value=0 if [ -n "$1" ]; then local print_message #ERRORS - [[ ${1^^} =~ .*REFUSED.* ]] && return_value=true && print_message="mqtt broker refused connection - check username, password, and host address" - [[ ${1^^} =~ .*NETWORK.* ]] && return_value=true && print_message="network is down. enqueuing command to try again after a delay." + [[ ${1^^} =~ .*REFUSED.* ]] && return_value=1 && print_message="mqtt broker refused connection - check username, password, and host address" + [[ ${1^^} =~ .*NETWORK.* ]] && return_value=1 && print_message="network is down. enqueuing command to try again after a delay." - $return_value && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" + [ $return_value == 1 ] && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" fi - echo $return_value + return $return_value } # ---------------------------------------------------------------------------------------- From 6155444c27193c72ef4c28c9e77f818bd87ab6aa Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:52:31 -0600 Subject: [PATCH 09/50] 0.2.191 --- support/mqtt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/mqtt b/support/mqtt index 3798c101..b3a71e0a 100644 --- a/support/mqtt +++ b/support/mqtt @@ -46,12 +46,12 @@ function json_format (){ mqtt_announce_online(){ #ANNOUCEE HEALTH - mqtt_error_handler $($mosquitto_pub_path \ + [ mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -m "online" -q "2" 2>&1) == 1 ] && echo "ERROR NEEDS TO BE HANDLED" } From 9dabbdfa79599ad3d4fdadc7724bd1ed1652d6b4 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:53:39 -0600 Subject: [PATCH 10/50] 0.2.191 --- support/mqtt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/support/mqtt b/support/mqtt index b3a71e0a..479f14a9 100644 --- a/support/mqtt +++ b/support/mqtt @@ -51,7 +51,7 @@ mqtt_announce_online(){ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1) == 1 ] && echo "ERROR NEEDS TO BE HANDLED" + -m "online" -q "2" 2>&1) == 1 ] && echo "TODO: handle error at $LINENO" } @@ -67,7 +67,7 @@ mqtt_echo(){ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/echo" \ -m "ok" \ - -q "2" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -q "2" 2>&1) && echo "TODO: handle error at $LINENO" } @@ -200,7 +200,7 @@ publish_rssi_message () { $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" fi } @@ -295,7 +295,7 @@ publish_presence_message () { $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ - -m "$device_tracker_message" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -m "$device_tracker_message" 2>&1) && echo "TODO: handle error at $LINENO" fi fi @@ -330,7 +330,7 @@ publish_presence_message () { $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" @@ -351,7 +351,7 @@ publish_cooperative_scan_message () { $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/scan/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" elif [ -n "$1" ] && [ -n "$2" ]; then #POST TO MQTT @@ -361,7 +361,7 @@ publish_cooperative_scan_message () { $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/$2/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" else @@ -371,7 +371,7 @@ publish_cooperative_scan_message () { -q 2 \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/scan" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "ERROR NEEDS TO BE HANDLED" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" fi } From e0a14dd1cd6466ff3ae65b6bf6ec8868ae27bfd0 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:54:54 -0600 Subject: [PATCH 11/50] 0.2.191 --- support/mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index 479f14a9..a6f595ee 100644 --- a/support/mqtt +++ b/support/mqtt @@ -51,7 +51,7 @@ mqtt_announce_online(){ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1) == 1 ] && echo "TODO: handle error at $LINENO" + -m "online" -q "2" 2>&1) == 0 ] && echo "TODO: handle error at $LINENO" } From 46e6227e233dc5e35630e9dd5337237e609bc684 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:58:53 -0600 Subject: [PATCH 12/50] 0.2.191 --- support/mqtt | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/support/mqtt b/support/mqtt index a6f595ee..ebb459d5 100644 --- a/support/mqtt +++ b/support/mqtt @@ -46,14 +46,12 @@ function json_format (){ mqtt_announce_online(){ #ANNOUCEE HEALTH - [ mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1) == 0 ] && echo "TODO: handle error at $LINENO" - - + -m "online" -q "2" 2>&1) } # ---------------------------------------------------------------------------------------- @@ -61,13 +59,13 @@ mqtt_announce_online(){ # ---------------------------------------------------------------------------------------- mqtt_echo(){ #ANNOUCEE HEALTH - mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/echo" \ -m "ok" \ - -q "2" 2>&1) && echo "TODO: handle error at $LINENO" + -q "2" } @@ -154,20 +152,19 @@ mqtt_listener (){ # MQTT ERROR HANDLER # ---------------------------------------------------------------------------------------- mqtt_error_handler () { - local return_value - return_value=0 - if [ -n "$1" ]; then - local print_message + #RUN THE COMMAND + mqtt_error=$($mosquitto_pub_path $@ 2>&1) + + #PROCESS ANY ERRORS THAT SHOULD OCCURR + if [ -n "$mqtt_error" ]; then #ERRORS - [[ ${1^^} =~ .*REFUSED.* ]] && return_value=1 && print_message="mqtt broker refused connection - check username, password, and host address" - [[ ${1^^} =~ .*NETWORK.* ]] && return_value=1 && print_message="network is down. enqueuing command to try again after a delay." + [[ ${mqtt_error^^} =~ .*REFUSED.* ]] && print_message="mqtt broker refused connection - check username, password, and host address" + [[ ${mqtt_error^^} =~ .*NETWORK.* ]] && print_message="network is down. enqueuing command to try again after a delay." - [ $return_value == 1 ] && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" + log "${RED}[CMD-ERROR]${NC} ${YELLOW} $print_message ${NC}" fi - - return $return_value } # ---------------------------------------------------------------------------------------- @@ -195,12 +192,12 @@ publish_rssi_message () { $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" + -m "$message" fi } @@ -289,13 +286,13 @@ publish_presence_message () { fi #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ - -m "$device_tracker_message" 2>&1) && echo "TODO: handle error at $LINENO" + -m "$device_tracker_message" fi fi @@ -323,14 +320,14 @@ publish_presence_message () { fi #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" + -m "$message" @@ -345,33 +342,33 @@ publish_cooperative_scan_message () { if [ -n "$1" ] && [ -z "$2" ]; then #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/scan/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" elif [ -n "$1" ] && [ -n "$2" ]; then #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/$2/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" else - mqtt_error_handler $($mosquitto_pub_path \ + mqtt_error_handler \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ -q 2 \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/scan" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" fi } From 3bdf9b6b3bdbab7410c6b4ae40cfdff289798e0f Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 12:59:41 -0600 Subject: [PATCH 13/50] 0.2.191 --- support/mqtt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/support/mqtt b/support/mqtt index ebb459d5..b8e58921 100644 --- a/support/mqtt +++ b/support/mqtt @@ -51,7 +51,8 @@ mqtt_announce_online(){ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1) + -m "online" \ + -q "2" } # ---------------------------------------------------------------------------------------- @@ -64,7 +65,7 @@ mqtt_echo(){ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/echo" \ - -m "ok" \ + -m "ok" \ -q "2" } From 22575849a55e93be80645c133c438732ff4c6d12 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:01:34 -0600 Subject: [PATCH 14/50] 0.2.191 --- support/mqtt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index b8e58921..a591a354 100644 --- a/support/mqtt +++ b/support/mqtt @@ -157,6 +157,8 @@ mqtt_error_handler () { #RUN THE COMMAND mqtt_error=$($mosquitto_pub_path $@ 2>&1) + local print_message + #PROCESS ANY ERRORS THAT SHOULD OCCURR if [ -n "$mqtt_error" ]; then @@ -164,7 +166,7 @@ mqtt_error_handler () { [[ ${mqtt_error^^} =~ .*REFUSED.* ]] && print_message="mqtt broker refused connection - check username, password, and host address" [[ ${mqtt_error^^} =~ .*NETWORK.* ]] && print_message="network is down. enqueuing command to try again after a delay." - log "${RED}[CMD-ERROR]${NC} ${YELLOW} $print_message ${NC}" + [ -n "$print_message" ] && log "${RED}[CMD-ERROR]${NC} ${YELLOW} $print_message / $mqtt_error ${NC}" fi } From 9f31c6d86d52799e76804fc6e5377c4ecb36a7d7 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:04:33 -0600 Subject: [PATCH 15/50] 0.2.191 --- support/mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index a591a354..eb4f0963 100644 --- a/support/mqtt +++ b/support/mqtt @@ -166,7 +166,7 @@ mqtt_error_handler () { [[ ${mqtt_error^^} =~ .*REFUSED.* ]] && print_message="mqtt broker refused connection - check username, password, and host address" [[ ${mqtt_error^^} =~ .*NETWORK.* ]] && print_message="network is down. enqueuing command to try again after a delay." - [ -n "$print_message" ] && log "${RED}[CMD-ERROR]${NC} ${YELLOW} $print_message / $mqtt_error ${NC}" + log "${RED}[CMD-ERROR]${NC} ${YELLOW} $print_message / $mqtt_error ${NC}" fi } From f5ad9e624025a861bf8e4ec9baba0368a446e098 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:07:32 -0600 Subject: [PATCH 16/50] 0.2.191 --- support/mqtt | 54 +++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/support/mqtt b/support/mqtt index eb4f0963..39ba0ff3 100644 --- a/support/mqtt +++ b/support/mqtt @@ -46,13 +46,12 @@ function json_format (){ mqtt_announce_online(){ #ANNOUCEE HEALTH - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" \ - -q "2" + -m "online" -q "2" 2>&1) && echo "TODO: handle error at $LINENO" } # ---------------------------------------------------------------------------------------- @@ -60,13 +59,13 @@ mqtt_announce_online(){ # ---------------------------------------------------------------------------------------- mqtt_echo(){ #ANNOUCEE HEALTH - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/echo" \ - -m "ok" \ - -q "2" + -m "ok" \ + -q "2" 2>&1) && echo "TODO: handle error at $LINENO" } @@ -153,21 +152,20 @@ mqtt_listener (){ # MQTT ERROR HANDLER # ---------------------------------------------------------------------------------------- mqtt_error_handler () { + local return_value + return_value=1 - #RUN THE COMMAND - mqtt_error=$($mosquitto_pub_path $@ 2>&1) - - local print_message - - #PROCESS ANY ERRORS THAT SHOULD OCCURR - if [ -n "$mqtt_error" ]; then + if [ -n "$1" ]; then + local print_message #ERRORS - [[ ${mqtt_error^^} =~ .*REFUSED.* ]] && print_message="mqtt broker refused connection - check username, password, and host address" - [[ ${mqtt_error^^} =~ .*NETWORK.* ]] && print_message="network is down. enqueuing command to try again after a delay." + [[ ${1^^} =~ .*REFUSED.* ]] && return_value=0 && print_message="mqtt broker refused connection - check username, password, and host address" + [[ ${1^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." - log "${RED}[CMD-ERROR]${NC} ${YELLOW} $print_message / $mqtt_error ${NC}" + [ $return_value == 0 ] && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" fi + + return $return_value } # ---------------------------------------------------------------------------------------- @@ -195,12 +193,12 @@ publish_rssi_message () { $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" #POST TO MQTT - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" + -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" fi } @@ -289,13 +287,13 @@ publish_presence_message () { fi #POST TO MQTT - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ - -m "$device_tracker_message" + -m "$device_tracker_message" 2>&1) && echo "TODO: handle error at $LINENO" fi fi @@ -323,14 +321,14 @@ publish_presence_message () { fi #POST TO MQTT - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$topic" \ - -m "$message" + -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" @@ -345,33 +343,33 @@ publish_cooperative_scan_message () { if [ -n "$1" ] && [ -z "$2" ]; then #POST TO MQTT - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/scan/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" elif [ -n "$1" ] && [ -n "$2" ]; then #POST TO MQTT - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/$2/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" else - mqtt_error_handler \ + mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ -q 2 \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/scan" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" fi } From d63684487c2477510c08753e95a1948a9a092f8d Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:10:04 -0600 Subject: [PATCH 17/50] 0.2.191 --- support/mqtt | 1 + 1 file changed, 1 insertion(+) diff --git a/support/mqtt b/support/mqtt index 39ba0ff3..48daa3a7 100644 --- a/support/mqtt +++ b/support/mqtt @@ -163,6 +163,7 @@ mqtt_error_handler () { [[ ${1^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." [ $return_value == 0 ] && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" + return_value=1 fi return $return_value From 36037e82e2353fbac8fe905553f0fc9d30726529 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:12:12 -0600 Subject: [PATCH 18/50] 0.2.191 --- support/mqtt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/support/mqtt b/support/mqtt index 48daa3a7..4790cba1 100644 --- a/support/mqtt +++ b/support/mqtt @@ -155,15 +155,17 @@ mqtt_error_handler () { local return_value return_value=1 - if [ -n "$1" ]; then + printf "%s\n" "$@" + + if [ -n "$@" ]; then local print_message #ERRORS - [[ ${1^^} =~ .*REFUSED.* ]] && return_value=0 && print_message="mqtt broker refused connection - check username, password, and host address" - [[ ${1^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." + [[ ${@^^} =~ .*REFUSED.* ]] && return_value=0 && print_message="mqtt broker refused connection - check username, password, and host address" + [[ ${@^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." [ $return_value == 0 ] && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" - return_value=1 + return_value=0 fi return $return_value @@ -295,7 +297,6 @@ publish_presence_message () { $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ -m "$device_tracker_message" 2>&1) && echo "TODO: handle error at $LINENO" - fi fi From 16efd832e15e6f4fb4e57431082bfdb6de0bad35 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:13:53 -0600 Subject: [PATCH 19/50] 0.2.191 --- support/mqtt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/support/mqtt b/support/mqtt index 4790cba1..d63395b8 100644 --- a/support/mqtt +++ b/support/mqtt @@ -152,19 +152,20 @@ mqtt_listener (){ # MQTT ERROR HANDLER # ---------------------------------------------------------------------------------------- mqtt_error_handler () { + local received="$@" local return_value return_value=1 - printf "%s\n" "$@" + printf "%s\n" "$received" - if [ -n "$@" ]; then + if [ -n "$received" ]; then local print_message #ERRORS - [[ ${@^^} =~ .*REFUSED.* ]] && return_value=0 && print_message="mqtt broker refused connection - check username, password, and host address" - [[ ${@^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." + [[ ${received^^} =~ .*REFUSED.* ]] && return_value=0 && print_message="mqtt broker refused connection - check username, password, and host address" + [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." - [ $return_value == 0 ] && log "${RED}[CMD-POST]${NC} ${YELLOW} $print_message ${NC}" + log "${RED}[CMD-POST]${NC} ${YELLOW} [$@] $print_message ${NC}" return_value=0 fi From d0fae1bfd6d1882340b7b197a9189fe62b72eb7c Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:16:24 -0600 Subject: [PATCH 20/50] 0.2.191 --- support/mqtt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/support/mqtt b/support/mqtt index d63395b8..f9a68fc2 100644 --- a/support/mqtt +++ b/support/mqtt @@ -152,12 +152,10 @@ mqtt_listener (){ # MQTT ERROR HANDLER # ---------------------------------------------------------------------------------------- mqtt_error_handler () { - local received="$@" + local received="$*" local return_value return_value=1 - printf "%s\n" "$received" - if [ -n "$received" ]; then local print_message @@ -165,7 +163,7 @@ mqtt_error_handler () { [[ ${received^^} =~ .*REFUSED.* ]] && return_value=0 && print_message="mqtt broker refused connection - check username, password, and host address" [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." - log "${RED}[CMD-POST]${NC} ${YELLOW} [$@] $print_message ${NC}" + log "${RED}[CMD-POST]${NC} ${YELLOW} $received / $print_message ${NC}" return_value=0 fi From 03c940a8ffea5c79990091635323cb0ed16a24ab Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:25:31 -0600 Subject: [PATCH 21/50] 0.2.192 --- monitor.sh | 2 +- support/mqtt | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/monitor.sh b/monitor.sh index f51f6716..79444b0d 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.191 +export version=0.2.192 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' diff --git a/support/mqtt b/support/mqtt index f9a68fc2..fcb36322 100644 --- a/support/mqtt +++ b/support/mqtt @@ -141,7 +141,7 @@ mqtt_listener (){ --will-payload "offline" 2>&1 ) #LOG ERROR - log "${RED}[CMD-ERRO]${NC} ${RED}mqtt broker is offline, or a password/username combination was rejected.${NC}" + log "${RED}[CMD-ERRO]${NC} ${YELLOW}mqtt broker refused connection - check username, password, and host address${NC}" sleep 10 done @@ -160,10 +160,10 @@ mqtt_error_handler () { local print_message #ERRORS - [[ ${received^^} =~ .*REFUSED.* ]] && return_value=0 && print_message="mqtt broker refused connection - check username, password, and host address" - [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay." + [[ ${received^^} =~ .*REFUSED.* ]] && return_value=1 && print_message="mqtt broker refused connection - check username, password, and host address" + [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay" - log "${RED}[CMD-POST]${NC} ${YELLOW} $received / $print_message ${NC}" + log "${RED}[CMD-ERRO]${NC} ${YELLOW} $print_message ${NC}" return_value=0 fi @@ -200,7 +200,7 @@ publish_rssi_message () { $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" + -m "$message" 2>&1) && sleep 5 && publish_rssi_message "$1" "$2" fi } @@ -309,9 +309,9 @@ publish_presence_message () { printf "%s\n" "${YELLOW}$(json_unformat "$message" | sed "s/\([0-9A-Fa-f]\{2\}:\)\{5\}/ [REDACTED]:/gi;s/\([0-9A-Fa-f-]\{36\}\)/ [REDACTED]/gi" )${NC}" else printf "%s\n" "${YELLOW}$(json_unformat "$message")${NC}" - fi + #EXTRACT RAW CONFIDENC elif [[ "${message,,}" =~ \"confidence\":\"([0-9]{1,3})\" ]]; then #GET CONFIDENCE VALUE @@ -322,17 +322,18 @@ publish_presence_message () { fi #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + while mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $should_retain \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) && echo "TODO: handle error at $LINENO" - - + -m "$message" 2>&1); do + echo "TODO: handle error at $LINENO" + sleep 5 + done fi } From 027a5de915cf565809c18f10cfa10528072e95b2 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:30:42 -0600 Subject: [PATCH 22/50] 0.2.193 --- monitor.sh | 2 +- support/mqtt | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/monitor.sh b/monitor.sh index 79444b0d..001e6ed8 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.192 +export version=0.2.193 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' diff --git a/support/mqtt b/support/mqtt index fcb36322..cd451f9c 100644 --- a/support/mqtt +++ b/support/mqtt @@ -299,6 +299,21 @@ publish_presence_message () { fi fi + #POST TO MQTT + while mqtt_error_handler $($mosquitto_pub_path \ + -I "$mqtt_publisher_identity" \ + $should_retain \ + $mqtt_version_append \ + $mqtt_ca_file_append \ + -q 2 \ + -L "$mqtt_url$topic" \ + -m "$message" 2>&1); do + + echo "TODO: handle error at $LINENO" + sleep 5 + done + + #MESSAGE PRINTING if [ $PREF_VERBOSE_LOGGING == true ]; then @@ -320,20 +335,6 @@ publish_presence_message () { #EXTRACT CONFIDENCE VALUE TO POST log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic { ... confidence : $confidence_printable ... } ${NC}" fi - - #POST TO MQTT - while mqtt_error_handler $($mosquitto_pub_path \ - -I "$mqtt_publisher_identity" \ - $should_retain \ - $mqtt_version_append \ - $mqtt_ca_file_append \ - -q 2 \ - -L "$mqtt_url$topic" \ - -m "$message" 2>&1); do - - echo "TODO: handle error at $LINENO" - sleep 5 - done fi } From 44b8fc4676592c6b9b575a9cce66ae8823a35977 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:35:44 -0600 Subject: [PATCH 23/50] 0.2.194 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Failure tolerance added for mqtt messages --- monitor.sh | 2 +- support/mqtt | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/monitor.sh b/monitor.sh index 001e6ed8..59e41321 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.193 +export version=0.2.194 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' diff --git a/support/mqtt b/support/mqtt index cd451f9c..549b3bdc 100644 --- a/support/mqtt +++ b/support/mqtt @@ -163,7 +163,7 @@ mqtt_error_handler () { [[ ${received^^} =~ .*REFUSED.* ]] && return_value=1 && print_message="mqtt broker refused connection - check username, password, and host address" [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay" - log "${RED}[CMD-ERRO]${NC} ${YELLOW} $print_message ${NC}" + log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message ${NC}" return_value=0 fi @@ -195,12 +195,14 @@ publish_rssi_message () { $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + while mqtt_error_handler $($mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$topic" \ - -m "$message" 2>&1) && sleep 5 && publish_rssi_message "$1" "$2" + -m "$message" 2>&1); do + sleep 15 + done fi } @@ -220,8 +222,8 @@ publish_presence_message () { local mqtt_topic_branch local confidence_printable local device_tracker_message - + #SET ISOLATED ADDRESS isolated_address="${1##*=}" mqtt_topic_branch="$isolated_address" @@ -275,6 +277,17 @@ publish_presence_message () { #ONLY POST A MESSAGE TO DEVICE TRACKER BOARD IF WE HAVE #A COMPLETE CONFIDENCE MESSAGE if [ -n "$device_tracker_message" ]; then + #POST TO MQTT + while mqtt_error_handler $($mosquitto_pub_path \ + -I "$mqtt_publisher_identity" \ + $should_retain \ + $mqtt_version_append \ + $mqtt_ca_file_append \ + -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ + -m "$device_tracker_message" 2>&1); do + sleep 5 + done + #PRINT FOR DEVICE TRACKER if [ $PREF_VERBOSE_LOGGING == true ]; then log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH $device_tracker_message${NC}" @@ -287,15 +300,6 @@ publish_presence_message () { #EXTRACT CONFIDENCE VALUE TO POST log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH { ... confidence : $confidence_printable ... } ${NC}" fi - - #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ - -I "$mqtt_publisher_identity" \ - $should_retain \ - $mqtt_version_append \ - $mqtt_ca_file_append \ - -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ - -m "$device_tracker_message" 2>&1) && echo "TODO: handle error at $LINENO" fi fi @@ -308,12 +312,10 @@ publish_presence_message () { -q 2 \ -L "$mqtt_url$topic" \ -m "$message" 2>&1); do - - echo "TODO: handle error at $LINENO" sleep 5 done - + #MESSAGE PRINTING if [ $PREF_VERBOSE_LOGGING == true ]; then @@ -346,33 +348,33 @@ publish_cooperative_scan_message () { if [ -n "$1" ] && [ -z "$2" ]; then #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/scan/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 elif [ -n "$1" ] && [ -n "$2" ]; then #POST TO MQTT - mqtt_error_handler $($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ $mqtt_ca_file_append \ -q 2 \ -L "$mqtt_url$mqtt_topicpath/$2/$1" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 else - mqtt_error_handler $($mosquitto_pub_path \ + $mosquitto_pub_path \ -I "$mqtt_publisher_identity" \ $mqtt_version_append \ -q 2 \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/scan" \ - -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1) && echo "TODO: handle error at $LINENO" + -m "{\"identity\":\"$mqtt_publisher_identity\"}" 2>&1 fi } From 03a62a2c81b6aac17099c0576900a0e4285a6b10 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Wed, 1 May 2019 13:43:53 -0600 Subject: [PATCH 24/50] 0.2.194 doc updates --- support/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/support/README.md b/support/README.md index 517585b2..559754ea 100644 --- a/support/README.md +++ b/support/README.md @@ -153,6 +153,11 @@ Make sure you've updated `mosquitto` to v1.5 or higher. In order to support a wi #### I keep seeing MQTT Broker Offline messages in the `monitor` log. What's going on? mosquitto fails to connect to a broker if your password has certain special characters such as: `@`, `:`,`/` - if this is the case, the easiest solution is to create a new user for `monitor` with a different password. + +#### Can I use a certfile for mosquitto instead of my password? + +Yes, specify a path for `mqtt_certificate_path` in mqtt_preferences. + ____ ## *Filters* From 1bbff844ea24e61d9f5b448a48e1ddc30e765152 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 14:32:42 -0600 Subject: [PATCH 25/50] 0.2.195 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • MQTT error handling --- monitor.sh | 2 +- support/mqtt | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/monitor.sh b/monitor.sh index 59e41321..6c87753e 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.194 +export version=0.2.195 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' diff --git a/support/mqtt b/support/mqtt index 549b3bdc..b160fe86 100644 --- a/support/mqtt +++ b/support/mqtt @@ -16,6 +16,10 @@ # UTILITY FUNCTION FOR JOINING STRINGS # ---------------------------------------------------------------------------------------- +#GLOBALS +last_error_message="" +duplicate_error_count=1 + #UTILITY FUNCTIONS function join_string () (IFS=$1; shift; printf "$*"); function json_keypair () (join_string ":" "\"$1\"" "\"$2\"") @@ -154,19 +158,38 @@ mqtt_listener (){ mqtt_error_handler () { local received="$*" local return_value + local print_message="" + + #SET RETURN VALUE TO TRUE return_value=1 if [ -n "$received" ]; then - local print_message + #RESET PRINT MESSAGE #ERRORS [[ ${received^^} =~ .*REFUSED.* ]] && return_value=1 && print_message="mqtt broker refused connection - check username, password, and host address" [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay" - log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message ${NC}" + if [ "$last_error_message" == "$print_message" ]; then + #HERE, WE HAVE A REPEATED ERROR + duplicate_error_count=$((duplicate_error_count + 1 )) + + log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message (x$duplicate_error_count) ${NC}" + + else + #MESSAGE IS NOT REPEATED, SO FEEL FREE TO LOG IT + log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message ${NC}" + duplicate_error_count=0 + fi + + #SET TO TRUE TO CAUSE A LOOP OF return_value=0 + else + duplicate_error_count=0 + last_error_message="" fi + #RETURN VALUE return $return_value } @@ -285,7 +308,7 @@ publish_presence_message () { $mqtt_ca_file_append \ -L "$mqtt_url$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH" \ -m "$device_tracker_message" 2>&1); do - sleep 5 + sleep 10 done #PRINT FOR DEVICE TRACKER From 9b8255832f24919f5ee458a978ed885068a7c60c Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 14:38:51 -0600 Subject: [PATCH 26/50] 0.2.195 --- support/mqtt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/support/mqtt b/support/mqtt index b160fe86..77a5af19 100644 --- a/support/mqtt +++ b/support/mqtt @@ -85,7 +85,7 @@ mqtt_broker_clean (){ while read instruction; do #ERROR HANDLING - [[ ${instruction^^} =~ .*REFUSED.* ]] && return 0 + mqtt_error_handler "$instruction" && break #EXTRACT TOPIC PATH FROM FORMATTED MQTT MESSAGE topic_path_of_instruction="${instruction%%|*}" @@ -128,7 +128,7 @@ mqtt_listener (){ while read instruction; do #ERROR HANDLING - [[ ${instruction^^} =~ .*REFUSED.* ]] && break + mqtt_error_handler "$instruction" && break #PRINT THE INSTRUCTION BACK TO THE MAIN THREAD printf "MQTT$instruction\n" > main_pipe @@ -144,9 +144,7 @@ mqtt_listener (){ --will-topic "$mqtt_topicpath/$mqtt_publisher_identity/status" \ --will-payload "offline" 2>&1 ) - #LOG ERROR - log "${RED}[CMD-ERRO]${NC} ${YELLOW}mqtt broker refused connection - check username, password, and host address${NC}" - + #NEED TO RESUBSCRIBE sleep 10 done } @@ -173,7 +171,7 @@ mqtt_error_handler () { if [ "$last_error_message" == "$print_message" ]; then #HERE, WE HAVE A REPEATED ERROR duplicate_error_count=$((duplicate_error_count + 1 )) - + last_error_message="$print_message" log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message (x$duplicate_error_count) ${NC}" else From 6aa5985029b53c6f9ed2accb79359439d10b5ff0 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 14:52:21 -0600 Subject: [PATCH 27/50] 0.2.195 --- support/mqtt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index 77a5af19..9fbcc4fd 100644 --- a/support/mqtt +++ b/support/mqtt @@ -172,12 +172,13 @@ mqtt_error_handler () { #HERE, WE HAVE A REPEATED ERROR duplicate_error_count=$((duplicate_error_count + 1 )) last_error_message="$print_message" - log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message (x$duplicate_error_count) ${NC}" + log "${RED}[CMD-ERRO]${NC} ${YELLOW} x$duplicate_error_count ${NC}" else #MESSAGE IS NOT REPEATED, SO FEEL FREE TO LOG IT log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message ${NC}" duplicate_error_count=0 + last_error_message="$print_message" fi #SET TO TRUE TO CAUSE A LOOP OF From f53011e1cd20d3bc809c750778d97d99d07239e8 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 14:58:08 -0600 Subject: [PATCH 28/50] 0.2.195 --- support/mqtt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/support/mqtt b/support/mqtt index 9fbcc4fd..c148ad7d 100644 --- a/support/mqtt +++ b/support/mqtt @@ -162,8 +162,6 @@ mqtt_error_handler () { return_value=1 if [ -n "$received" ]; then - #RESET PRINT MESSAGE - #ERRORS [[ ${received^^} =~ .*REFUSED.* ]] && return_value=1 && print_message="mqtt broker refused connection - check username, password, and host address" [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay" @@ -172,11 +170,14 @@ mqtt_error_handler () { #HERE, WE HAVE A REPEATED ERROR duplicate_error_count=$((duplicate_error_count + 1 )) last_error_message="$print_message" - log "${RED}[CMD-ERRO]${NC} ${YELLOW} x$duplicate_error_count ${NC}" + + if [ "$duplicate_error_count" -gt "3" ]; then + log "${RED}[CMD-ERRO]${NC} ${RED}fatal mqtt error - messages may not be delivered as intended${NC}" + fi else #MESSAGE IS NOT REPEATED, SO FEEL FREE TO LOG IT - log "${RED}[CMD-ERRO]${NC} ${YELLOW}$print_message ${NC}" + log "${YELLOW}[CMD-WARN]${NC} ${YELLOW}warning: $print_message ${NC}" duplicate_error_count=0 last_error_message="$print_message" fi From 2f149308a50b75a1223e2ded2a3c37468a4b3877 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:01:32 -0600 Subject: [PATCH 29/50] 0.2.195 --- support/log | 4 +--- support/mqtt | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/support/log b/support/log index 868f4b86..46ae3b92 100644 --- a/support/log +++ b/support/log @@ -46,8 +46,6 @@ log_listener () { if [ "$last_log_line" == "$line" ] ; then duplicate_log_count=$((duplicate_log_count + 1 )) line_append=" (x$duplicate_log_count)" - should_repeat=$REPEAT - else duplicate_log_count=1 fi @@ -58,7 +56,7 @@ log_listener () { fi #ECHO LAST LINE - printf "${should_repeat}$launch_flag $version $(date "+%d-%m-%Y %I:%M:%S %p") $line$line_append\n" + printf "%s\n" "$launch_flag $version $(date "+%d-%m-%Y %I:%M:%S %p") $line$line_append" last_log_line="$line" done < log_pipe diff --git a/support/mqtt b/support/mqtt index c148ad7d..6b74f661 100644 --- a/support/mqtt +++ b/support/mqtt @@ -55,7 +55,7 @@ mqtt_announce_online(){ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/status" \ - -m "online" -q "2" 2>&1) && echo "TODO: handle error at $LINENO" + -m "online" -q "2" 2>&1) } # ---------------------------------------------------------------------------------------- @@ -68,8 +68,8 @@ mqtt_echo(){ $mqtt_version_append \ $mqtt_ca_file_append \ -L "$mqtt_url$mqtt_topicpath/$mqtt_publisher_identity/echo" \ - -m "ok" \ - -q "2" 2>&1) && echo "TODO: handle error at $LINENO" + -m "ok" \ + -q "2" 2>&1) } @@ -173,6 +173,8 @@ mqtt_error_handler () { if [ "$duplicate_error_count" -gt "3" ]; then log "${RED}[CMD-ERRO]${NC} ${RED}fatal mqtt error - messages may not be delivered as intended${NC}" + duplicate_error_count=0 + last_error_message="" fi else From e22b171c1af10aed757f5873642f30b1f0df9123 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:03:19 -0600 Subject: [PATCH 30/50] 0.2.195 --- support/log | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/support/log b/support/log index 46ae3b92..323f1d59 100644 --- a/support/log +++ b/support/log @@ -45,7 +45,6 @@ log_listener () { #IS THIS LINE DUPLICATED? if [ "$last_log_line" == "$line" ] ; then duplicate_log_count=$((duplicate_log_count + 1 )) - line_append=" (x$duplicate_log_count)" else duplicate_log_count=1 fi @@ -56,7 +55,7 @@ log_listener () { fi #ECHO LAST LINE - printf "%s\n" "$launch_flag $version $(date "+%d-%m-%Y %I:%M:%S %p") $line$line_append" + printf "%s\n" "$launch_flag $version $(date "+%d-%m-%Y %I:%M:%S %p") $line" last_log_line="$line" done < log_pipe From cff189a0522e995ddfec700fd73e09eeaf3dd612 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:05:49 -0600 Subject: [PATCH 31/50] 0.2.195 --- support/mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index 6b74f661..b41901bb 100644 --- a/support/mqtt +++ b/support/mqtt @@ -172,7 +172,7 @@ mqtt_error_handler () { last_error_message="$print_message" if [ "$duplicate_error_count" -gt "3" ]; then - log "${RED}[CMD-ERRO]${NC} ${RED}fatal mqtt error - messages may not be delivered as intended${NC}" + log "${RED}[CMD-ERRO]${NC} ${RED}fatal mqtt error - messages may not be delivered as intended ($print_message / $duplicate_error_count)${NC}" duplicate_error_count=0 last_error_message="" fi From 73cfa223fc6b58e33d1d94a281d6d98fa27574b5 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:07:11 -0600 Subject: [PATCH 32/50] 0.2.195 --- support/mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index b41901bb..fcbc880e 100644 --- a/support/mqtt +++ b/support/mqtt @@ -166,7 +166,7 @@ mqtt_error_handler () { [[ ${received^^} =~ .*REFUSED.* ]] && return_value=1 && print_message="mqtt broker refused connection - check username, password, and host address" [[ ${received^^} =~ .*NETWORK.* ]] && return_value=0 && print_message="network is down. enqueuing command to try again after a delay" - if [ "$last_error_message" == "$print_message" ]; then + if [ -n "$last_error_message" ] && [ "$last_error_message" == "$print_message" ]; then #HERE, WE HAVE A REPEATED ERROR duplicate_error_count=$((duplicate_error_count + 1 )) last_error_message="$print_message" From 8c2c886df15b02a8baae89fbc1f180210bea9a1e Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:09:31 -0600 Subject: [PATCH 33/50] 0.2.195 --- support/mqtt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/support/mqtt b/support/mqtt index fcbc880e..846f84dc 100644 --- a/support/mqtt +++ b/support/mqtt @@ -175,17 +175,20 @@ mqtt_error_handler () { log "${RED}[CMD-ERRO]${NC} ${RED}fatal mqtt error - messages may not be delivered as intended ($print_message / $duplicate_error_count)${NC}" duplicate_error_count=0 last_error_message="" - fi + fi + + #SET TO TRUE TO CAUSE A LOOP OF + return_value=0 - else + elif [ -n "$print_message"]; then #MESSAGE IS NOT REPEATED, SO FEEL FREE TO LOG IT - log "${YELLOW}[CMD-WARN]${NC} ${YELLOW}warning: $print_message ${NC}" + log "${YELLOW}[CMD-POST]${NC} ${YELLOW}warning: $print_message ${NC}" duplicate_error_count=0 - last_error_message="$print_message" - fi + last_error_message="$print_message" - #SET TO TRUE TO CAUSE A LOOP OF - return_value=0 + #SET TO TRUE TO CAUSE A LOOP OF + return_value=0 + fi else duplicate_error_count=0 last_error_message="" From edff0e5827bae70c057658fba1f94fc5f79dcc5b Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:10:30 -0600 Subject: [PATCH 34/50] 0.2.195 --- support/mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index 846f84dc..55f8dcc4 100644 --- a/support/mqtt +++ b/support/mqtt @@ -180,7 +180,7 @@ mqtt_error_handler () { #SET TO TRUE TO CAUSE A LOOP OF return_value=0 - elif [ -n "$print_message"]; then + elif [ -n "$print_message" ]; then #MESSAGE IS NOT REPEATED, SO FEEL FREE TO LOG IT log "${YELLOW}[CMD-POST]${NC} ${YELLOW}warning: $print_message ${NC}" duplicate_error_count=0 From 749c14182c963e4d0a22867a7cf23d2b7580c0d2 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:12:40 -0600 Subject: [PATCH 35/50] 0.2.196 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • mqtt error handling improvements --- monitor.sh | 2 +- support/mqtt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/monitor.sh b/monitor.sh index 6c87753e..ab192f20 100644 --- a/monitor.sh +++ b/monitor.sh @@ -25,7 +25,7 @@ # ---------------------------------------------------------------------------------------- #VERSION NUMBER -export version=0.2.195 +export version=0.2.196 #COLOR OUTPUT FOR RICH OUTPUT ORANGE=$'\e[1;33m' diff --git a/support/mqtt b/support/mqtt index 55f8dcc4..373faae5 100644 --- a/support/mqtt +++ b/support/mqtt @@ -182,7 +182,7 @@ mqtt_error_handler () { elif [ -n "$print_message" ]; then #MESSAGE IS NOT REPEATED, SO FEEL FREE TO LOG IT - log "${YELLOW}[CMD-POST]${NC} ${YELLOW}warning: $print_message ${NC}" + log "${YELLOW}[CMD-MQTT]${NC} ${YELLOW}warning: $print_message ${NC}" duplicate_error_count=0 last_error_message="$print_message" @@ -220,7 +220,7 @@ publish_rssi_message () { local topic="$mqtt_topicpath/$mqtt_publisher_identity/$mqtt_topic_branch/rssi" - $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" + $PREF_VERBOSE_LOGGING && log "${YELLOW}[CMD-MQTT]${NC} ${YELLOW}$topic${NC}" #POST TO MQTT while mqtt_error_handler $($mosquitto_pub_path \ @@ -318,7 +318,7 @@ publish_presence_message () { #PRINT FOR DEVICE TRACKER if [ $PREF_VERBOSE_LOGGING == true ]; then - log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH $device_tracker_message${NC}" + log "${YELLOW}[CMD-MQTT]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH $device_tracker_message${NC}" elif [[ "${message,,}" =~ \"confidence\":\"([0-9]{1,3})\" ]]; then @@ -326,7 +326,7 @@ publish_presence_message () { confidence_printable="${BASH_REMATCH[1]}" #EXTRACT CONFIDENCE VALUE TO POST - log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH { ... confidence : $confidence_printable ... } ${NC}" + log "${YELLOW}[CMD-MQTT]${NC} ${YELLOW}$topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH { ... confidence : $confidence_printable ... } ${NC}" fi fi fi @@ -348,7 +348,7 @@ publish_presence_message () { if [ $PREF_VERBOSE_LOGGING == true ]; then - log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic${NC}" + log "${YELLOW}[CMD-MQTT]${NC} ${YELLOW}$topic${NC}" #REDACTIONS? if [ "$PREF_REDACT" == true ]; then printf "%s\n" "${YELLOW}$(json_unformat "$message" | sed "s/\([0-9A-Fa-f]\{2\}:\)\{5\}/ [REDACTED]:/gi;s/\([0-9A-Fa-f-]\{36\}\)/ [REDACTED]/gi" )${NC}" @@ -363,7 +363,7 @@ publish_presence_message () { confidence_printable="${BASH_REMATCH[1]}" #EXTRACT CONFIDENCE VALUE TO POST - log "${YELLOW}[CMD-POST]${NC} ${YELLOW}$topic { ... confidence : $confidence_printable ... } ${NC}" + log "${YELLOW}[CMD-MQTT]${NC} ${YELLOW}$topic { ... confidence : $confidence_printable ... } ${NC}" fi fi } From 3f7eca36f2a70a0c66c0a386b1792eca4201542c Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:42:58 -0600 Subject: [PATCH 36/50] 0.2.196 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Readme updates --- README.md | 102 +++++++++++++++++----------------------------- support/README.md | 3 +- 2 files changed, 40 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 00819cc6..ddc6452c 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ # *Highlights* -`monitor` sends a JSON-formatted MQTT message including a confidence value from 0 to 100 to a specified broker when a specified Bluetooth device responds to a `name` query. By default, `name` queries are triggered after receiving an anonymous advertisement from a previously-unseen device. +`monitor` sends a JSON-formatted MQTT message including a confidence value from 0 to 100 to a specified broker when a specified Bluetooth device responds to a `name` query. By default, `name` queries are triggered after receiving an anonymous advertisement from a previously-unseen device (e.g., a device in peripheral mode advertising an ability to connect). -Example: +Example JSON package: ``` topic: monitor/{{name of monitor install}}/{{mac address}} message: { @@ -29,8 +29,7 @@ message: { In addition, optionally, a JSON-formatted MQTT message can be reported to the same broker whenever a publicly-advertising beacon device or an iBeacon device advertises. -Example: - +Example JSON package: ``` topic: monitor/{{name of monitor install}}/{{mac address or ibeacon uuid}} message: { @@ -54,7 +53,7 @@ ___ # *Oversimplified Analogy of the Bluetooth Presence Problem* -Imagine you're blindfolded in a large room with other people. We want to find out who of your friends **is** there and who of your friends **isn't** there: +Imagine you're blindfolded in a large room with other people. We want to find out who of your friends **is** present and who of your friends **isn't** present: ![First Picture](https://i.imgur.com/FOubz6T.png) @@ -62,92 +61,94 @@ Some of the people in the room periodically make sounds (e.g., eating a chip, sn ![Second Picture](https://i.imgur.com/UwPJIMM.png) -Here's the problem. You can’t just shout “WHO’S HERE” because then everyone would say their name at the same time and you couldn’t tell anything apart. That won't work. Obviously, you also can't simply ask "WHO ISN'T HERE." That's a pretty foolish suggestion... - -So, what about taking attendance like in a classroom? Great idea! Everyone in the room agrees beforehand to respond to an attendance call **only** when their own name is shouted. That way you can actually hear whether someone responds. Neat! +Here's the problem. You can’t just shout “WHO’S HERE” because then everyone would say their name at the same time and you couldn’t tell anything apart. Similarly, for obvious reasons, you can't simply ask "WHO ISN'T HERE?" -Since you're blindfolded, you don't know how big the room is. That means you have take attendance loudly because we don't want our friends to not hear their name being called - taking attendance quietly simply won't do. +So, you take attendance like in a classroom. Everyone in the room responds **only** when their own name is shouted. ![Third Picture](https://i.imgur.com/VCW8AmH.png) -Ok, now how can you figure out which of your friends are in the room? If your friends say a name out loud randomly ("[Alan!](https://www.youtube.com/watch?v=RFhNJ8ozDBk)") it’s easy to know if they’re present or absent - all you have to do is listen for them in the din of the crowd. For most of your friends though, you need to take attendance from a list shouting names one at a time. All other sounds you hear in the room are totally anonymous ... you have no idea who made what sound. - -So, one way to take attendance is to shout for each friend on a list by name, one at a time, repeatedly. Shout, get a response, wait for a moment, and ask again. +So, one way to take attendance is to shout for each friend on a list by name, one at a time, repeatedly. Ask for someone, get a response, wait for a moment, and ask again. Once a friend stops responding (for some period of time), you presume that he or she has left: ![Simple Loop](https://i.imgur.com/ijGw2qb.png) -This technique should work just fine, but there's a problem. You're constantly shouting into the room, which means that it's difficult for you to hear quiet responses and it's difficult for other people to carry on conversations. What else can we do? +This technique should work just fine, but there's a minor problem. You're constantly shouting into the room, which means that it's difficult for you to hear quiet responses and it's difficult for other people to carry on conversations. What else can we do? Can we use those random sounds for anything? -A smarter approach is to wait for an anonymous sound, *then* start asking whether your friend is there: +Yes! A smarter approach is to wait for an anonymous sound, *then* start asking whether a friend *you know isn't present* has just arrived: ![Complex Loop](https://i.imgur.com/9Ugn27i.png) +This way, you're not constantly asking the room for all of your friends. Efficient! + This technique is a very simplified description of how `montior` works for devices like cell phones (friends on a list) and beacons (announce a name out loud). This also gives an idea of how `monitor` uses anonymous sounds to reduce the number of times that it has to send inquiries into the Bluetooth environment. ___ -# *Oversimplified Technical Description* +# *Oversimplified Technical Background* -The Bluetooth Low Energy 4.0 spec was designed to make connecting Bluetooth devices simpler for the user. No more pin codes, no more code verifications, no more “discovery mode” - for the most part. It was also designed to be much more private than previous Bluetooth specs. But it’s hard to maintain privacy when you want to be able to connect to an unknown device without user intervention, so a compromise was made. The following is oversimplified and not technically accurate in most cases, but should give the reader a gist of how `monitor` determines presence. +The Bluetooth Low Energy spec was designed to make connecting Bluetooth devices simpler for the user. No more pin codes, no more code verifications, no more “discovery mode” - for the most part. It was also designed to be more private than previous Bluetooth implementations. That said, it’s hard to maintain privacy when you want to be able to connect to an unknown device without intervention. ## Name Requests -A part of the Blueooth spec is a special function called a `name` request that asks another Bluetooth device to send back a human-readable name of itself. In order to send a `name` request, we need to know a private (unchanging) address of the target device. +A part of the Blueooth spec is a special function called a `name` request that asks another Bluetooth device to send back a human-readable name of itself. In order to send a `name` request, however, we need to know a private (unchanging) address of the target device. -Issuing a `name` request to the same private mac address every few seconds is a reliable - albeit rudimentary - way of detecting whether that device is "**present**" (it responds to the `name` request) or "**absent**" (no response to the `name` request is received). However, issuing `name` requests too frequently (*e.g.*, every few seconds) uses quite a bit of 2.4GHz spectrum, which can cause substantial interference with Wi-Fi or other wireless communications. +Issuing a `name` request to the same private mac address every few seconds is a reliable - albeit rudimentary - way of detecting whether that device is "**present**" (it responds to the `name` request) or "**absent**" (no response to the `name` request is received). However, issuing `name` requests too frequently (*e.g.*, every few seconds) uses quite a bit of 2.4GHz spectrum, which can cause interference with Wi-Fi or other wireless communications. -## Connectable Devices +Not all devices respond to `name` requests, however. For example, beacon devices do not respond. -Blueooth devices that can exchange information with other devices (almost always) advertise a random/anonymous address that other devices can use to negotiate a secure connection with that device's real, private, Bluetooth address. +## Connectible Devices -Using a random address when publicly advertising prevents baddies from tracking people via Bluetooth monitoring. This is because monitoring for anonymous advertisement is not a reliable way to detect whether a device is **present** or **absent**. However, nearly all connectible devices respond to `name` requests if made to the device's private Bluetooth address. +Blueooth devices that can exchange information with other devices (almost always) advertise a random/anonymous address that other devices can use to negotiate a secure connection and receive the first device's real, private, Bluetooth address. Using a random address in this way when publicly advertising prevents bad actors from tracking via passive Bluetooth monitoring. -## Beacon Devices +## Beacon/Advertising Devices -The Bluetooth spec has been used by Apple, Google, and others to create additional standards (e.g., iBeacon, Eddystone, and so on). These devices generally don't care to connect to other devices, so their random/anonymous addresses don't really matter. Instead, these devices encode additional information into each advertisement of an anonymous address. For example, iBeacon devices will broadcast a UUID that conforms to the 8-4-4-4-12 format defined by [IETC RFC4122](http://www.ietf.org/rfc/rfc4122.txt). +The Bluetooth spec has been used by Apple, Google, and others to create additional standards (e.g., iBeacon, Eddystone, and so on). These devices generally don't care to connect to other devices, so use of random/anonymous addresses doesn't really matter. Instead, these devices encode additional information into each advertisement of an anonymous address. For example, iBeacon devices will broadcast a UUID that conforms to the 8-4-4-4-12 format defined by [IETC RFC4122](http://www.ietf.org/rfc/rfc4122.txt). -Beacons do not respond to `name` requests, even if made to the device's private Bluetooth address. So, issuing periodic `name` requests to beacons is not a reliable way to detect whether a beacon device is **present** or **absent**. However, monitoring for beacon advertisement is a reliable way to detect whether a beacon device is **present** or **absent**. +As noted above, most beacons do not respond to `name` requests, even if made to the device's private Bluetooth address. So, issuing periodic `name` requests to beacons is not a good way to detect whether a beacon device is **present** or **absent**. However, monitoring for beacon advertisement is a reliable way to detect whether a beacon device is **present** or **absent**. _____ # *How `monitor` Works* -This script combines `name` requests, anonymous advertisements, and beacon advertisements to logically determine (1) *when* to issue a `name` scan to determine whether a device is **present** and (2) *when* to issue a `name` scan to determine whether a device is **absent**. The script also listens for beacons. +This script combines `name` requests, anonymous advertisements, and beacon advertisements to logically determine (1) *when* to issue a `name` request to determine whether a device is **present** and (2) *when* to issue a `name` request to determine whether a device is **absent**. The script also listens for beacons. ##### Known Static Addresses -More specifically, `monitor` accesses private mac addresses that you have added to a file called `known_static_addresses`. These are the addresses for which `monitor` will issue `name` requests to determine whether or not these devices are **present** or **absent**. +`monitor` uses unchanging/static mac addresses for your devices that you have added to a file called `known_static_addresses`. These are the addresses for which `monitor` will issue `name` requests to determine whether or not these devices are **present** or **absent**. -Once a determination of presence is made, the script posts to an mqtt topic path defined in a file called `mqtt_preferences` that includes a JSON-formatted message with a confidence value that corresponds to a confidence of presence. For example, a confidence of 100 means that `monitor` is 100% sure the device is present and present. Similarly, a confidence of 0 means that `monitor` is 0% sure the device is present (*i.e.*, the `monitor` is 100% sure the device is absent). +Once a determination of presence is made, the script posts to an mqtt topic path defined in a file called `mqtt_preferences` that includes a JSON-formatted message with a confidence value that corresponds to a confidence of presence. For example, a confidence of 100 means that `monitor` is 100% sure the device is present. Similarly, a confidence of 0 means that `monitor` is 0% sure the device is present (*i.e.*, the `monitor` is 100% sure the device is absent). -To minimize the number of times that `monitor` issues `name` requests (thereby reducing 2.4GHz interference), the script performs either an ***ARRIVAL*** scan or a ***DEPART*** scan, instead of scanning all devices listed in the `known_static_addresses` each time. More specifically: +To minimize the number of times that `monitor` issues `name` requests (thereby reducing 2.4GHz interference), the script performs either an ***ARRIVAL*** scan or a ***DEPART*** scan, instead of scanning all devices listed in the `known_static_addresses` each time. -* An ***ARRIVAL*** scan issues a `name` request *only* for devices from the `known_static_addresses` file that are known to be **absent**. +More specifically: -* Similarly, a ***DEPART*** scan issues a `name` request *only* for devices from the `known_static_addresses` file that are known to be **present**. +* An ***ARRIVAL*** scan issues a `name` request, sequentially, for each device listed in the `known_static_addresses` file that is known to be **absent**. + +* Similarly, a ***DEPART*** scan issues a `name` request, sequentially, for each device listed in the `known_static_addresses` file that is known to be **present**. For example, if there are two phone addresses listed in the `known_static_addresses` file, and both of those devices are **present**, an ***ARRIVAL*** scan will never occur. Similarly, if both of these addresses are **absent** then a ***DEPART*** scan will never occur. If only one device is present, an **ARRIVAL** scan will only scan for the device that is currently away. -To reduce the number of `name` scans that occur, `monitor` listens for anonymous advertisements and triggers an ***ARRIVAL*** scan for every *new* anonymous address. +To reduce the number of `name` requests that occur, `monitor` listens for anonymous advertisements and triggers an ***ARRIVAL*** scan for every *new* anonymous address. The script will also trigger an ***ARRIVE*** scan in response to an mqtt message posted to the topic of `monitor/scan/arrive`. Advertisement-triggered scanning can be disabled by using the trigger argument if `-ta`, which causes `monitor` to *only* trigger ***ARRIVAL*** scans in response to mqtt messages. If `monitor` has not heard from a particular anonymous address in a long time, `monitor` triggers a ***DEPART*** scan. The script will also trigger a ***DEPART*** scan in response to an mqtt message posted to the topic of `monitor/scan/depart`. Expiration-triggered scanning can be disabled by using the trigger argument if `-td`, which causes `monitor` to *only* trigger ***DEPART*** scans in response to mqtt messages. -To reduce scanning even further, `monitor` can filter which types of anonymous advertisements are used for ***ARRIVE*** scans. These are called "filters" and are defined in a file called `behavior_preferences`. The filters are bash RegEx strings that either pass or reject anonymous advertisements that match the filter. There are two filter types: +To reduce scanning even further, `monitor` can filter which types of anonymous advertisements are used for ***ARRIVE*** scans. These are called "filters" and are defined in a file called `behavior_preferences`. The filters are bash RegEx strings that either pass or reject anonymous advertisements that match the filter. + +There are two filter types: * **Manufacturer Filter** - filters based on data in an advertisement that is connected to a particular device manufacturer. This is almost always the OEM of the device that is transmitting the anonymous advertisement. By default, because of the prevalence of iPhones, Apple is the only manufacturer that triggers an ***ARRIVAL*** scan. Multiple manufacturers can be appended together by a pipe: `|`. An example filter for Apple and Samsung looks like: `Apple|Samsung`. To disable the manufacturer filter, use `.*`. * **Flag Filter:** filters based on flags contained in an advertisement. This varies by device type. By default, because of the prevalence of iPhones, the flag of `0x1b` triggers an ***ARRIVAL*** scan. Like with the manufacturer filter, multiple flags can be appended together by a pipe: `|`. To disable the manufacturer filter, use `.*`. ##### Beacons & iBeacons -In addition, once installed and run with the `-b` beacon argument, `monitor` listens for beacon advertisements that report themselves as "public", meaning that their addresses will not change. The script can track these by default; these addresses do not have to be added anywhere - after all, `monitor` will obtain them just by listening. +In addition, when run with the `-b` beacon argument, `monitor` listens for beacon advertisements that report themselves as "public", meaning that their addresses will not change. The script can track these by default; these addresses do not have to be added anywhere - after all, `monitor` will obtain them just by listening. Since iBeacons include a UUID and a mac address, two presence messages are reported via mqtt. ## Known Beacon Addresses -In some cases, certain manufacturers try to get sneaky and cause their beacons to advertise as "anonymous" (or "random") devices, despite that their addresses do not change at all. By default, `monitor` ignores anonymous devices, so to force `monitor` to recognize these devices, we add the "random" address to a file called `known_static_beacons`. After restarting, `monitor` will know that these addresses should be treated like a normal beacon. +In some cases, manufacturers try to get sneaky and cause their beacons to advertise as "anonymous" (or "random") devices, despite that their addresses do not change at all. By default, `monitor` does not report presence of anonymous advertisement devices, so to force `monitor` to recognize these devices, we add the "random" address to a file called `known_static_beacons`. After restarting, `monitor` will know that these addresses should be treated like a normal beacon. ___ @@ -258,7 +259,7 @@ git clone git://github.com/andrewjfreyer/monitor #enter `monitor` directory cd monitor/ -#switch to beta branch for latest updates and features (may be instable) +#(optional) switch to beta branch for latest updates and features (may be unstable) git checkout beta ``` @@ -473,7 +474,7 @@ Similarly, we can create a negative filter. If you or your neighbors use Google PREF_FAIL_FILTER_MANUFACTURER_ARRIVE="Google" ``` -Filters are a great way to minimize the frequency of `name` scanning, which causes 2.4GHz interference and can, if your values are too aggressive, dramatically interfere with Wi-Fi and other services. +Filters are a great way to minimize the frequency of `name` requestning, which causes 2.4GHz interference and can, if your values are too aggressive, dramatically interfere with Wi-Fi and other services. 2. **Standard configuration options:** @@ -498,7 +499,7 @@ In addition to the options described above, there are a number of advanced optio | **Option** | **Default Value** | **Description** | |-|-|-| -PREF_INTERSCAN_DELAY|3|This is a fixed delay between `name` scans. Increasing the value will decrease interference, but will decrease responsiveness. Decreasing the value will risk a Bluetooth hardware fault.| +PREF_INTERSCAN_DELAY|3|This is a fixed delay between `name` requests. Increasing the value will decrease interference, but will decrease responsiveness. Decreasing the value will risk a Bluetooth hardware fault.| PREF_RANDOM_DEVICE_EXPIRATION_INTERVAL|75|This is the interval after which an anonymous advertisement mac address is considered expired. Increasing this value will reduce arrival scan frequency, but will also increase memory footprint (minimal) and will decrease the frequency of depart scans.| PREF_RSSI_CHANGE_THRESHOLD|-20|If a beacon's rssi changes by at least this value, then the beacon will be reported again via mqtt.| PREF_RSSI_IGNORE_BELOW|-75|If an anonymous advertisement is "farther" away (lower RSSI), ignore the advertisement @@ -541,33 +542,6 @@ message: -99 through 0 If an rssi measurement cannot be obtained, the value of -99 is sent. -3. Using the rssi data for something: - -I strongly recommend using a filter to smooth the rssi data. An example for Home Assistant follows: - - -```yaml -sensor: - - - platform: mqtt - state_topic: 'location/first floor/34:08:BC:15:24:F7/rssi' - name: 'Andrew First Floor RSSI raw' - unit_of_measurement: 'dBm' - - - platform: filter - name: "Andrew First Floor RSSI" - entity_id: sensor.andrew_first_floor_rssi_raw - filters: - - filter: outlier - window_size: 2 - radius: 1.0 - - filter: lowpass - time_constant: 2 - - filter: time_simple_moving_average - window_size: 00:01 - precision: 1 -``` - Anything else? Post a [question.](https://github.com/andrewjfreyer/monitor/issues/new) diff --git a/support/README.md b/support/README.md index 559754ea..b04d3304 100644 --- a/support/README.md +++ b/support/README.md @@ -15,7 +15,8 @@ ____ #### Will this be able to track my Apple Watch/Smart Watch? -Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. +Answer Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. + #### What special app do I need on my phone to get this to work? From 548ff39281f2ec40951e27b53a5451fa3fc1251a Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:43:45 -0600 Subject: [PATCH 37/50] 0.2.196 --- support/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/support/README.md b/support/README.md index b04d3304..9fa47fc0 100644 --- a/support/README.md +++ b/support/README.md @@ -15,8 +15,9 @@ ____ #### Will this be able to track my Apple Watch/Smart Watch? -Answer Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. - +
Answer + Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. +
#### What special app do I need on my phone to get this to work? From 9a611c3656e428c925497b4240636c90ed35d26e Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:44:38 -0600 Subject: [PATCH 38/50] 0.2.196 --- support/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/README.md b/support/README.md index 9fa47fc0..16670c86 100644 --- a/support/README.md +++ b/support/README.md @@ -15,7 +15,7 @@ ____ #### Will this be able to track my Apple Watch/Smart Watch? -
Answer +
Show Detailed Answer

Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones.

From 9979b7815dea631b40501b10c50c354905e3702e Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:45:24 -0600 Subject: [PATCH 39/50] 0.2.196 --- support/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/support/README.md b/support/README.md index 16670c86..c2aa2df7 100644 --- a/support/README.md +++ b/support/README.md @@ -13,9 +13,8 @@ ____ ## *Monitor Basics* -#### Will this be able to track my Apple Watch/Smart Watch? +####
Will this be able to track my Apple Watch/Smart Watch? -
Show Detailed Answer

Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones.

From a7820fd5a0c31a64ac64372435fbd2b834a88cf4 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:46:16 -0600 Subject: [PATCH 40/50] 0.2.196 --- support/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/README.md b/support/README.md index c2aa2df7..c0b0f9af 100644 --- a/support/README.md +++ b/support/README.md @@ -15,7 +15,7 @@ ____ ####
Will this be able to track my Apple Watch/Smart Watch? - Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. +Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones.
#### What special app do I need on my phone to get this to work? From 8d4798a0672e8d165b0e3e451cb2211e6fac99be Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:46:52 -0600 Subject: [PATCH 41/50] 0.2.196 --- support/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/support/README.md b/support/README.md index c0b0f9af..1b4518fa 100644 --- a/support/README.md +++ b/support/README.md @@ -13,7 +13,8 @@ ____ ## *Monitor Basics* -####
Will this be able to track my Apple Watch/Smart Watch? +
+#### Will this be able to track my Apple Watch/Smart Watch? Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones.
From 5b50a773dfeab78c220e76de9d02ef4c0733914d Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:47:48 -0600 Subject: [PATCH 42/50] 0.2.196 --- support/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/README.md b/support/README.md index 1b4518fa..167a6ae1 100644 --- a/support/README.md +++ b/support/README.md @@ -13,9 +13,9 @@ ____ ## *Monitor Basics* -
-#### Will this be able to track my Apple Watch/Smart Watch? +#### Will this be able to track my Apple Watch/Smart Watch? +
Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones.
From 1924f86ad51ce70d9624a3bd609d9c853c80f77a Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:50:52 -0600 Subject: [PATCH 43/50] 0.2.196 --- support/README.md | 86 ++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/support/README.md b/support/README.md index 167a6ae1..25404be6 100644 --- a/support/README.md +++ b/support/README.md @@ -1,41 +1,29 @@ # *Frequenty Asked Questions:* -[***Basics***](#monitor-basics) - -[***Wi-Fi Interference & Performance***](#wi-fi-interference--performance-issues) - -[***Debugging***](#monitor-logs--debugging) - -[***Filters***](#filters) - -[***Miscellaneous***](#other-questions) - ____ -## *Monitor Basics* +## *Basics* -#### Will this be able to track my Apple Watch/Smart Watch? +
Will this be able to track my Apple Watch/Smart Watch? -
Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. -
-#### What special app do I need on my phone to get this to work? +
What special app do I need on my phone to get this to work? None, except in rare circumstances. The only requirement is that Bluetooth is left on. Works best with iPhones and Android phones that have peripheral mode enabled. -#### Does `monitor` reduce battery life for my phone? +
Does `monitor` reduce battery life for my phone? Not noticeable in my several years of using techniques similar to this. -#### How can I trigger an arrival scan? +
How can I trigger an arrival scan? Post a message with blank content to `monitor/scan/arrive` -#### How can I trigger an depart scan? +
How can I trigger an depart scan? Post a message with blank content to `monitor/scan/depart` -#### How can I trigger an arrive/depart scan from an automation in Home Assistant? +
How can I trigger an arrive/depart scan from an automation in Home Assistant? For an automation or script (or other service trigger), use: @@ -51,19 +39,19 @@ For an automation or script (or other service trigger), use: topic: location/scan/depart ``` -#### How can I add a known device without manually entering an address? +
How can I add a known device without manually entering an address? Post a message with the mac address separated from an alias (optional) by a space to: `monitor/setup/add known device` -#### How can I delete a known device without manually editing an address? +
How can I delete a known device without manually editing an address? Post a message with the mac address to: `monitor/setup/delete known device` -#### How can I upgrade to the latest version without using ssh? +
How can I upgrade to the latest version without using ssh? Post a message with blank content to `monitor/scan/update` or `monitor/scan/updatebeta` -#### How can I restart a `monitor` node? +
How can I restart a `monitor` node? Via command line: @@ -73,11 +61,11 @@ sudo systemctl restart monitor Or, post a message with blank content to `monitor/scan/restart` -#### Why don't I see RSSI for my iPhone/Andriod/whatever phone? +
Why don't I see RSSI for my iPhone/Andriod/whatever phone? See the RSSI section of this FAQ. You'll have to connect your phone to `monitor` first. -#### How do I force an RSSI update for a known device, like my phone? +
How do I force an RSSI update for a known device, like my phone? Post a message with blank content to `monitor/scan/rssi` @@ -85,42 +73,42 @@ ____ ## *Wi-Fi Interference & Performance Issues* -#### I'm running 5GHz Wi-Fi, I don't use Bluetooth for anything else, and I don't care whether I interfere with my neighbor's devices. Can't I just issue a name scan every few seconds to get faster arrival and depart detection? +
I'm running 5GHz Wi-Fi, I don't use Bluetooth for anything else, and I don't care whether I interfere with my neighbor's devices. Can't I just issue a name scan every few seconds to get faster arrival and depart detection? Yes, use periodic scanning mode with `-r`. -#### Can I use other Bluetooth services while `monitor` is running? +
Can I use other Bluetooth services while `monitor` is running? No. Monitor needs exclusive use of the Bluetooth radio to function properly. This is why it is designed to run on inexpensive hardware like the Raspberry Pi Zero W. -#### Can `monitor` run on XYZ hardware or in XYZ container? +
Can `monitor` run on XYZ hardware or in XYZ container? Probably. The script has been designed to minimize dependencies as much as possible. That said, I can't guarantee or provide support to all systems. -#### Does `monitor` interfere with Wi-Fi, Zigbee, or Zwave? +
Does `monitor` interfere with Wi-Fi, Zigbee, or Zwave? It can, if it scans too frequently, especially if you're running `monitor` from internal Raspberry Pi radios. Try to use all techniques for reducing `name` scans, including using trigger-only depart mode `-tdr`. When in this mode, `monitor` will never scan when all devices are home. Instead, `monitor` will wait until a `monitor/scan/depart` message is sent. Personally, I use my front door lock as a depart scan trigger. -#### How can I check if a `monitor` node is up and hasn't shut down for some reason? +
How can I check if a `monitor` node is up and hasn't shut down for some reason? Post a message to `monitor/scan/echo`, and you'll receive a response at the topic `$mqtt_topicpath/$mqtt_publisher_identity/echo` -#### I *still* have interference and/or my ssh sessions to the raspberry pi are really slow and laggy. What gives? +
I *still* have interference and/or my ssh sessions to the raspberry pi are really slow and laggy. What gives? Cheap Wi-Fi chipsets and cheap Bluetooth chipsets can perform poorly together if operated at the same time, especially on Raspberry Pi devices. If you still experience interference in your network, switching to a Wi-Fi dongle can help. -#### I use a Bluetooth dongle, and `monitor` seems to become non-responsive after a while - what's going on? +
I use a Bluetooth dongle, and `monitor` seems to become non-responsive after a while - what's going on? Many Bluetooth dongles do not properly filter out duplicate advertisements, so `monitor` gets overwhelmed trying to filter out hundreds of reports, when it expects dozens. I'm working on a solution, but for now the best option is to switch to internal Bluetooth or, alternatively, you can try another Bluetooth dongle. ___ ## *Monitor Logs & Debugging* -#### I keep seeing that my Bluetooth hardware is "cycling" in the logs - what does that mean? +
I keep seeing that my Bluetooth hardware is "cycling" in the logs - what does that mean? If more than one program or executable try to use the Bluetooth hardware at the same time, your Bluetooth hardware will report an error. To correct this error, the hardware needs to be taken offline, then brought back. -#### I can't do **XYZ**, is `monitor` broken? +
I can't do **XYZ**, is `monitor` broken? Run via command line and post log output to github. Else, access `journalctl` to show the most recent logs: @@ -128,35 +116,35 @@ Run via command line and post log output to github. Else, access `journalctl` to journalctl -u monitor -r ``` -#### My Android phone doesn't seem to send any anonymous advertisements, no matter what I do. Is there any solution? +
My Android phone doesn't seem to send any anonymous advertisements, no matter what I do. Is there any solution? -Some phones, like the LG ThinQ G7 include an option in settings to enable file sharing via bluetooth. As resported by Home Assistant forum user @jusdwy, access this option via Settings >Connected Devices > File Sharing > File Sharing ON. For other android phones, an app like [Beacon Simulator](https://play.google.com/store/apps/details?id=net.alea.beaconsimulator&hl=en_US) may be a good option. You may also be able to see more information about Bluetooth on your phone using [nRF Connect](https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en_US). +Some phones, like the LG ThinQ G7 include an option in settings to enable file sharing via bluetooth. As resported by Home Assistant forum user @jusdwy, access this option via Settings >Connected Devices > File Sharing > File Sharing ON. For other android phones, an app like [Beacon Simulator](https://play.google.com/store/apps/details?id=net.alea.beaconsimulator&hl=en_US) may be a good option. You may also be able to see more information about Bluetooth on your phone using [nRF Connect](https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en_US). Unfortunately, until Android OS includes at least one service that requires bluetooth peripheral mode to be enabled, Android devices will probably not advertise without an application running in the background. In short, as I understand it, Android/Google has been slow to adopt BTLE peripheral mode as an option in addition to the default central mode. [Here is a decently comprehensive list of phones that support peripheral mode](https://altbeacon.github.io/android-beacon-library/beacon-transmitter-devices.html), should an application choose to leverage the appropriate API. It does not appear as though the native OS has an option (outside of the file sharing option mentioned above on LG phones) to enable this mode. Unfortunately, it seems to me that absent an application causing an advertisement to send, Android users will not be able to use monitor in the same way as iOS users or beacon users. -#### My phone doesn't seem to automatically broadcast an anonymous Bluetooth advertisement ... what can I do? +
My phone doesn't seem to automatically broadcast an anonymous Bluetooth advertisement ... what can I do? Many phones will only broadcast once they have already connected to *at least one* other Bluetooth device. Connect to a speaker, a car, a headset, or `monitor.sh -c [address]` and try again. -#### I have connected my phone to Bluetooth devices before but my phone doesn't seem to automatically broadcast an anonymous Bluetooth advertisement ... what can I do? +
I have connected my phone to Bluetooth devices before but my phone doesn't seem to automatically broadcast an anonymous Bluetooth advertisement ... what can I do? See above. -#### Why does my MQTT broker show connection and disconnection so often? +
Why does my MQTT broker show connection and disconnection so often? This is normal behavior for `mosquitto_pub` - nothing to worry about. -#### I updated and `monitor` is no longer working ... what gives? +
I updated and `monitor` is no longer working ... what gives? Make sure you've updated `mosquitto` to v1.5 or higher. In order to support a wider userbase, backward compatibility for old versions of `mosquitto` was dropped. It is alos strongly recommended that you upgrade to bash 4.4+. -#### I keep seeing MQTT Broker Offline messages in the `monitor` log. What's going on? +
I keep seeing MQTT Broker Offline messages in the `monitor` log. What's going on? mosquitto fails to connect to a broker if your password has certain special characters such as: `@`, `:`,`/` - if this is the case, the easiest solution is to create a new user for `monitor` with a different password. -#### Can I use a certfile for mosquitto instead of my password? +
Can I use a certfile for mosquitto instead of my password? Yes, specify a path for `mqtt_certificate_path` in mqtt_preferences. @@ -164,7 +152,7 @@ ____ ## *Filters* -#### What filters do you personally use? +
What filters do you personally use? ```bash @@ -177,11 +165,11 @@ PREF_FAIL_FILTER_MANUFACTURER_ARRIVE=\"Google|Samsung\" PREF_FAIL_FILTER_MANUFACTURER_ARRIVE=\"NONE\" ``` -#### What are the default filters for the PDU filter option? +
What are the default filters for the PDU filter option? ```ADV_IND|ADV_SCAN_IND|ADV_NONCONN_IND|SCAN_RSP``` -#### How do I use this as a device_tracker, in addition to the standard confidence messages? +
How do I use this as a device_tracker, in addition to the standard confidence messages? Set the option `PREF_DEVICE_TRACKER_REPORT` in your `behavior_preferences` file to true. If it's not there, add a line like this: @@ -203,7 +191,7 @@ device_tracker: The standard confidence report will also send. -#### How do I determine what values to set for filters? +
How do I determine what values to set for filters? Try using the verbose logging option `-V` to see what `monitor` sees when a new bluetooth device advertisement is seen. Then, power cycle the bluetooth radio on the device you'd like to track - you'll probably see a pattern develop with flags or manufacturers. Use these values to create your arrival filters! @@ -213,7 +201,7 @@ ____ ## *Other Questions* -#### It's annoying to have to keep track of mac addresses. Can't I just use a nickname for the mac addresses for MQTT topics? +
It's annoying to have to keep track of mac addresses. Can't I just use a nickname for the mac addresses for MQTT topics? Yes, this is now default behavior. All you have to do is provide a name next to the address in the `known_static_addresses` file. For example, if you have a known device with the mac address of 00:11:22:33:44:55 that you would like to call "Andrew's Phone": @@ -237,11 +225,11 @@ The same is true for beacons in the `known_beacon_addresses` file as well: To disable this feature, set `PREF_ALIAS_MODE=false` in your `behavior_preferences` file. -#### I don't care about a few devices that are reporting. Can I block them? +
I don't care about a few devices that are reporting. Can I block them? Yes. Create a file called `address_blacklist` in your configuration directory and add the mac addresses you'd like to block (or uuid-major-minor for iBeacons) one at a time. -#### I can't use the `device_tracker` platform with the default status strings of `home` and `not_home` with my home automation software. What can I do? +
I can't use the `device_tracker` platform with the default status strings of `home` and `not_home` with my home automation software. What can I do? Set these options in `behavior_preferences`: From 64d0607883b0bd842488241878d63c19da204220 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:54:13 -0600 Subject: [PATCH 44/50] 0.2.196 --- support/README.md | 116 ++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 41 deletions(-) diff --git a/support/README.md b/support/README.md index 25404be6..84880ca3 100644 --- a/support/README.md +++ b/support/README.md @@ -3,27 +3,33 @@ ____ ## *Basics* -
Will this be able to track my Apple Watch/Smart Watch? +
Will this be able to track my Apple Watch/Smart Watch?

Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. -

What special app do I need on my phone to get this to work? +
+ +
What special app do I need on my phone to get this to work?

None, except in rare circumstances. The only requirement is that Bluetooth is left on. Works best with iPhones and Android phones that have peripheral mode enabled. +

-
Does `monitor` reduce battery life for my phone? +
Does `monitor` reduce battery life for my phone?

Not noticeable in my several years of using techniques similar to this. +

-
How can I trigger an arrival scan? +
How can I trigger an arrival scan?

Post a message with blank content to `monitor/scan/arrive` +

-
How can I trigger an depart scan? +
How can I trigger an depart scan?

Post a message with blank content to `monitor/scan/depart` +

-
How can I trigger an arrive/depart scan from an automation in Home Assistant? +
How can I trigger an arrive/depart scan from an automation in Home Assistant?

For an automation or script (or other service trigger), use: @@ -38,20 +44,24 @@ For an automation or script (or other service trigger), use: data: topic: location/scan/depart ``` +

-
How can I add a known device without manually entering an address? +
How can I add a known device without manually entering an address?

Post a message with the mac address separated from an alias (optional) by a space to: `monitor/setup/add known device` +

-
How can I delete a known device without manually editing an address? +
How can I delete a known device without manually editing an address?

Post a message with the mac address to: `monitor/setup/delete known device` +

-
How can I upgrade to the latest version without using ssh? +
How can I upgrade to the latest version without using ssh?

Post a message with blank content to `monitor/scan/update` or `monitor/scan/updatebeta` +

-
How can I restart a `monitor` node? +
How can I restart a `monitor` node?

Via command line: @@ -60,99 +70,115 @@ sudo systemctl restart monitor ``` Or, post a message with blank content to `monitor/scan/restart` +

-
Why don't I see RSSI for my iPhone/Andriod/whatever phone? +
Why don't I see RSSI for my iPhone/Andriod/whatever phone?

See the RSSI section of this FAQ. You'll have to connect your phone to `monitor` first. +

-
How do I force an RSSI update for a known device, like my phone? +
How do I force an RSSI update for a known device, like my phone?

Post a message with blank content to `monitor/scan/rssi` +

+ ____ ## *Wi-Fi Interference & Performance Issues* -
I'm running 5GHz Wi-Fi, I don't use Bluetooth for anything else, and I don't care whether I interfere with my neighbor's devices. Can't I just issue a name scan every few seconds to get faster arrival and depart detection? +
I'm running 5GHz Wi-Fi, I don't use Bluetooth for anything else, and I don't care whether I interfere with my neighbor's devices. Can't I just issue a name scan every few seconds to get faster arrival and depart detection?

Yes, use periodic scanning mode with `-r`. +

-
Can I use other Bluetooth services while `monitor` is running? +
Can I use other Bluetooth services while `monitor` is running?

No. Monitor needs exclusive use of the Bluetooth radio to function properly. This is why it is designed to run on inexpensive hardware like the Raspberry Pi Zero W. +

-
Can `monitor` run on XYZ hardware or in XYZ container? +
Can `monitor` run on XYZ hardware or in XYZ container?

Probably. The script has been designed to minimize dependencies as much as possible. That said, I can't guarantee or provide support to all systems. +

-
Does `monitor` interfere with Wi-Fi, Zigbee, or Zwave? +
Does `monitor` interfere with Wi-Fi, Zigbee, or Zwave?

It can, if it scans too frequently, especially if you're running `monitor` from internal Raspberry Pi radios. Try to use all techniques for reducing `name` scans, including using trigger-only depart mode `-tdr`. When in this mode, `monitor` will never scan when all devices are home. Instead, `monitor` will wait until a `monitor/scan/depart` message is sent. Personally, I use my front door lock as a depart scan trigger. +

-
How can I check if a `monitor` node is up and hasn't shut down for some reason? +
How can I check if a `monitor` node is up and hasn't shut down for some reason?

Post a message to `monitor/scan/echo`, and you'll receive a response at the topic `$mqtt_topicpath/$mqtt_publisher_identity/echo` +

-
I *still* have interference and/or my ssh sessions to the raspberry pi are really slow and laggy. What gives? +
I *still* have interference and/or my ssh sessions to the raspberry pi are really slow and laggy. What gives?

Cheap Wi-Fi chipsets and cheap Bluetooth chipsets can perform poorly together if operated at the same time, especially on Raspberry Pi devices. If you still experience interference in your network, switching to a Wi-Fi dongle can help. +

-
I use a Bluetooth dongle, and `monitor` seems to become non-responsive after a while - what's going on? +
I use a Bluetooth dongle, and `monitor` seems to become non-responsive after a while - what's going on?

Many Bluetooth dongles do not properly filter out duplicate advertisements, so `monitor` gets overwhelmed trying to filter out hundreds of reports, when it expects dozens. I'm working on a solution, but for now the best option is to switch to internal Bluetooth or, alternatively, you can try another Bluetooth dongle. +

+ ___ ## *Monitor Logs & Debugging* -
I keep seeing that my Bluetooth hardware is "cycling" in the logs - what does that mean? +
I keep seeing that my Bluetooth hardware is "cycling" in the logs - what does that mean?

If more than one program or executable try to use the Bluetooth hardware at the same time, your Bluetooth hardware will report an error. To correct this error, the hardware needs to be taken offline, then brought back. +

-
I can't do **XYZ**, is `monitor` broken? +
I can't do **XYZ**, is `monitor` broken?

Run via command line and post log output to github. Else, access `journalctl` to show the most recent logs: ```bash journalctl -u monitor -r ``` +

-
My Android phone doesn't seem to send any anonymous advertisements, no matter what I do. Is there any solution? +
My Android phone doesn't seem to send any anonymous advertisements, no matter what I do. Is there any solution?

-Some phones, like the LG ThinQ G7 include an option in settings to enable file sharing via bluetooth. As resported by Home Assistant forum user @jusdwy, access this option via Settings >Connected Devices > File Sharing > File Sharing ON. For other android phones, an app like [Beacon Simulator](https://play.google.com/store/apps/details?id=net.alea.beaconsimulator&hl=en_US) may be a good option. You may also be able to see more information about Bluetooth on your phone using [nRF Connect](https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en_US). +Some phones, like the LG ThinQ G7 include an option in settings to enable file sharing via bluetooth. As resported by Home Assistant forum user @jusdwy, access this option via Settings >Connected Devices > File Sharing > File Sharing ON. For other android phones, an app like [Beacon Simulator](https://play.google.com/store/apps/details?

id=net.alea.beaconsimulator&hl=en_US) may be a good option. You may also be able to see more information about Bluetooth on your phone using [nRF Connect](https://play.google.com/store/apps/details?

id=no.nordicsemi.android.mcp&hl=en_US). Unfortunately, until Android OS includes at least one service that requires bluetooth peripheral mode to be enabled, Android devices will probably not advertise without an application running in the background. In short, as I understand it, Android/Google has been slow to adopt BTLE peripheral mode as an option in addition to the default central mode. [Here is a decently comprehensive list of phones that support peripheral mode](https://altbeacon.github.io/android-beacon-library/beacon-transmitter-devices.html), should an application choose to leverage the appropriate API. It does not appear as though the native OS has an option (outside of the file sharing option mentioned above on LG phones) to enable this mode. Unfortunately, it seems to me that absent an application causing an advertisement to send, Android users will not be able to use monitor in the same way as iOS users or beacon users. +

-
My phone doesn't seem to automatically broadcast an anonymous Bluetooth advertisement ... what can I do? +
My phone doesn't seem to automatically broadcast an anonymous Bluetooth advertisement ... what can I do?

Many phones will only broadcast once they have already connected to *at least one* other Bluetooth device. Connect to a speaker, a car, a headset, or `monitor.sh -c [address]` and try again. +

-
I have connected my phone to Bluetooth devices before but my phone doesn't seem to automatically broadcast an anonymous Bluetooth advertisement ... what can I do? - -See above. - -
Why does my MQTT broker show connection and disconnection so often? +
Why does my MQTT broker show connection and disconnection so often?

This is normal behavior for `mosquitto_pub` - nothing to worry about. +

-
I updated and `monitor` is no longer working ... what gives? +
I updated and `monitor` is no longer working ... what gives?

Make sure you've updated `mosquitto` to v1.5 or higher. In order to support a wider userbase, backward compatibility for old versions of `mosquitto` was dropped. It is alos strongly recommended that you upgrade to bash 4.4+. +

-
I keep seeing MQTT Broker Offline messages in the `monitor` log. What's going on? +
I keep seeing MQTT Broker Offline messages in the `monitor` log. What's going on?

mosquitto fails to connect to a broker if your password has certain special characters such as: `@`, `:`,`/` - if this is the case, the easiest solution is to create a new user for `monitor` with a different password. +

-
Can I use a certfile for mosquitto instead of my password? +
Can I use a certfile for mosquitto instead of my password?

Yes, specify a path for `mqtt_certificate_path` in mqtt_preferences. +

____ ## *Filters* -
What filters do you personally use? +
What filters do you personally use?

```bash @@ -164,12 +190,14 @@ PREF_PASS_FILTER_MANUFACTURER_ARRIVE=\"Apple\" PREF_FAIL_FILTER_MANUFACTURER_ARRIVE=\"Google|Samsung\" PREF_FAIL_FILTER_MANUFACTURER_ARRIVE=\"NONE\" ``` +

-
What are the default filters for the PDU filter option? +
What are the default filters for the PDU filter option?

```ADV_IND|ADV_SCAN_IND|ADV_NONCONN_IND|SCAN_RSP``` +

-
How do I use this as a device_tracker, in addition to the standard confidence messages? +
How do I use this as a device_tracker, in addition to the standard confidence messages?

Set the option `PREF_DEVICE_TRACKER_REPORT` in your `behavior_preferences` file to true. If it's not there, add a line like this: @@ -190,20 +218,22 @@ device_tracker: ``` The standard confidence report will also send. +

-
How do I determine what values to set for filters? +
How do I determine what values to set for filters?

Try using the verbose logging option `-V` to see what `monitor` sees when a new bluetooth device advertisement is seen. Then, power cycle the bluetooth radio on the device you'd like to track - you'll probably see a pattern develop with flags or manufacturers. Use these values to create your arrival filters! Similarly, to set exclude filters, you can observe bluetooth traffic for a period of time to see what devices you simply do not care about seeing. +

____ ## *Other Questions* -
It's annoying to have to keep track of mac addresses. Can't I just use a nickname for the mac addresses for MQTT topics? +
It's annoying to have to keep track of mac addresses. Can't I just use a nickname for the mac addresses for MQTT topics?

-Yes, this is now default behavior. All you have to do is provide a name next to the address in the `known_static_addresses` file. For example, if you have a known device with the mac address of 00:11:22:33:44:55 that you would like to call "Andrew's Phone": +Yes, this is default behavior. All you have to do is provide a name next to the address in the `known_static_addresses` file. For example, if you have a known device with the mac address of 00:11:22:33:44:55 that you would like to call "Andrew's Phone": ```bash 00:11:22:33:44:55 Andrew's iPhone @@ -224,12 +254,14 @@ The same is true for beacons in the `known_beacon_addresses` file as well: ``` To disable this feature, set `PREF_ALIAS_MODE=false` in your `behavior_preferences` file. +

-
I don't care about a few devices that are reporting. Can I block them? +
I don't care about a few devices that are reporting. Can I block them?

Yes. Create a file called `address_blacklist` in your configuration directory and add the mac addresses you'd like to block (or uuid-major-minor for iBeacons) one at a time. +

-
I can't use the `device_tracker` platform with the default status strings of `home` and `not_home` with my home automation software. What can I do? +
I can't use the `device_tracker` platform with the default status strings of `home` and `not_home` with my home automation software. What can I do?

Set these options in `behavior_preferences`: @@ -263,4 +295,6 @@ Generic: PREF_DEVICE_TRACKER_HOME_STRING='home' PREF_DEVICE_TRACKER_AWAY_STRING='away' PREF_DEVICE_TRACKER_TOPIC_BRANCH='anything you like' -``` \ No newline at end of file +``` + +

From 9b969039c097170778d5805c13c2013422ec7cc8 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:55:14 -0600 Subject: [PATCH 45/50] 0.2.196 --- support/README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/support/README.md b/support/README.md index 84880ca3..db53cdcd 100644 --- a/support/README.md +++ b/support/README.md @@ -5,7 +5,7 @@ ____
Will this be able to track my Apple Watch/Smart Watch?

-Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to `monitor`. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones. +Yes, with a caveat. Many users, including myself, have successfully added Apple Watch Bluetooth addresses to the `known_static_addresses` file. In my personal experience, an Apple Watch works just fine [once it has connected to at least one other Bluetooth device, apart from your iPhone](https://github.com/andrewjfreyer/monitor#my-phone-doesnt-seem-to-automatically-broadcast-an-anonymous-bluetooth-advertisement-what-can-i-do). Other users have reported that the Apple Watch will occasionally not respond to this script. Your mileage using the Apple Watch and/or other low-power connectible Bluetooth devices may vary. I strongly recommend tracking phones.

@@ -14,7 +14,7 @@ Yes, with a caveat. Many users, including myself, have successfully added Apple None, except in rare circumstances. The only requirement is that Bluetooth is left on. Works best with iPhones and Android phones that have peripheral mode enabled.
-
Does `monitor` reduce battery life for my phone?

+

Does this script reduce battery life for my phone?

Not noticeable in my several years of using techniques similar to this.

@@ -61,7 +61,7 @@ Post a message with the mac address to: `monitor/setup/delete known device` Post a message with blank content to `monitor/scan/update` or `monitor/scan/updatebeta`
-
How can I restart a `monitor` node?

+

How can I restart a this script node?

Via command line: @@ -74,7 +74,7 @@ Or, post a message with blank content to `monitor/scan/restart`

Why don't I see RSSI for my iPhone/Andriod/whatever phone?

-See the RSSI section of this FAQ. You'll have to connect your phone to `monitor` first. +See the RSSI section of this FAQ. You'll have to connect your phone to this script first.

How do I force an RSSI update for a known device, like my phone?

@@ -92,22 +92,22 @@ ____ Yes, use periodic scanning mode with `-r`.

-
Can I use other Bluetooth services while `monitor` is running?

+

Can I use other Bluetooth services while this script is running?

No. Monitor needs exclusive use of the Bluetooth radio to function properly. This is why it is designed to run on inexpensive hardware like the Raspberry Pi Zero W.

-
Can `monitor` run on XYZ hardware or in XYZ container?

+

Can this script run on XYZ hardware or in XYZ container?

Probably. The script has been designed to minimize dependencies as much as possible. That said, I can't guarantee or provide support to all systems.

-
Does `monitor` interfere with Wi-Fi, Zigbee, or Zwave?

+

Does this script interfere with Wi-Fi, Zigbee, or Zwave?

-It can, if it scans too frequently, especially if you're running `monitor` from internal Raspberry Pi radios. Try to use all techniques for reducing `name` scans, including using trigger-only depart mode `-tdr`. When in this mode, `monitor` will never scan when all devices are home. Instead, `monitor` will wait until a `monitor/scan/depart` message is sent. Personally, I use my front door lock as a depart scan trigger. +It can, if it scans too frequently, especially if you're running this script from internal Raspberry Pi radios. Try to use all techniques for reducing `name` scans, including using trigger-only depart mode `-tdr`. When in this mode, this script will never scan when all devices are home. Instead, this script will wait until a `monitor/scan/depart` message is sent. Personally, I use my front door lock as a depart scan trigger.

-
How can I check if a `monitor` node is up and hasn't shut down for some reason?

+

How can I check if a this script node is up and hasn't shut down for some reason?

Post a message to `monitor/scan/echo`, and you'll receive a response at the topic `$mqtt_topicpath/$mqtt_publisher_identity/echo`

@@ -117,9 +117,9 @@ Post a message to `monitor/scan/echo`, and you'll receive a response at the topi Cheap Wi-Fi chipsets and cheap Bluetooth chipsets can perform poorly together if operated at the same time, especially on Raspberry Pi devices. If you still experience interference in your network, switching to a Wi-Fi dongle can help.
-
I use a Bluetooth dongle, and `monitor` seems to become non-responsive after a while - what's going on?

+

I use a Bluetooth dongle, and this script seems to become non-responsive after a while - what's going on?

-Many Bluetooth dongles do not properly filter out duplicate advertisements, so `monitor` gets overwhelmed trying to filter out hundreds of reports, when it expects dozens. I'm working on a solution, but for now the best option is to switch to internal Bluetooth or, alternatively, you can try another Bluetooth dongle. +Many Bluetooth dongles do not properly filter out duplicate advertisements, so this script gets overwhelmed trying to filter out hundreds of reports, when it expects dozens. I'm working on a solution, but for now the best option is to switch to internal Bluetooth or, alternatively, you can try another Bluetooth dongle.

___ @@ -131,7 +131,7 @@ ___ If more than one program or executable try to use the Bluetooth hardware at the same time, your Bluetooth hardware will report an error. To correct this error, the hardware needs to be taken offline, then brought back.
-
I can't do **XYZ**, is `monitor` broken?

+

I can't do **XYZ**, is this script broken?

Run via command line and post log output to github. Else, access `journalctl` to show the most recent logs: @@ -159,14 +159,14 @@ Many phones will only broadcast once they have already connected to *at least on This is normal behavior for `mosquitto_pub` - nothing to worry about.

-
I updated and `monitor` is no longer working ... what gives?

+

I updated and this script is no longer working ... what gives?

Make sure you've updated `mosquitto` to v1.5 or higher. In order to support a wider userbase, backward compatibility for old versions of `mosquitto` was dropped. It is alos strongly recommended that you upgrade to bash 4.4+.

-
I keep seeing MQTT Broker Offline messages in the `monitor` log. What's going on?

+

I keep seeing MQTT Broker Offline messages in the this script log. What's going on?

-mosquitto fails to connect to a broker if your password has certain special characters such as: `@`, `:`,`/` - if this is the case, the easiest solution is to create a new user for `monitor` with a different password. +mosquitto fails to connect to a broker if your password has certain special characters such as: `@`, `:`,`/` - if this is the case, the easiest solution is to create a new user for this script with a different password.

Can I use a certfile for mosquitto instead of my password?

@@ -207,7 +207,7 @@ PREF_DEVICE_TRACKER_REPORT=true Then, an additional mqtt message will be posted to the topic branch ending in `/device_tracker` -So, as an example for a `monitor` node named "first floor", a device tracker configuration for Home Assistant can look like: +So, as an example for a this script node named "first floor", a device tracker configuration for Home Assistant can look like: ```yaml @@ -222,7 +222,7 @@ The standard confidence report will also send.

How do I determine what values to set for filters?

-Try using the verbose logging option `-V` to see what `monitor` sees when a new bluetooth device advertisement is seen. Then, power cycle the bluetooth radio on the device you'd like to track - you'll probably see a pattern develop with flags or manufacturers. Use these values to create your arrival filters! +Try using the verbose logging option `-V` to see what this script sees when a new bluetooth device advertisement is seen. Then, power cycle the bluetooth radio on the device you'd like to track - you'll probably see a pattern develop with flags or manufacturers. Use these values to create your arrival filters! Similarly, to set exclude filters, you can observe bluetooth traffic for a period of time to see what devices you simply do not care about seeing.

@@ -239,7 +239,7 @@ Yes, this is default behavior. All you have to do is provide a name next to the 00:11:22:33:44:55 Andrew's iPhone ``` -Then restart the `monitor` service. The script will now use "andrew_s_iphone" as the final mqtt topic path component. +Then restart the this script service. The script will now use "andrew_s_iphone" as the final mqtt topic path component. ***Important:*** From 89dfde62a6ba1278cdbdee7364bc2bc970e12deb Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:57:09 -0600 Subject: [PATCH 46/50] 0.2.196 --- support/README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/support/README.md b/support/README.md index db53cdcd..f51cf59b 100644 --- a/support/README.md +++ b/support/README.md @@ -1,6 +1,3 @@ -# *Frequenty Asked Questions:* -____ - ## *Basics*
Will this be able to track my Apple Watch/Smart Watch?

@@ -87,7 +84,7 @@ ____ ## *Wi-Fi Interference & Performance Issues* -

I'm running 5GHz Wi-Fi, I don't use Bluetooth for anything else, and I don't care whether I interfere with my neighbor's devices. Can't I just issue a name scan every few seconds to get faster arrival and depart detection?

+

Can't I just issue a name scan every few seconds to get faster arrival and depart detection?

Yes, use periodic scanning mode with `-r`.

@@ -112,7 +109,7 @@ It can, if it scans too frequently, especially if you're running this script fro Post a message to `monitor/scan/echo`, and you'll receive a response at the topic `$mqtt_topicpath/$mqtt_publisher_identity/echo`
-
I *still* have interference and/or my ssh sessions to the raspberry pi are really slow and laggy. What gives?

+

I have interference and/or my ssh sessions are really slow and laggy. What gives?

Cheap Wi-Fi chipsets and cheap Bluetooth chipsets can perform poorly together if operated at the same time, especially on Raspberry Pi devices. If you still experience interference in your network, switching to a Wi-Fi dongle can help.

From 45af759c3a258102ffd566697ed9de143fe3631e Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:57:46 -0600 Subject: [PATCH 47/50] 0.2.196 --- support/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/README.md b/support/README.md index f51cf59b..602967e4 100644 --- a/support/README.md +++ b/support/README.md @@ -128,7 +128,7 @@ ___ If more than one program or executable try to use the Bluetooth hardware at the same time, your Bluetooth hardware will report an error. To correct this error, the hardware needs to be taken offline, then brought back.
-
I can't do **XYZ**, is this script broken?

+

How do I access logs?

Run via command line and post log output to github. Else, access `journalctl` to show the most recent logs: From fa53550438fe42e01e0c08ed9657e89d178802e7 Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:59:12 -0600 Subject: [PATCH 48/50] 0.2.196 --- support/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/README.md b/support/README.md index 602967e4..8ffef40d 100644 --- a/support/README.md +++ b/support/README.md @@ -69,9 +69,9 @@ sudo systemctl restart monitor Or, post a message with blank content to `monitor/scan/restart`

-
Why don't I see RSSI for my iPhone/Andriod/whatever phone?

+

Why don't I see RSSI for my device?

-See the RSSI section of this FAQ. You'll have to connect your phone to this script first. +For phones, you'll have to connect to `monitor` first using the `-c` flag.

How do I force an RSSI update for a known device, like my phone?

From 4bb0d97b0eb0b100392ff34d6bf6f5a964afa69a Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 15:59:50 -0600 Subject: [PATCH 49/50] 0.2.196 --- support/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/support/README.md b/support/README.md index 8ffef40d..ffb53576 100644 --- a/support/README.md +++ b/support/README.md @@ -82,7 +82,7 @@ Post a message with blank content to `monitor/scan/rssi` ____ -## *Wi-Fi Interference & Performance Issues* +## *Performance*

Can't I just issue a name scan every few seconds to get faster arrival and depart detection?

@@ -121,7 +121,7 @@ Many Bluetooth dongles do not properly filter out duplicate advertisements, so t ___ -## *Monitor Logs & Debugging* +## *Debugging*

I keep seeing that my Bluetooth hardware is "cycling" in the logs - what does that mean?

@@ -226,7 +226,7 @@ Similarly, to set exclude filters, you can observe bluetooth traffic for a perio ____ -## *Other Questions* +## *Other*

It's annoying to have to keep track of mac addresses. Can't I just use a nickname for the mac addresses for MQTT topics?

From c9c219182ae2b2f7bdfb2ee422c8df75f937eefc Mon Sep 17 00:00:00 2001 From: Andrew J Freyer Date: Thu, 2 May 2019 16:00:12 -0600 Subject: [PATCH 50/50] 0.2.196 --- support/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/README.md b/support/README.md index ffb53576..fdc02999 100644 --- a/support/README.md +++ b/support/README.md @@ -258,7 +258,7 @@ To disable this feature, set `PREF_ALIAS_MODE=false` in your `behavior_preferenc Yes. Create a file called `address_blacklist` in your configuration directory and add the mac addresses you'd like to block (or uuid-major-minor for iBeacons) one at a time.

-
I can't use the `device_tracker` platform with the default status strings of `home` and `not_home` with my home automation software. What can I do?

+

I can't use the device_tracker platform with the default status strings of `home` and `not_home` with my home automation software. What can I do?

Set these options in `behavior_preferences`: