Skip to content

Instantly share code, notes, and snippets.

@ErgoFriend

ErgoFriend/main.go

Last active Nov 28, 2020
Embed
What would you like to do?
golang ble ibeacon peripheral advertise macos darwin
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