pi@raspberrypi:~/Desktop/WeatherMachine2-hrm-master $ go run hrm1.go
go: finding module for package github.com/muka/go-bluetooth/api
hrm1.go:16:2: no matching versions for query "latest"
==========================Inside hrm.go=========================
package main
func pollHeartRateMonitor(hr chan uint16, halt chan bool) {
// Connect bluetooth.
hciconfig := linux.HCIConfig{}
_, err := hciconfig.Up()
if err != nil {
log.Printf("Unable to connect %s", err)
return
}
// Bluetooth cleanup function.
defer func() {
api.Exit()
_, err = hciconfig.Down()
if err != nil {
log.Printf("Unable to disconnect %s", err)
return
}
log.Printf("HRM stopped.")
}()
// Give the hardware a second to warmup.
time.Sleep(time.Second)
// See if the device is known first.
d, err := api.GetDeviceByAddress("E5:20:2B:3A:13:F5")
if err != nil {
log.Printf("Unable to get device %s", err)
return
}
// Unable to find the device, try discovering it for 10 seconds.
if d == nil {
log.Printf("Starting discovery")
err = api.StartDiscovery()
if err != nil {
log.Printf("Unable to start discovery %s", err)
}
api.On("discovery", emitter.NewCallback(func(ev emitter.Event) {
discoveryEvent := ev.GetData().(api.DiscoveredDeviceEvent)
dev := discoveryEvent.Device
if dev == nil {
log.Printf("Device removed!")
return
}
log.Printf("Found %v", dev)
}))
time.Sleep(10 * time.Second)
log.Printf("Stopping discovery")
api.StopDiscovery()
d, err = api.GetDeviceByAddress("0C:F3:EE:AA:B1:F7")
if err != nil {
log.Printf("Unable to get device %s", err)
return
}
}
log.Printf("Connecting to device %v", d.Properties)
err = d.Connect()
if err != nil {
log.Printf("Unable to connect to device %s", err)
return
}
// Discover the bluetooth device characteristics.
char := getCharacteristic(d, "2A37")
if char == nil {
log.Printf("waiting while characteristics are discovered")
time.Sleep(15 * time.Second)
char = getCharacteristic(d, "2A37")
}
hrChannel, err := char.Register()
if err != nil {
log.Printf("Unable to register to characteristic %s", err)
return
}
pi@raspberrypi:~/Desktop/WeatherMachine2-hrm-master $ go run hrm1.go go: finding module for package github.com/muka/go-bluetooth/api hrm1.go:16:2: no matching versions for query "latest"
==========================Inside hrm.go========================= package main
import ( "encoding/binary" "flag" "fmt" "log" "os" "strings"
)
func pollHeartRateMonitor(hr chan uint16, halt chan bool) { // Connect bluetooth. hciconfig := linux.HCIConfig{} _, err := hciconfig.Up() if err != nil { log.Printf("Unable to connect %s", err) return }
// Bluetooth cleanup function. defer func() { api.Exit()
}()
// Give the hardware a second to warmup. time.Sleep(time.Second)
// See if the device is known first. d, err := api.GetDeviceByAddress("E5:20:2B:3A:13:F5") if err != nil { log.Printf("Unable to get device %s", err) return }
// Unable to find the device, try discovering it for 10 seconds. if d == nil { log.Printf("Starting discovery") err = api.StartDiscovery() if err != nil { log.Printf("Unable to start discovery %s", err) }
}
log.Printf("Connecting to device %v", d.Properties) err = d.Connect() if err != nil { log.Printf("Unable to connect to device %s", err) return }
// Discover the bluetooth device characteristics. char := getCharacteristic(d, "2A37") if char == nil { log.Printf("waiting while characteristics are discovered") time.Sleep(15 * time.Second) char = getCharacteristic(d, "2A37") }
hrChannel, err := char.Register() if err != nil { log.Printf("Unable to register to characteristic %s", err) return }
err = char.StartNotify() if err != nil { log.Printf("StartNotify error %v", err) return } log.Printf("Characteristic registered %v", char)
for e := range hrChannel { if e == nil { return }
} }