Skip to content

Instantly share code, notes, and snippets.

@ergofriend
Last active November 28, 2020 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ergofriend/54d25d7ad1acd1d733880686facadd0e to your computer and use it in GitHub Desktop.
Save ergofriend/54d25d7ad1acd1d733880686facadd0e to your computer and use it in GitHub Desktop.
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