From c813ec827bba631deaac497f05a76c1203f990e3 Mon Sep 17 00:00:00 2001 From: "suguo.yao" Date: Tue, 21 Dec 2021 16:22:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87ibeacon?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 11 ++++++- cpu/cpu.go | 2 ++ main.go | 89 ++++-------------------------------------------------- 3 files changed, 18 insertions(+), 84 deletions(-) diff --git a/Makefile b/Makefile index 24c471f..9ec93b7 100644 --- a/Makefile +++ b/Makefile @@ -17,4 +17,13 @@ macos: 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" \ No newline at end of file + 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:~/ \ No newline at end of file diff --git a/cpu/cpu.go b/cpu/cpu.go index 5085c9c..994819a 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -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 { diff --git a/main.go b/main.go index 71e82b0..e49a573 100644 --- a/main.go +++ b/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 {}