test
This commit is contained in:
parent
ef51dbe795
commit
0b6bc0c6af
31
main.go
31
main.go
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/paypal/gatt"
|
||||
"github.com/paypal/gatt/examples/option"
|
||||
|
|
@ -20,7 +21,7 @@ type IBeancon struct {
|
|||
|
||||
func NewiBeacon(data []byte) (*IBeancon, error) {
|
||||
if len(data) < 25 || binary.BigEndian.Uint32(data) != 0x4c000215 {
|
||||
return nil, errors.New("Not an iBeacon")
|
||||
return nil, errors.New("not an iBeacon")
|
||||
}
|
||||
beacon := new(IBeancon)
|
||||
beacon.Uuid = strings.ToUpper(hex.EncodeToString(data[4:8]) + hex.EncodeToString(data[8:10]) + hex.EncodeToString(data[10:12]) + hex.EncodeToString(data[12:14]) + hex.EncodeToString(data[14:20]))
|
||||
|
|
@ -30,20 +31,26 @@ func NewiBeacon(data []byte) (*IBeancon, error) {
|
|||
}
|
||||
|
||||
func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
|
||||
// if p.ID() != "C6:1A:05:02:06:C0" {
|
||||
// if p.ID() != "78:2C:29:16:F2:78" {
|
||||
// return
|
||||
// }
|
||||
if p.ID() != "90:98:38:F5:DA:60" {
|
||||
return
|
||||
}
|
||||
fmt.Println("MAC:", p.ID(), "RSSI:", rssi, "LEN:", len(a.ManufacturerData))
|
||||
// if p.ID() != "90:98:38:F5:DA:60" {
|
||||
// return
|
||||
// }
|
||||
// if !(p.ID() == "C6:1A:05:02:06:C0" || p.ID() == "90:98:38:F5:DA:60") {
|
||||
// return
|
||||
// }
|
||||
fmt.Println("NAME:", a.LocalName, "T:", time.Now(), "MAC:", p.ID(), "RSSI:", rssi, "LEN:", len(a.ManufacturerData))
|
||||
|
||||
b, err := NewiBeacon(a.ManufacturerData)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("UUID: %s Major: %d Minor: %d RSSI: %d\n", b.Uuid, b.Major, b.Minor, rssi)
|
||||
// for _, d := range a.ServiceData {
|
||||
// fmt.Println("uuid:", d.UUID, " data:", d.Data)
|
||||
// }
|
||||
// b, err := NewiBeacon(a.ManufacturerData)
|
||||
// if err != nil {
|
||||
// fmt.Println(err.Error())
|
||||
// return
|
||||
// }
|
||||
// fmt.Printf("UUID: %s Major: %d Minor: %d RSSI: %d\n", b.Uuid, b.Major, b.Minor, rssi)
|
||||
}
|
||||
|
||||
func onStateChanged(device gatt.Device, s gatt.State) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue