From 89448299e070f71580a52c0aa935769448b95645 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 29 Jul 2018 09:03:28 -0700 Subject: [PATCH] bluetooth shouldn't block if it fails --- Dockerfile | 1 - bluetooth.go | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index b2761fe..c39c7ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ FROM ubuntu:18.04 - ENV GOLANG_VERSION 1.10 ENV PATH="/usr/local/go/bin:${PATH}" ENV GOPATH /root/go diff --git a/bluetooth.go b/bluetooth.go index e0d284f..664d538 100644 --- a/bluetooth.go +++ b/bluetooth.go @@ -32,11 +32,18 @@ var d gatt.Device var bluetoothInitiated bool func scanBluetooth(out chan map[string]map[string]interface{}) (err error) { + log.Debug("scanning bluetooth") + bdatasync.Lock() + bdata = make(map[string]map[string]interface{}) + bdata["bluetooth"] = make(map[string]interface{}) + bdatasync.Unlock() + if !bluetoothInitiated { log.Debug("initiating bluetooth") d, err = gatt.NewDevice() if err != nil { - log.Debug("Failed to open device, err: %s", err.Error()) + log.Debugf("Failed to open device, err: %s", err.Error()) + out <- bdata return } d.Handle(gatt.PeripheralDiscovered(onPeriphDiscovered)) @@ -44,12 +51,6 @@ func scanBluetooth(out chan map[string]map[string]interface{}) (err error) { bluetoothInitiated = true } - log.Debug("scanning bluetooth") - bdatasync.Lock() - bdata = make(map[string]map[string]interface{}) - bdata["bluetooth"] = make(map[string]interface{}) - bdatasync.Unlock() - d.Scan([]gatt.UUID{}, false) select { case <-time.After(time.Duration(scanSeconds) * time.Second):