Skip to content

Instantly share code, notes, and snippets.

@thetzel

thetzel/main.go

Last active Jun 21, 2020
Embed
What would you like to do?
Exposure Notification Scanning on Raspberry Pi
package main
import (
"fmt"
"log"
"github.com/paypal/gatt"
"github.com/paypal/gatt/examples/option"
)
func onStateChanged(device gatt.Device, s gatt.State) {
switch s {
case gatt.StatePoweredOn:
fmt.Println("Scanning for Rolling Proximity Identifiers")
device.Scan([]gatt.UUID{}, false)
return
default:
device.StopScanning()
}
}
func onPeripheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
// fmt.Printf("%+v\n", a)
if(len(a.Services) > 0){
if(gatt.UUID.Equal(a.Services[0], gatt.MustParseUUID("fd6f"))){
if(len(a.ServiceData) > 0){
log.Printf("%x\n", a.ServiceData[0].Data)
}
}
}
}
func main() {
device, err := gatt.NewDevice(option.DefaultClientOptions...)
if err != nil {
log.Fatalf("Failed to open device, err: %s\n", err)
return
}
device.Handle(gatt.PeripheralDiscovered(onPeripheralDiscovered))
device.Init(onStateChanged)
select {}
}
case typeServiceData16:
var s ServiceData
s.UUID = UUID{d[:2]}
s.Data = d[2:]
a.ServiceData = append(a.ServiceData, s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.