Last active
June 21, 2020 23:03
-
-
Save thetzel/398c5c504a4616732e78c991e2478e52 to your computer and use it in GitHub Desktop.
Exposure Notification Scanning on Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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