测试通过ibeacon识别
This commit is contained in:
parent
c08a167ccc
commit
c813ec827b
9
Makefile
9
Makefile
|
|
@ -18,3 +18,12 @@ release: arm
|
|||
ssh pi@192.168.0.21 "sudo systemctl stop ble.service"
|
||||
scp ./ble-ibeacon pi@192.168.0.21:~/
|
||||
ssh pi@192.168.0.21 "sudo systemctl start ble.service"
|
||||
|
||||
.PHONY: release2
|
||||
release2: arm
|
||||
ssh pi@192.168.0.28 "sudo systemctl stop ble.service"
|
||||
scp ./ble-ibeacon pi@192.168.0.28:~/
|
||||
ssh pi@192.168.0.28 "sudo systemctl start ble.service"
|
||||
|
||||
release2: arm
|
||||
scp ./ble-ibeacon pi@192.168.0.28:~/
|
||||
|
|
@ -16,6 +16,8 @@ func main() {
|
|||
|
||||
fmt.Printf("%v\n", cpu)
|
||||
|
||||
fmt.Println(cpu.JSONString(true))
|
||||
|
||||
for _, proc := range cpu.Processors {
|
||||
fmt.Printf(" %v\n", proc)
|
||||
for _, core := range proc.Cores {
|
||||
|
|
|
|||
89
main.go
89
main.go
|
|
@ -6,14 +6,10 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/client/v2"
|
||||
"github.com/paypal/gatt"
|
||||
"github.com/paypal/gatt/examples/option"
|
||||
"myschools.me/suguo/ble-ibeacon/influx"
|
||||
)
|
||||
|
||||
type IBeancon struct {
|
||||
|
|
@ -33,48 +29,14 @@ func NewiBeacon(data []byte) (*IBeancon, error) {
|
|||
return beacon, nil
|
||||
}
|
||||
|
||||
var (
|
||||
chn chan *client.Point
|
||||
)
|
||||
|
||||
func init() {
|
||||
chn = make(chan *client.Point, 500)
|
||||
}
|
||||
|
||||
func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
|
||||
// if p.ID() != "78:2C:29:16:F2:78" {
|
||||
// return
|
||||
// }
|
||||
// if p.ID() != "90:98:38:F5:DA:60" {
|
||||
// return
|
||||
// }
|
||||
// if p.ID() != "E4:78:41:19:10:98" {
|
||||
// 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))
|
||||
|
||||
tags := make(map[string]string)
|
||||
tags["mac"] = p.ID()
|
||||
|
||||
fields := make(map[string]interface{})
|
||||
fields["name"] = a.LocalName
|
||||
fields["rssi"] = rssi
|
||||
fields["pl"] = strconv.Itoa(len(a.ManufacturerData)) //包长度
|
||||
fields["power"] = a.TxPowerLevel
|
||||
|
||||
point, err := client.NewPoint(
|
||||
"band",
|
||||
tags,
|
||||
fields,
|
||||
time.Now(),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
b, err := NewiBeacon(a.ManufacturerData)
|
||||
if err == nil {
|
||||
fmt.Println("UUID:", b.Uuid)
|
||||
fmt.Println("Major:", b.Major)
|
||||
fmt.Println("Minor:", b.Minor)
|
||||
fmt.Println("RSSI:", rssi)
|
||||
}
|
||||
chn <- point
|
||||
}
|
||||
|
||||
func onStateChanged(device gatt.Device, s gatt.State) {
|
||||
|
|
@ -88,51 +50,12 @@ func onStateChanged(device gatt.Device, s gatt.State) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
influx.Init(&influx.Config{
|
||||
Address: "http://127.0.0.1:8086",
|
||||
DBName: "wristband",
|
||||
Username: "abc",
|
||||
Password: "abc",
|
||||
Timeout: 3,
|
||||
})
|
||||
|
||||
// if err := influx.CreateDB("wristband", 10); err != nil {
|
||||
// log.Fatalln("influx.CreateDB", err.Error())
|
||||
// }
|
||||
|
||||
go func() {
|
||||
db, err := influx.New()
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
|
||||
for {
|
||||
bp, err := client.NewBatchPoints(client.BatchPointsConfig{
|
||||
Database: "wristband",
|
||||
Precision: "ms",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
for i := 1; i < 50; i++ {
|
||||
if d, ok := <-chn; ok {
|
||||
bp.AddPoint(d)
|
||||
}
|
||||
}
|
||||
if err := db.Write(bp); err != nil {
|
||||
log.Println("db.Write: ", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
dev, err := gatt.NewDevice(option.DefaultClientOptions...)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open device, err:%s\n", err)
|
||||
}
|
||||
dev.Handle(
|
||||
gatt.PeripheralDiscovered(onPerhipheralDiscovered),
|
||||
gatt.CentralConnected(func(c gatt.Central) { fmt.Println("Connect: ", c.ID()) }),
|
||||
gatt.CentralDisconnected(func(c gatt.Central) { fmt.Println("Disconnect: ", c.ID()) }),
|
||||
)
|
||||
dev.Init(onStateChanged)
|
||||
select {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue