Skip to content

Commit

Permalink
bluetooth shouldn't block if it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Jul 29, 2018
1 parent 15ce690 commit 8944829
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM ubuntu:18.04

ENV GOLANG_VERSION 1.10
ENV PATH="/usr/local/go/bin:${PATH}"
ENV GOPATH /root/go
Expand Down
15 changes: 8 additions & 7 deletions bluetooth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,25 @@ 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))
d.Init(onStateChanged)
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):
Expand Down

0 comments on commit 8944829

Please sign in to comment.