init
This commit is contained in:
commit
4cfb26b1aa
|
|
@ -0,0 +1,6 @@
|
|||
go.sum
|
||||
ble-ibeacon
|
||||
*.exe
|
||||
*.bin
|
||||
logs/
|
||||
.vscode/
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
.PHONY: arm
|
||||
arm:
|
||||
go mod tidy
|
||||
GOOS=linux GOARCH=arm GOARM=7 go build
|
||||
|
||||
.PHONY: release
|
||||
release: arm
|
||||
scp ./ble-ibeacon pi@192.168.0.21:~/
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
module myschools.me/suguo/ble-ibeacon
|
||||
|
||||
go 1.17
|
||||
|
||||
require github.com/paypal/gatt v0.0.0-20151011220935-4ae819d591cf
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/paypal/gatt"
|
||||
"github.com/paypal/gatt/examples/option"
|
||||
)
|
||||
|
||||
func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
|
||||
fmt.Println(string(a.ManufacturerData))
|
||||
}
|
||||
|
||||
func onStateChanged(device gatt.Device, s gatt.State) {
|
||||
switch s {
|
||||
case gatt.StatePoweredOn:
|
||||
device.Scan([]gatt.UUID{}, true)
|
||||
return
|
||||
default:
|
||||
device.StopScanning()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
dev, err := gatt.NewDevice(option.DefaultClientOptions...)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open device, err:%s\n", err)
|
||||
}
|
||||
dev.Handle(gatt.PeripheralDiscovered(onPerhipheralDiscovered))
|
||||
dev.Init(onStateChanged)
|
||||
select {}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# 蓝牙通讯例子
|
||||
|
||||
### 概述
|
||||
希望用于通过蓝牙RSSI值判断距离的研究。
|
||||
|
||||
### 组件
|
||||
- github.com/paypal/gatt
|
||||
|
||||
### 部署
|
||||
- sudo hciconfig hci0 down
|
||||
- sudo service bluetooth stop
|
||||
|
||||
### QA
|
||||
- Failed to open device, err:no supported devices available
|
||||
> 执行权限不够导致设备找不到,记得sudo
|
||||
- 查看raspberrypi几位系统
|
||||
> getconf LONG_BIT
|
||||
- 查看操作系统信息
|
||||
> lsb_release -a
|
||||
- 直接查看系统的架构
|
||||
> arch
|
||||
Loading…
Reference in New Issue