golang ble ibeacon peripheral advertise macos darwin
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 ( | |
"context" | |
"fmt" | |
"log" | |
"os" | |
"os/signal" | |
"time" | |
"github.com/JuulLabs-OSS/ble" | |
"github.com/JuulLabs-OSS/ble/darwin" | |
) | |
func main() { | |
d, err := darwin.NewDevice() | |
if err != nil { | |
log.Printf("can't new device : %s", err) | |
} | |
ble.SetDefaultDevice(d) | |
// 6c617265-6870-6972-6570-2d6f6762632d | |
var a ble.UUID = []byte("-cbgo-peripheral") | |
var c uint16 | |
ctx := ble.WithSigHandler(context.WithTimeout(context.Background(), 3000 * time.Millisecond)) | |
for range time.Tick(3000 * time.Millisecond) { | |
fmt.Println("Tick count", c) | |
ble.AdvertiseIBeacon(ctx, a, 1, c, 0) | |
c++ | |
ble.Stop() | |
} | |
quit := make(chan os.Signal) | |
signal.Notify(quit, os.Interrupt) | |
<-quit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment